You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
802 B
33 lines
802 B
#include "mpi.h"
|
|
#include <stdio.h>
|
|
|
|
int main(argc,argv)
|
|
int argc;
|
|
char *argv[]; {
|
|
int numtasks, rank, next, prev, buf[2], tag1=1, tag2=2;
|
|
MPI_Request reqs[4];
|
|
MPI_Status stats[4];
|
|
|
|
MPI_Init(&argc,&argv);
|
|
MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
|
|
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
|
|
|
prev = rank-1;
|
|
next = rank+1;
|
|
if (rank == 0) prev = numtasks - 1;
|
|
if (rank == (numtasks - 1)) next = 0;
|
|
|
|
MPI_Irecv(&buf[0], 1, MPI_INT, prev, tag1, MPI_COMM_WORLD, &reqs[0]);
|
|
MPI_Irecv(&buf[1], 1, MPI_INT, next, tag2, MPI_COMM_WORLD, &reqs[1]);
|
|
|
|
MPI_Isend(&rank, 1, MPI_INT, prev, tag2, MPI_COMM_WORLD, &reqs[2]);
|
|
MPI_Isend(&rank, 1, MPI_INT, next, tag1, MPI_COMM_WORLD, &reqs[3]);
|
|
|
|
MPI_Waitall(4, reqs, stats);
|
|
|
|
printf("Process %d: Parelava ta stoixeia %d and %d\n", rank, buf[0], buf[1]);
|
|
|
|
MPI_Finalize();
|
|
}
|
|
|
|
|
|
|