All pastes #189334 Raw Edit

Stuff

public c v1 · immutable
·published 2006-10-03 00:11 UTC
rendered paste body
/* test of MPI*/#include <mpi.h>#include <stdio.h>#include <string.h>int main(int argc, char *argv[]){  char idstr[32];  char buff[128];  int numprocs;  int myid;  int i;  MPI_Status stat;   MPI_Init(&argc,&argv);   MPI_Comm_size(MPI_COMM_WORLD,&numprocs);   MPI_Comm_rank(MPI_COMM_WORLD,&myid);   if(myid == 0) // Am I the head (controller) node?  {    printf("We have %d processors\n", numprocs);    for(i=1;i<numprocs;i++)    {      sprintf(buff, "Hello %d! ", i);      MPI_Send(buff, 128, MPI_CHAR, i, 0, MPI_COMM_WORLD);    }    for(i=1;i<numprocs;i++)    {      MPI_Recv(buff, 128, MPI_CHAR, i, 0, MPI_COMM_WORLD, &stat);      printf("%s\n", buff);    }  }  else // I am a compute node  {    MPI_Recv(buff, 128, MPI_CHAR, 0, 0, MPI_COMM_WORLD, &stat);    sprintf(idstr, "Processor %d ", myid);    strcat(buff, idstr);    strcat(buff, "reporting for duty\n");    MPI_Send(buff, 128, MPI_CHAR, 0, 0, MPI_COMM_WORLD);  }  MPI_Finalize();  return 0;}