#include "MyMPI.hpp" #include #include #include using std::cout; using std::endl; using namespace MF; int main(int argc, char* argv[]) { MyMPI const* mpi = MyMPI::instance(); int const root = 0; typedef std::vector VectorOfInts; VectorOfInts sendBuf(mpi->rank() + 1,-1); VectorOfInts* recvBuf = NULL; VectorOfInts* recvCount = NULL; VectorOfInts* recvDispl = NULL; int* pRecvBuf = NULL; int* pRecvCount = NULL; int* pRecvDispl = NULL; for (unsigned int i=0; irank()*10 + i; if(mpi->rank() == root) { int const stride = 3; recvCount = new VectorOfInts(mpi->size(), 1); recvDispl = new VectorOfInts(mpi->size(), 0); for(int i=1; isize(); ++i) { (*recvCount)[i] = i + 1; (*recvDispl)[i] = (*recvDispl)[i-1] + i + stride; } recvBuf = new VectorOfInts(recvCount->back() + recvDispl->back(),-1); pRecvBuf = &(*recvBuf)[0]; pRecvCount = &(*recvCount)[0]; pRecvDispl = &(*recvDispl)[0]; } cout << *mpi->instance() << " "; std::copy(sendBuf.begin(), sendBuf.end(), std::ostream_iterator(std::cout," ")); cout << endl; mpi->world().Gatherv(&sendBuf[0], sendBuf.size(), MPI::INT, pRecvBuf, pRecvCount, pRecvDispl, MPI::INT, root); if(mpi->rank() == root) { cout << *mpi->instance() << " "; std::copy(recvBuf->begin(), recvBuf->end(), std::ostream_iterator(std::cout," ")); cout << endl; delete recvBuf; delete recvCount; delete recvDispl; } return 0; }