Created
December 2, 2011 16:17
-
-
Save aprell/1423804 to your computer and use it in GitHub Desktop.
Nonblocking send and receive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <mpi.h> | |
#define WORKER(id) if (ID == (id)) | |
#define MASTER WORKER(0) | |
int main(int argc, char *argv[]) | |
{ | |
int numprocs, ID; | |
int next, prev; | |
int buf; | |
MPI_Request req; | |
MPI_Init(&argc, &argv); | |
MPI_Comm_size(MPI_COMM_WORLD, &numprocs); | |
MPI_Comm_rank(MPI_COMM_WORLD, &ID); | |
next = (ID + 1) % numprocs; | |
prev = (ID - 1 + numprocs) % numprocs; | |
MPI_Isend(&ID, 1, MPI_INT, next, 0, MPI_COMM_WORLD, &req); | |
MPI_Irecv(&buf, 1, MPI_INT, prev, 0, MPI_COMM_WORLD, &req); | |
//MPI_Irecv(&buf, 1, MPI_INT, MPI_ANY_SOURCE, 0, MPI_COMM_WORLD, &req); | |
MPI_Wait(&req, NULL); | |
printf("Worker %d: %d\n", ID, buf); | |
MPI_Finalize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment