From 2be21a13dd8f06e9071ee3e1702921cdd6167efd Mon Sep 17 00:00:00 2001 From: Marco Agnese <m.agnese13@imperial.ac.uk> Date: Tue, 24 Nov 2015 15:32:57 +0000 Subject: [PATCH] use MPI_Get_address instead of MPI_Adress with MPI>=2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 2125b2839732fd9ba712bc1be41342896996e8a3) Signed-off-by: Steffen Müthing <muething@dune-project.org> --- dune/common/parallel/communicator.hh | 9 +++++++++ dune/common/parallel/indicessyncer.hh | 9 +++++++++ dune/common/parallel/mpihelper.hh | 4 ++-- dune/common/parallel/mpitraits.hh | 29 +++++++++++++++++++++++++++ dune/common/parallel/plocalindex.hh | 6 ++++++ dune/common/parallel/remoteindices.hh | 7 +++++++ 6 files changed, 62 insertions(+), 2 deletions(-) diff --git a/dune/common/parallel/communicator.hh b/dune/common/parallel/communicator.hh index 2d5ac757a..bcdebbbb7 100644 --- a/dune/common/parallel/communicator.hh +++ b/dune/common/parallel/communicator.hh @@ -419,8 +419,13 @@ namespace Dune { IndexedTypeInformation& info=information_[proc]; assert((info.elements)<info.size); + #if MPI_2 + MPI_Get_address( const_cast<void*>(CommPolicy<V>::getAddress(data_, local)), + info.displ+info.elements); + #else MPI_Address( const_cast<void*>(CommPolicy<V>::getAddress(data_, local)), info.displ+info.elements); + #endif info.length[info.elements]=CommPolicy<V>::getSize(data_, local); info.elements++; } @@ -1006,7 +1011,11 @@ namespace Dune IndexedTypeInformation& info=dataInfo.information_[process->first]; // Shift the displacement MPI_Aint base; + #if MPI_2 + MPI_Get_address(const_cast<void *>(CommPolicy<V>::getAddress(data, 0)), &base); + #else MPI_Address(const_cast<void *>(CommPolicy<V>::getAddress(data, 0)), &base); + #endif for(int i=0; i< info.elements; i++) { info.displ[i]-=base; diff --git a/dune/common/parallel/indicessyncer.hh b/dune/common/parallel/indicessyncer.hh index 1d38ccb06..178464e86 100644 --- a/dune/common/parallel/indicessyncer.hh +++ b/dune/common/parallel/indicessyncer.hh @@ -640,11 +640,20 @@ namespace Dune // Compute displacement MessageInformation message; + #if MPI_2 + MPI_Get_address( &(message.publish), displacement); + MPI_Get_address( &(message.pairs), displacement+1); + #else MPI_Address( &(message.publish), displacement); MPI_Address( &(message.pairs), displacement+1); + #endif // Make the displacement relative + #if MPI_2 + MPI_Get_address(&message, &base); + #else MPI_Address(&message, &base); + #endif displacement[0] -= base; displacement[1] -= base; diff --git a/dune/common/parallel/mpihelper.hh b/dune/common/parallel/mpihelper.hh index fd8822c6f..bcbcd0992 100644 --- a/dune/common/parallel/mpihelper.hh +++ b/dune/common/parallel/mpihelper.hh @@ -261,14 +261,14 @@ namespace Dune //! \brief calls MPI_Finalize ~MPIHelper() { -#ifdef MPI_2 +#if MPI_2 int wasFinalized = -1; MPI_Finalized( &wasFinalized ); if(!wasFinalized) { #endif MPI_Finalize(); dverb << "Called MPI_Finalize on p=" << rank_ << "!" <<std::endl; -#ifdef MPI_2 +#if MPI_2 } #endif diff --git a/dune/common/parallel/mpitraits.hh b/dune/common/parallel/mpitraits.hh index e22ce48b1..222e517ad 100644 --- a/dune/common/parallel/mpitraits.hh +++ b/dune/common/parallel/mpitraits.hh @@ -97,12 +97,21 @@ namespace Dune FieldVector<K,n> fvector; MPI_Aint base; MPI_Aint displ; + #if MPI_2 + MPI_Get_address(&fvector, &base); + MPI_Get_address(&(fvector[0]), &displ); + #else MPI_Address(&fvector, &base); MPI_Address(&(fvector[0]), &displ); + #endif displ -= base; int length[1]={1}; + #if MPI_2 + MPI_Type_create_struct(1, length, &displ, &vectortype, &datatype); + #else MPI_Type_struct(1, length, &displ, &vectortype, &datatype); + #endif MPI_Type_commit(&datatype); } return datatype; @@ -134,11 +143,20 @@ namespace Dune bigunsignedint<k> data; MPI_Aint base; MPI_Aint displ; + #if MPI_2 + MPI_Get_address(&data, &base); + MPI_Get_address(&(data.digit), &displ); + #else MPI_Address(&data, &base); MPI_Address(&(data.digit), &displ); + #endif displ -= base; int length[1]={1}; + #if MPI_2 + MPI_Type_create_struct(1, length, &displ, &vectortype, &datatype); + #else MPI_Type_struct(1, length, &displ, &vectortype, &datatype); + #endif MPI_Type_commit(&datatype); } return datatype; @@ -171,13 +189,24 @@ namespace Dune MPITraits<T2>::getType(), MPI_UB}; std::pair<T1,T2> rep[2]; length[0]=length[1]=length[2]=length[3]=1; + #if MPI_2 + MPI_Get_address(rep, disp); // lower bound of the datatype + MPI_Get_address(&(rep[0].first), disp+1); + MPI_Get_address(&(rep[0].second), disp+2); + MPI_Get_address(rep+1, disp+3); // upper bound of the datatype + #else MPI_Address(rep, disp); // lower bound of the datatype MPI_Address(&(rep[0].first), disp+1); MPI_Address(&(rep[0].second), disp+2); MPI_Address(rep+1, disp+3); // upper bound of the datatype + #endif for(int i=3; i >= 0; --i) disp[i] -= disp[0]; + #if MPI_2 + MPI_Type_create_struct(4, length, disp, types, &type); + #else MPI_Type_struct(4, length, disp, types, &type); + #endif MPI_Type_commit(&type); } return type; diff --git a/dune/common/parallel/plocalindex.hh b/dune/common/parallel/plocalindex.hh index 994cf4b0d..e371545d8 100644 --- a/dune/common/parallel/plocalindex.hh +++ b/dune/common/parallel/plocalindex.hh @@ -294,9 +294,15 @@ namespace Dune MPI_Datatype types[3] = {MPI_LB, MPITraits<char>::getType(), MPI_UB}; ParallelLocalIndex<T> rep[2]; length[0]=length[1]=length[2]=1; + #if MPI_2 + MPI_Get_address(rep, disp); // lower bound of the datatype + MPI_Get_address(&(rep[0].attribute_), disp+1); + MPI_Get_address(rep+1, disp+2); // upper bound of the datatype + #else MPI_Address(rep, disp); // lower bound of the datatype MPI_Address(&(rep[0].attribute_), disp+1); MPI_Address(rep+1, disp+2); // upper bound of the datatype + #endif for(int i=2; i >= 0; --i) disp[i] -= disp[0]; MPI_Type_struct(3, length, disp, types, &type); diff --git a/dune/common/parallel/remoteindices.hh b/dune/common/parallel/remoteindices.hh index f224ba685..fc0cd13c8 100644 --- a/dune/common/parallel/remoteindices.hh +++ b/dune/common/parallel/remoteindices.hh @@ -891,10 +891,17 @@ namespace Dune { MPITraits<ParallelLocalIndex<TA> >::getType(), MPI_UB}; IndexPair<TG,ParallelLocalIndex<TA> > rep[2]; length[0]=length[1]=length[2]=length[3]=1; + #if MPI_2 + MPI_Get_address(rep, disp); // lower bound of the datatype + MPI_Get_address(&(rep[0].global_), disp+1); + MPI_Get_address(&(rep[0].local_), disp+2); + MPI_Get_address(rep+1, disp+3); // upper bound of the datatype + #else MPI_Address(rep, disp); // lower bound of the datatype MPI_Address(&(rep[0].global_), disp+1); MPI_Address(&(rep[0].local_), disp+2); MPI_Address(rep+1, disp+3); // upper bound of the datatype + #endif for(int i=3; i >= 0; --i) disp[i] -= disp[0]; MPI_Type_struct(4, length, disp, types, &type); -- GitLab