#include "MyMPI.hpp" #include "P2PComm_NB.hpp" #include "Cont2Cout.hpp" #include #include using namespace MF; using namespace Common; using std::cout; using std::endl; int main(int argc, char* argv[]) { MyMPI const* mpi = MyMPI::instance(); typedef std::vector VectorOfDouble; const size_t size = 10; VectorOfDouble data(size,0.0); for(size_t i=0; i<=data.size(); ++i) data[i] = i + 1; int factor = data.size() / mpi->size(); int start = mpi->rank() * factor; int end = (mpi->rank() + 1) * factor; if (mpi->rank() == (mpi->size() - 1) ) end += (data.size() % mpi->size()); cout << *mpi << " start: " << start << " end: " << end << endl; VectorOfDouble::value_type sum = std::accumulate(&data[start], &data[end], 0.0); int left = (mpi->rank() + 1) % mpi->size(); int right = (mpi->rank() - 1 + mpi->size()) % mpi->size(); int const cnt = 1; int const tag = 0; cout << *mpi << ": " << left << "<--" << mpi->rank() << "-->" << right << endl; cout << *mpi << " local sum: " << sum << endl; ITransceiver transceiver; transceiver.send(&sum, cnt, MPI::DOUBLE, left, tag); transceiver.send(&sum, cnt, MPI::DOUBLE, right, tag); MPI::Status status; transceiver.recv(cnt, MPI::DOUBLE, left, tag, status); sum += transceiver.getData()[0]; transceiver.recv(cnt, MPI::DOUBLE, right, tag, status); sum += transceiver.getData()[0]; cout << *mpi << " global sum = " << sum << endl; }