2
0
mirror of https://github.com/boostorg/mpi.git synced 2026-01-27 07:02:09 +00:00
Files
mpi/test/nonblocking_test.cpp
Alain Miniussi 3051fc5aaa checkpoint
2018-08-24 18:49:32 +02:00

50 lines
1.4 KiB
C++

#include <boost/mpi/nonblocking.hpp>
#include <boost/mpi/communicator.hpp>
#include <boost/mpi/environment.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/serialization/string.hpp>
#include <iterator>
#include <algorithm>
using boost::mpi::communicator;
using boost::mpi::request;
using boost::mpi::status;
int main(int argc, char* argv[])
{
boost::mpi::environment env(argc, argv);
boost::mpi::communicator comm;
int value = 42;
int input;
int next = (comm.rank() + 1) % comm.size();
int prev = (comm.rank() + comm.size() - 1) % comm.size();
int tag = 2;
MPI_Request sreq;
MPI_Isend(&value, 1, MPI_INT, next, tag, comm, &sreq);
//request rreq = comm.irecv(prev, tag, input);
int probe = 0;
int test = 0;
MPI_Message msg;
do {
if (!test) {
MPI_Test(&sreq, &test, MPI_STATUS_IGNORE);
if (test) {
printf("Proc %i sent msg %i to Proc %i\n", comm.rank(), tag, next);
} else {
printf("Proc %i have not sent msg %i to Proc %i yet\n", comm.rank(), tag, next);
}
}
if (!probe) {
int err = MPI_Improbe(prev, tag,
comm, &probe,
&msg,
MPI_STATUS_IGNORE);
if (probe)
printf("Proc %i got msg %i from proc %i\n", comm.rank(), tag, prev);
else
printf("Proc %i haven't got msg %i from proc %i yet\n", comm.rank(), tag, prev);
}
} while(probe == 0 || test == 0);
return 0;
}