fork download
  1. #include <stdio.h>
  2. #include <mpi.h>
  3. #include <string.h>
  4. #define BUFFER_SIZE 32
  5. int main(int argc,char *argv[])
  6. {
  7. int MyRank,Numprocs, Destination, iproc;
  8. int tag = 0;
  9. int Root = 0, temp = 1;
  10. char Message[BUFFER_SIZE];
  11. MPI_Init(&argc,&argv);
  12. MPI_Status status;
  13. MPI_Comm_rank(MPI_COMM_WORLD,&MyRank);
  14. MPI_Comm_size(MPI_COMM_WORLD,&Numprocs);
  15. /* print host name, and send message from process with rank 0 to all other processes */
  16. if(MyRank == 0) {
  17. system("hostname");
  18. strcpy(Message, "Hello India");
  19. for (temp=1; temp<Numprocs;temp++)
  20. {
  21. MPI_Send(Message, BUFFER_SIZE, MPI_CHAR, temp,
  22. tag,MPI_COMM_WORLD);
  23. }
  24. }
  25. else
  26. {
  27. system("hostname");
  28. MPI_Recv(Message, BUFFER_SIZE, MPI_CHAR, Root,
  29. tag,MPI_COMM_WORLD, &status);
  30. printf("\n%s in process with rank %d from Process with rank %d\n",
  31. Message,MyRank,Root);
  32. }
  33. MPI_Finalize();
  34. }
Success #stdin #stdout #stderr 0.29s 40500KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted