fork download
  1.  
  2.  
  3. #include"stdio.h"
  4. #include"mpi.h"
  5.  
  6. int main(int argc, char **argv)
  7. {
  8. int myid, size;
  9. int data;
  10.  
  11. //Initialize MPI environment
  12. MPI_Init(&argc,&argv);
  13.  
  14. //Get total number of processes
  15. MPI_Comm_size(MPI_COMM_WORLD, &size);
  16.  
  17. //Get my unique identification among all processes
  18. MPI_Comm_rank(MPI_COMM_WORLD, &myid);
  19.  
  20. //Initialize data to some value
  21. data = 20;
  22.  
  23. //If root
  24. if(myid==0)
  25. {
  26. data = 10;
  27. }
  28. //Bradcast the data
  29. MPI_Bcast(&data, 1, MPI_INT, 0, MPI_COMM_WORLD);
  30.  
  31. //Every process prints the value of data
  32. printf("myid:%d \t data = %d\n",myid, data);
  33.  
  34. //End MPI environment
  35. MPI_Finalize();}
Success #stdin #stdout #stderr 0.28s 40732KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted