fork download
  1. #include<stdio.h>
  2. #include<mpi.h>
  3. #include<math.h>
  4. int main(int argc, char* argv[])
  5. {
  6. int rank,size;
  7. int x;
  8. double power;
  9. MPI_Init(&argc,&argv);
  10. MPI_Comm_rank(MPI_COMM_WORLD,&rank);
  11. MPI_Comm_size(MPI_COMM_WORLD,&size);
  12. if(rank == 0){
  13. printf("Please enter the value for x \n");
  14. fflush(stdout);//To Ensure prompt is printed before waiting for the input
  15. scanf("%d", &x);
  16. //done so that only one thread takes the unput
  17. }
  18. //now broadcast the input to all the processes
  19. MPI_Bcast(&x, 1, MPI_INT, 0 , MPI_COMM_WORLD);
  20. //this is to broadcast so x is the variable, 1 is the one value, MPI int is the datatype and 0 is the rank to broadcast from
  21. power = pow(rank,x);
  22. printf("the power for the process with rank %d to %d is %f \n",rank,x,power);
  23. MPI_Finalize();
  24. return 0;
  25. }
Success #stdin #stdout #stderr 0.31s 40664KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted