It is common for parallel programs to use a static process model, in
which no process begins computing until all the other processes have
joined the program. Hence, we present the following code, which waits
for maxnodes processes to join the program, can be used to
fabricate a static process model atop FM's dynamic process model. It
can be used as boilerplate initialization for FM programs.
With FM's send rule, a static process model with totalnodes participating processes can be fabricated using the following C code:
#include <fm.h>
ULONG fmhAllAllSync; /* Handler ID for all-to-all synchronization */
ULONG joined = 0; /* # of processes that have joined the program */
/* Update process map */
int synchandler (FM_stream *mystream, unsigned sender)
{
joined++; /* One more node has joined */
return FM_CONTINUE;
}
/*****************************************/
/* Wait until maxnodes nodes have joined */
/*****************************************/
/* ALGORITHM: FM guarantees a process can send to all nodes that */
/* have sent to it or that have a smaller node ID. Hence, */
/* allallsync() sends a message to each node with a smaller node ID */
/* and then waits for a message from each node with a larger node ID. */
BOOLEAN allallsync(int maxnodes)
{
FM_stream *syncstream; /* Stream to use for synchronization */
ULONG i;
/* Make sure there aren't more nodes than anticipated */
if (FM_nodeid >= maxnodes)
return FALSE;
/* Notify everyone with a smaller node ID */
for (i=0; i<FM_nodeid; i++) {
while (!(syncstream=FM_begin_message(i,0,fmhAllAllSync)))
;
FM_end_message(syncstream);
joined++;
}
/* We've joined */
joined++;
/* Wait for everyone with a greater node ID to join the program */
while (joined != maxnodes)
(void) FM_extract(~0); /* Extract all we can */
/* Finish up */
(void) FM_reallocate_credit(); /* Promise that no one else will join */
return TRUE;
}
Go to the first, previous, next, last section, table of contents.