Skip to content
Snippets Groups Projects
Commit 6c31280e authored by Christian Engwer's avatar Christian Engwer
Browse files

Merge branch 'fix_mpi_gather_scatter' into 'master'

Fix mpi gather scatter

See merge request core/dune-common!885
parents c3bf4c3b b2bafd86
No related branches found
No related tags found
No related merge requests found
......@@ -307,12 +307,12 @@ namespace Dune
//! @copydoc Communication::igather
template<class TIN, class TOUT = std::vector<TIN>>
MPIFuture<TOUT, TIN> igather(TIN&& data_in, TOUT&& data_out, int root){
MPIFuture<TOUT, TIN> igather(TIN&& data_in, TOUT&& data_out, int root) const{
MPIFuture<TOUT, TIN> future(std::forward<TOUT>(data_out), std::forward<TIN>(data_in));
auto mpidata_in = future.get_send_mpidata();
auto mpidata_out = future.get_mpidata();
assert(root != me || mpidata_in.size()*procs <= mpidata_out.size());
int outlen = me==root * mpidata_in.size();
int outlen = (me==root) * mpidata_in.size();
MPI_Igather(mpidata_in.ptr(), mpidata_in.size(), mpidata_in.type(),
mpidata_out.ptr(), outlen, mpidata_out.type(),
root, communicator, &future.req_);
......@@ -345,7 +345,7 @@ namespace Dune
MPIFuture<TOUT, TIN> future(std::forward<TOUT>(data_out), std::forward<TIN>(data_in));
auto mpidata_in = future.get_send_mpidata();
auto mpidata_out = future.get_mpidata();
int inlen = me==root * mpidata_in.size();
int inlen = (me==root) * mpidata_in.size()/procs;
MPI_Iscatter(mpidata_in.ptr(), inlen, mpidata_in.type(),
mpidata_out.ptr(), mpidata_out.size(), mpidata_out.type(),
root, communicator, &future.req_);
......
......@@ -51,3 +51,10 @@ dune_add_test(SOURCES mpipacktest.cc
TIMEOUT 300
CMAKE_GUARD MPI_FOUND
LABELS quick)
dune_add_test(SOURCES mpigatherscattertest.cc
LINK_LIBRARIES dunecommon
MPI_RANKS 2
TIMEOUT 300
CMAKE_GUARD MPI_FOUND
LABELS quick)
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#include <config.h>
#include <iostream>
#include <array>
#include <vector>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/common/parallel/mpicommunication.hh>
#include <dune/common/exceptions.hh>
using namespace Dune;
int main(int argc, char** argv){
MPIHelper & mpihelper = MPIHelper::instance(argc, argv);
auto cc = mpihelper.getCommunication();
int rank = cc.rank();
int size = cc.size();
std::array<double, 2> data = {1.0 + rank, 2.0 + rank};
auto gathered = cc.igather(data, std::vector<double>(rank==0?2*size:0), 0).get();
for(auto& d : gathered)
d += 1;
cc.iscatter(gathered, data, 0).get();
if(data[0] != 2+rank ||
data[1] != 3+rank){
DUNE_THROW(Exception, "Wrong result after gather - scatter");
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment