https://www.cac.cornell.edu/wiki/index.php?title=MPI_Hello_World&feed=atom&action=historyMPI Hello World - Revision history2024-03-29T15:00:14ZRevision history for this page on the wikiMediaWiki 1.35.5https://www.cac.cornell.edu/wiki/index.php?title=MPI_Hello_World&diff=571&oldid=prevAd876: Created page with "This is a simple example of workers sending a message to a master process using the Message Passing Interface, MPI. If you copy it into a file called main.c, you can compile i..."2015-09-21T22:18:08Z<p>Created page with "This is a simple example of workers sending a message to a master process using the Message Passing Interface, MPI. If you copy it into a file called main.c, you can compile i..."</p>
<p><b>New page</b></p><div>This is a simple example of workers sending a message to a master process using the Message Passing Interface, MPI. If you copy it into a file called main.c, you can compile it with "mpicc main.c -o hello".<br />
<br />
<source lang=C><br />
#include <stdio.h><br />
#include <mpi.h><br />
<br />
int main(int argc, char ** argv)<br />
{<br />
int size,rank;<br />
int length;<br />
char name[80];<br />
MPI_Status status;<br />
int workerIdx;<br />
<br />
MPI_Init(&argc, &argv);<br />
MPI_Comm_rank(MPI_COMM_WORLD,&rank);<br />
MPI_Comm_size(MPI_COMM_WORLD,&size);<br />
MPI_Get_processor_name(name,&length);<br />
<br />
if (rank==0) {<br />
printf("Hello MPI from the server process!\n");<br />
<br />
for (workerIdx=1; workerIdx<size; workerIdx++) {<br />
MPI_Recv(name, 80, MPI_CHAR, workerIdx, 999, MPI_COMM_WORLD, &status);<br />
printf("Hello MPI!\n");<br />
printf(" message from %d of %d on %s\n", workerIdx, size, name);<br />
}<br />
} else {<br />
MPI_Send(name,80,MPI_CHAR,0,999,MPI_COMM_WORLD);<br />
}<br />
<br />
MPI_Finalize(); <br />
}<br />
</source></div>Ad876