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();
29.}
MS4jaW5jbHVkZSA8c3RkbGliLmg+CjIuI2luY2x1ZGUgPHN0ZGlvLmg+CjMuI2luY2x1ZGUgIm1waS5oIgo0LmludCBtYWluKGludCBhcmdjLCBjaGFyKiBhcmd2W10pCjUuewo2LiAgIGludCB4LCB5LCBucCwgaWQ7CjcuICAgaW50IHRhZyA9IDQyOwo4LiAgIE1QSV9TdGF0dXMgc3RhdHVzOwo5LiAgIE1QSV9Jbml0KCZhcmdjLCAmYXJndik7CjEwLiAgIE1QSV9Db21tX3NpemUoTVBJX0NPTU1fV09STEQsICZucCk7CjExLiAgIE1QSV9Db21tX3JhbmsoTVBJX0NPTU1fV09STEQsICZpZCk7CjEyLiAgIGlmIChpZCA9PSAwKSAKMTMuICB7CjE0LiAgICAgIHByaW50ZigiV2UgaGF2ZSAlZCAgcHJvY2Vzc2VzIFxuIiwgbnApOwoJCQlwcmludGYoImp1c3QgdGVzdCBcbiIsIG5wKTsKMTUuICAgICAgeD01OwoxNi4gICAgICBwcmludGYoIlByb2Nlc3MgJWQgc2VuZGluZyB0byBwcm9jZXNzIDFcbiIsIGl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