#include<stdio.h>
#include<mpi.h>
int main(
int argc,
char *argv[]){
int numTasks, rank, rc0, rc1, rc2, rc3;
MPI_Request request[4];
MPI_Status status[4];
char sendChar;
char receiveChar;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &numTasks);
//get from -np
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
//each process's ID
if(rank == 0){
sendChar = 'A';
int count = 1;
int destRank = 1;
int sourceRank = 1;
//MPI_ANY_SOURCE
int tagSendMSGID = 6;
int tagRecvMSGID = 9;
rc0 = MPI_Isend(&sendChar, count, MPI_CHAR,
destRank, tagSendMSGID, MPI_COMM_WORLD, &request[0]);
rc1 = MPI_Irecv(&receiveChar, count, MPI_CHAR,
sourceRank, tagRecvMSGID, MPI_COMM_WORLD, &request[1]);
}
else
if(rank == 1){
sendChar = 'Z';
int count = 1;
int destRank = 0;
int sourceRank = 0;
int tagRecvMSGID = 6;
int tagSendMSGID = 9;
rc2 = MPI_Isend(&sendChar, count, MPI_CHAR,
destRank, tagSendMSGID, MPI_COMM_WORLD, &request[2]);
rc3 = MPI_Irecv(&receiveChar, count, MPI_CHAR,
sourceRank, tagRecvMSGID, MPI_COMM_WORLD, &request[3]);
}
//MPI_Waitall(4, request, status);
printf(
"Rank = %d, received char = %c, send char = %c\n",
rank, receiveChar, sendChar);
printf(
"rc0 = %d, rc1 = %d, rc2 = %d, rc3 = %d\n", rc0, rc1, rc2, rc3);
MPI_Finalize();
return 0;
}