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 just test \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+CjMuI2luY2x1ZGUgIm1waS5oIgo0LmludCBtYWluKGludCBhcmdjLCBjaGFyKiBhcmd2W10pCjUuewo2LiAgIGludCB4LCB5LCBucCwgaWQ7CjcuICAgaW50IHRhZyA9IDQyOwo4LiAgIE1QSV9TdGF0dXMgc3RhdHVzOwo5LiAgIE1QSV9Jbml0KCZhcmdjLCAmYXJndik7CjEwLiAgIE1QSV9Db21tX3NpemUoTVBJX0NPTU1fV09STEQsICZucCk7CjExLiAgIE1QSV9Db21tX3JhbmsoTVBJX0NPTU1fV09STEQsICZpZCk7CjEyLiAgIGlmIChpZCA9PSAwKSAKMTMuICB7CjE0LiAgICAgIHByaW50ZigiV2UgaGF2ZSAlZCAganVzdCB0ZXN0IFxuIiwgbnApOwoxNS4gICAgICB4PTU7CjE2LiAgICAgIHByaW50ZigiUHJvY2VzcyAlZCBzZW5kaW5nIHRvIHByb2Nlc3MgMVxuIiwgaWQpOyAgCjE3LiAgICAgIHByaW50ZigiUHJvY2Vzc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