fork(2) 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. 15. x=5;
  16. 16. printf("Process %d sending to process 1\n", id);
  17. 17. printf("Process %d sent %d to process 1\n", id, x);
  18. 18. MPI_Send(&x, 1, MPI_INT, 1, tag, MPI_COMM_WORLD);
  19. 19. }
  20. 20.else
  21. 21.{ /* id == 1 */
  22. 22. printf("Process %d receiving from process 0\n", id);
  23. 23. MPI_Recv (&y, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
  24. 24. printf("Process %d received %d form process 0\n", id, y);
  25. 25. printf("Result= %d \n",y*2);
  26. 26.}
  27. 27.MPI_Finalize();
  28. 28.exit(0);
  29. 29.}
  30.  
Success #stdin #stdout #stderr 0.27s 40944KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error in library(Rmpi) : there is no package called ‘Rmpi’
Execution halted