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