43 #define MAX_SHMEMPI_ERRS 500
47 static int numErrors = 0;
48 static int size_of_SHMEMPI_INT;
52 #define PACKSIZE ((PSIZE)*sizeof(long))
53 static long shmempipackbuf[
PSIZE];
66 int i, reported, rep_host, ierror, result_len;
68 char *currtok, *nexttok, *execname;
71 currtok = strstr(argv[0],
"/");
74 execname = strdup(argv[0]);
79 nexttok = strstr(currtok,
"/");
83 nexttok = strstr(currtok,
"/");
85 execname = strdup(currtok);
89 MPI_Init(&argc, &argv);
92 strcpy(argv[0],execname);
96 MPI_Comm_rank(MPI_COMM_WORLD,&
myHost);
107 MPI_Type_size ( MPI_INT, &size_of_SHMEMPI_INT );
118 std::vector<int> child_ready(TotalNodes);
119 for (i = 0; i <
TotalNodes; child_ready[i++] = 0);
120 INFOMSG(
"CommSHMEMPI: Parent process waiting for children ..." <<
endl);
122 while (reported < TotalNodes)
124 ierror = MPI_Recv(&rep_host, 1, MPI_INT, MPI_ANY_SOURCE,
127 if (rep_host >= 0 && rep_host < TotalNodes && !(child_ready[rep_host]))
129 child_ready[rep_host] = 1;
131 INFOMSG(
"CommSHMEMPI: Child " << rep_host <<
" ready." <<
endl);
135 ERRORMSG(
"CommSHMEMPI: Error with child reporting to parent. ");
136 ERRORMSG(
"rep_host = " << rep_host);
137 ERRORMSG(
", child_ready[] = " << child_ready[rep_host] <<
endl);
141 INFOMSG(
"CommSHMEMPI: Initialization complete." <<
endl);
146 char host_name[MPI_MAX_PROCESSOR_NAME];
147 ierror = MPI_Get_processor_name(host_name, &result_len);
150 INFOMSG(
"CommSHMEMPI: Started job " <<
myHost <<
" on host `");
160 MPI_Recv(&checknode, 1, MPI_INT, 0,
COMM_HOSTS_TAG, MPI_COMM_WORLD,
164 WARNMSG(
"CommSHMEMPI: Child received bad message during startup." <<
endl);
174 vector<int> proccount;
175 proccount.push_back(1);
197 int trial, node, tag;
199 for (trial = 0; trial < 50000; ++trial)
208 WARNMSG(
"CommSHMEMPI: Found extra message from node " << node);
209 WARNMSG(
", tag " << tag <<
": msg = " << *msg <<
endl);
222 MPI_Send(&dieCode, 1, MPI_INT, i,
COMM_DIE_TAG, MPI_COMM_WORLD);
229 MPI_Recv(&dieCode, 1, MPI_INT, 0,
COMM_DIE_TAG, MPI_COMM_WORLD, &stat);
272 int nitems = msg->
size();
278 MPI_Status rec_status;
279 int src_node, rec_node, rec_tag, rec_size, rec_utag, bufid, rec_flag = 0;
287 errstat = MPI_Isend(outbuffer, size, MPI_BYTE, node, etag,
288 MPI_COMM_WORLD, &request);
294 bufid = MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD,
295 &rec_flag, &rec_status);
296 if ( (bufid >= 0) && (rec_flag != 0) )
299 src_node = rec_status.MPI_SOURCE;
300 rec_tag = rec_status.MPI_TAG;
301 MPI_Get_count(&rec_status, MPI_BYTE, &rec_size);
302 if ( (rec_size >= 0) && (rec_tag >= 0) && (src_node >= 0) )
308 MPI_Recv(rec_buff, rec_size, MPI_BYTE, src_node, rec_tag,
309 MPI_COMM_WORLD, &rec_status);
319 if (
add_msg(newmsg,rec_node,rec_utag))
328 MPI_Test(&request, &flag, &status);
336 return (errstat == 0);
354 int bufid, size, checknode, checktag, flag =
false;
358 checknode = (node < 0 || node >=
TotalNodes ? MPI_ANY_SOURCE : node);
362 bufid = MPI_Iprobe(checknode, checktag, MPI_COMM_WORLD, &flag, &stat);
366 ERRORMSG(
"CommSHMEMPI: cannot receive msg from node " << checknode);
371 ERRORMSG(
"Maximum number of MPI receive errors (" << numErrors);
380 MPI_Get_count(&stat,MPI_BYTE,&size);
383 ERRORMSG(
"CommSHMEMPI: received message has size " << size <<
endl);
385 else if ((stat.MPI_TAG != checktag) || (stat.MPI_TAG < 0))
387 ERRORMSG(
"CommSHMEMPI: received message with invalid tag ");
390 else if (stat.MPI_SOURCE < 0)
392 ERRORMSG(
"CommSHMEMPI: received message from invalid source ");
397 checknode = stat.MPI_SOURCE;
398 checktag = stat.MPI_TAG;
404 MPI_Recv(outbuff, size, MPI_BYTE, checknode, checktag,
405 MPI_COMM_WORLD, &stat);
419 DEBUGMSG(
level2 <<
"CommSHMEMPI: No Message Received to Match Request");
436 MPI_Barrier(MPI_COMM_WORLD);
static void abort(const char *=0, int exitcode=(-1))
bool add_msg(Message *, int, int)
void fill_msg_buffer(void *, Message &, int, int, int)
std::vector< std::vector< int > > Processes
void * pack_message(Message *msg, int tag, int &buffsize)
virtual void cleanupMessage(void *)
std::vector< int > Contexts
int find_msg_length(Message &)
Inform & level2(Inform &inf)
virtual bool mysend(Message *, int node, int utag, int etag)
virtual void mybarrier(void)
static void * makebuffer(int size)
virtual ~CommSHMEMPI(void)
void useCommunicate(Communicate *c, void *d)
static void freebuffer(void *buf)
CommSHMEMPI(int &argc, char **&argv, int procs=(-1))
Message * unpack_message(int &node, int &tag, void *pos)
Inform & endl(Inform &inf)
virtual Message * myreceive(int &node, int &tag, int etag)