fork download
  1. #include <stdio.h>
  2. #include <mpi.h>
  3. #include <string.h>
  4. void main(){
  5. int rank,size,tag[50];
  6. char m1[20],m2[20]="hello world";
  7. MPI_Status Status;
  8. MPI_Init(NULL,NULL);
  9. MPI_Comm_size(MPI_COMM_WORLD,&size);
  10. MPI_Comm_rank(MPI_COMM_WORLD,&rank);a
  11. if(rank==0)
  12. {
  13. strcpy(m1,m2);
  14. for(int i=1;i<size;i++)
  15. {
  16. MPI_Send(&m1 ,13 ,MPI_CHAR , i ,tag ,MPI_COMM_WORLD);
  17. }
  18. }
  19. else
  20. {
  21. MPI_Recv(&m1,13,MPI_CHAR, i , tag,MPI_COMM_WORLD , &status);
  22. printf("nod %d : %s\n",rank,m1);
  23. }
  24. MPI_Finalize()
  25. }
  26.  
Success #stdin #stdout #stderr 0.27s 40780KB
stdin
mpicc -o m1 m1.c
mpiexec -n 4 m1
stdout
Standard output is empty
stderr
Error: unexpected symbol in "void main"
Execution halted