fork download
  1. #include "mpi.h"
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7. int rank,size;
  8. int x;
  9. MPI_Init(&argc,&argv);
  10. MPI_Comm_rank(MPI_COMM_WORLD,&rank);
  11. MPI_Comm_size(MPI_COMM_WORLD,&size);
  12. MPI_Status status;
  13. printf("Enter the value of number");
  14.  
  15.  
  16. if (rank==0)
  17. {
  18. scanf("%d",&x);
  19. for (int i = 1; i <size ; i++)
  20. {
  21. MPI_Send(&x,1,MPI_INT,i,1,MPI_COMM_WORLD);
  22. }
  23. }
  24. else{
  25. MPI_Recv(&x,1,MPI_INT,0,1,MPI_COMM_WORLD,&status);
  26. printf("process of rank %d and the output is %d",rank,x);
  27. }
  28. MPI_Finalize();
  29.  
  30. return 0;
  31. }
Success #stdin #stdout #stderr 0.29s 40256KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted