fork download
  1. /*PID 0 has an array of integer values, It should send the array to pid 1 and
  2. pid 1 should receive the values*/
  3.  
  4. #include <mpi.h> //containd the MPI function type declaractions
  5. #include <stdio.h > // stands for standarad input output
  6. #include <string.h>
  7. int main()
  8. {
  9. int np;
  10. int pid;
  11. MPI_Init(NULL, NULL);
  12. MPI_Comm_size(MPI_COMM_WORLD, &np);
  13. MPI_Comm_rank(MPI_COMM_WORLD, &pid);
  14. MPI_Status sta;
  15. if (pid == 0)
  16. {
  17. int Send_Num[5] = { 10,20,30,40,50 };
  18. MPI_Send(&Send_Num, 5, MPI_INT, 1, 50, MPI_COMM_WORLD);
  19. printf("My processor id is %d and I'm the sender. \n", pid);
  20. }
  21. if (pid == 1)
  22. {
  23. int Recv_msg[5];
  24. int sum = 0;
  25. MPI_Recv(&Recv_msg, 5, MPI_INT, 0, 50, MPI_COMM_WORLD, &sta);
  26. printf("My processor id is %d and I'm the receiver. \n", pid);
  27. printf("Received Messages are,");
  28. for(int i=0;i<5;i++)
  29. {
  30. printf("%d \n",Recv_msg[i]);
  31. }
  32. }
  33. MPI_Finalize();
  34. return 0;
  35. }
Success #stdin #stdout #stderr 0.28s 40684KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: unexpected '/' in "/"
Execution halted