Go to the first, previous, next, last section, table of contents.


Raw `TOP-C' interface: raw_master_slave

There are instances when tasks are most naturally generated deep inside nested loops. In such circumstances, it may be difficult to re-write the code to create a function GenerateTaskInput(), since that would require turning the loops inside out. (If you don't know what this refers to, then you probably don't need "raw_master_slave".)

A typical usage of these functions for raw master-slave mode is:

   /* variable not_done initialized to 1, and changed to 0 when done */
   TOPC_raw_begin_master_slave(do_task, check_task_result, update_shared_data);
   if TOPC_is_master() {
       while ( ! done || TOPC_raw_wait_for_task() ) {
         ...
         TOPC_raw_submit_task_input( task_input );
         ...
       }
   }
   TOPC_raw_end_master_slave();

Function: void TOPC_raw_begin_master_slave
(do_task, check_task_result, update_shared_data)
Function: void TOPC_raw_end_master_slave ()
This behaves like master_slave, with TOPC_raw_submit_task_input(input) serving the role of GenerateTaskInput(). The slave blocks inside TOPC_raw_begin_master_slave() and executes do_task() and update_shared_data() until the master executes TOPC_raw_end_master_slave(). At that time, the slave unblocks. The slave does nothing inside TOPC_raw_end_master_slave().

Function: void TOPC_raw_submit_task_input ( TOPC_BUF input )
Invoked by master between TOPC_raw_begin_master_slave() and TOPC_raw_end_master_slave(); Typical usage is:
     TOPC_raw_submit_task_input(TOPC_MSG(&input_data,
                                         sizeof(input_data)) );

The argument, input, corresponds to what would be returned by GenerateTaskInput() in the routine TOPC_master_slave(). input will be processed by DoTask() and its siblings, just as in TOPC_master_slave()). There can be multiple occurrences of TOPC_raw_submit_task_input().

Function: TOPC_BOOL TOPC_raw_wait_for_task ()
Invoked by master between TOPC_raw_begin_master_slave() and TOPC_raw_end_master_slave(); If no tasks are outstanding, returns false immediately. Otherwise, it blocks until a task does return, and then returns true.


Go to the first, previous, next, last section, table of contents.