| Version 1 (modified by wade, 17 years ago) (diff) |
|---|
Source code
/* Program:
* 讓 node 0 可以接受來自任何 node 的訊息
* History:
* 2008-06-24 BETA
*/
#include <stdio.h>
#include <mpi.h>
main (int argc, char **argv)
{
int numprocs, myrank, i=0, buf;
MPI_Status status;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
if (myrank > 0)
{
for(i = 0; i < 5; i++)
{
buf = myrank * 100 + i;
MPI_Send(&buf, 1, MPI_INT, 0, i, MPI_COMM_WORLD);
}
}
if (myrank == 0)
{
for (i = 0; i < 5*(numprocs-1); i++)
{
MPI_Recv(&buf, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
printf("[Node %d][Tag %d] => %d\n", status.MPI_SOURCE, status.MPI_TAG, buf);
}
}
MPI_Finalize();
}
Result
Attachments (1)
- demo4-01.png (84.0 KB) - added by wade 17 years ago.
Download all attachments as: .zip

