Created
November 30, 2022 20:42
-
-
Save benkirk/15aea836fa7feb9636bc7e799e714c15 to your computer and use it in GitHub Desktop.
test various MPI Send modes with 0-length messages between two ranks.
This file contains hidden or 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 <iostream> | |
#include <iomanip> | |
#include <cassert> | |
#include <unistd.h> | |
#include "mpi.h" | |
int main (int argc, char **argv) | |
{ | |
int numranks, rank; | |
char hn[256]; | |
gethostname(hn, sizeof(hn) / sizeof(char)); | |
MPI_Init(&argc, &argv); | |
MPI_Comm_size (MPI_COMM_WORLD, &numranks); | |
MPI_Comm_rank (MPI_COMM_WORLD, &rank); | |
assert (2 == numranks); | |
std::cout << "Hello from " << rank | |
<< " / " << std::string (hn) | |
<< ", running " << argv[0] << " on " | |
<< numranks << " ranks" | |
<< std::endl; | |
MPI_Barrier(MPI_COMM_WORLD); | |
if (0 == rank) | |
{ | |
// First, matched send/recv | |
{ | |
std::cout << "calling MPI_Send"; | |
MPI_Send (NULL, 0, MPI_INT, /* dest = */ 1, /* tag = */ 100, MPI_COMM_WORLD); | |
std::cout << "...done\n"; | |
} | |
// Next, matched isend/recv | |
{ | |
MPI_Request req; | |
std::cout << "calling MPI_Isend"; | |
MPI_Isend (NULL, 0, MPI_INT, /* dest = */ 1, /* tag = */ 200, MPI_COMM_WORLD, &req); | |
MPI_Wait(&req, MPI_STATUS_IGNORE); | |
std::cout << "...done\n"; | |
} | |
// Next, matched ssend/recv | |
{ | |
std::cout << "calling MPI_Ssend"; | |
MPI_Ssend (NULL, 0, MPI_INT, /* dest = */ 1, /* tag = */ 300, MPI_COMM_WORLD); | |
std::cout << "...done\n"; | |
} | |
// Next, matched isend/recv | |
{ | |
MPI_Request req; | |
std::cout << "calling MPI_Issend"; | |
MPI_Issend (NULL, 0, MPI_INT, /* dest = */ 1, /* tag = */ 400, MPI_COMM_WORLD, &req); | |
MPI_Wait(&req, MPI_STATUS_IGNORE); | |
std::cout << "...done\n"; | |
} | |
} | |
else | |
{ | |
MPI_Recv (NULL, 0, MPI_INT, /* dest = */ 0, /* tag = */ 100, MPI_COMM_WORLD, MPI_STATUS_IGNORE); | |
MPI_Recv (NULL, 0, MPI_INT, /* dest = */ 0, /* tag = */ 200, MPI_COMM_WORLD, MPI_STATUS_IGNORE); | |
MPI_Recv (NULL, 0, MPI_INT, /* dest = */ 0, /* tag = */ 300, MPI_COMM_WORLD, MPI_STATUS_IGNORE); | |
MPI_Recv (NULL, 0, MPI_INT, /* dest = */ 0, /* tag = */ 400, MPI_COMM_WORLD, MPI_STATUS_IGNORE); | |
} | |
MPI_Finalize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment