fork download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "mpi.h"
  4. int main(int argc, char* argv[])
  5. {
  6. int x, y, np, id;
  7. int tag = 42;
  8. MPI_Status status;
  9. MPI_Init(&argc, &argv);
  10. MPI_Comm_size(MPI_COMM_WORLD, &np);
  11. MPI_Comm_rank(MPI_COMM_WORLD, &id);
  12. if (id == 0)
  13. {
  14. printf("We have %d processes \n", np);
  15. x=5;
  16. printf("Process %d sending to process 1\n", id);
  17. printf("Process %d sent %d to process 1\n", id, x);
  18. MPI_Send(&x, 1, MPI_INT, 1, tag, MPI_COMM_WORLD);
  19. }
  20. else
  21. { /* id == 1 */
  22. printf("Process %d receiving from process 0\n", id);
  23. MPI_Recv (&y, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
  24. printf("Process %d received %d form process 0\n", id, y);
  25. printf("Result= %d \n",y*2);
  26. }
  27. MPI_Finalize();
  28. exit(0);
  29. }
Success #stdin #stdout #stderr 0.3s 40420KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected symbol in "int main"
Execution halted