[MPICH] Send and Recv Guidance Needed

Matthew Chambers matthew.chambers at vanderbilt.edu
Wed Apr 11 09:44:37 CDT 2007


You might try having a call like:

MPI_Recv( &sourceProcessRank, 1, MPI_INT, MPI_ANY_SOURCE, 0xFF,
MPI_COMM_WORLD, &st );

Inside a loop in your parent process (rank 0).  This is equivalent to saying
"I'm waiting for somebody to talk to me, and then asking them who they are."
Obviously the matching MPI_Send sends the rank id of that child process.
Then you can do your record receiving inside the loop, since
sourceProcessRank tells you what process to receive from for each iteration.
You can add a kind of "control" receive before actually receiving the
record, which may get a 0 or a 1 from the child process indicating whether
it has actually found a record and should start receiving it, or if it is
instead done with its search and won't be sending any more records.  When
you have received a "control" code from each child node indicating it is
finished, you exit the loop.  You can send a 1 from the child node if it's
done searching, and use that value to just increment a counter which you
check against the number of child nodes as your loop condition.  I use a
solution like this in many situations.  It's much simplier than requiring
MPI thread support.

 

Matt

 

  _____  

From: owner-mpich-discuss at mcs.anl.gov
[mailto:owner-mpich-discuss at mcs.anl.gov] On Behalf Of Erich Peterson
Sent: Tuesday, April 10, 2007 10:52 PM
To: mpich-discuss at mcs.anl.gov
Subject: [MPICH] Send and Recv Guidance Needed

 

Hi all,

                I am trying to come up with the best way to approach this. I
am want to have many processes access a file, each gathering records, using
a specified criteria (which is not important here). I want each process to
send each record (100 bytes long) it matches to process rank 0 as a string.
Lastly, I want rank 0 to place all the records it receives into a vector of
strings (vector<string>).

                I thought of letting each process call MPI_Send() from each
record it matches and have process rank 0 call MPI_Recv, but, process rank 0
won't know how many times to call MPI_Recv to receive all the records.

                

                Thanks,

Erich

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/mpich-discuss/attachments/20070411/05826ab1/attachment.htm>


More information about the mpich-discuss mailing list