diff --git a/Grid/communicator/Communicator_base.cc b/Grid/communicator/Communicator_base.cc index 79efb90c..f9a4c442 100644 --- a/Grid/communicator/Communicator_base.cc +++ b/Grid/communicator/Communicator_base.cc @@ -57,18 +57,29 @@ int CartesianCommunicator::ProcessorCount(void) { return // very VERY rarely (Log, serial RNG) we need world without a grid //////////////////////////////////////////////////////////////////////////////// +#ifdef USE_GRID_REDUCTION +void CartesianCommunicator::GlobalSum(ComplexF &c) +{ + GlobalSumP2P(c); +} +void CartesianCommunicator::GlobalSum(ComplexD &c) +{ + GlobalSumP2P(c); +} +#else void CartesianCommunicator::GlobalSum(ComplexF &c) { GlobalSumVector((float *)&c,2); } -void CartesianCommunicator::GlobalSumVector(ComplexF *c,int N) -{ - GlobalSumVector((float *)c,2*N); -} void CartesianCommunicator::GlobalSum(ComplexD &c) { GlobalSumVector((double *)&c,2); } +#endif +void CartesianCommunicator::GlobalSumVector(ComplexF *c,int N) +{ + GlobalSumVector((float *)c,2*N); +} void CartesianCommunicator::GlobalSumVector(ComplexD *c,int N) { GlobalSumVector((double *)c,2*N); diff --git a/Grid/communicator/Communicator_mpi3.cc b/Grid/communicator/Communicator_mpi3.cc index 5fa70da4..192bb339 100644 --- a/Grid/communicator/Communicator_mpi3.cc +++ b/Grid/communicator/Communicator_mpi3.cc @@ -257,6 +257,25 @@ CartesianCommunicator::~CartesianCommunicator() } } } +#ifdef USE_GRID_REDUCTION +void CartesianCommunicator::GlobalSum(float &f){ + CartesianCommunicator::GlobalSumP2P(f); +} +void CartesianCommunicator::GlobalSum(double &d) +{ + CartesianCommunicator::GlobalSumP2P(d); +} +#else +void CartesianCommunicator::GlobalSum(float &f){ + int ierr=MPI_Allreduce(MPI_IN_PLACE,&f,1,MPI_FLOAT,MPI_SUM,communicator); + assert(ierr==0); +} +void CartesianCommunicator::GlobalSum(double &d) +{ + int ierr = MPI_Allreduce(MPI_IN_PLACE,&d,1,MPI_DOUBLE,MPI_SUM,communicator); + assert(ierr==0); +} +#endif void CartesianCommunicator::GlobalSum(uint32_t &u){ int ierr=MPI_Allreduce(MPI_IN_PLACE,&u,1,MPI_UINT32_T,MPI_SUM,communicator); assert(ierr==0); @@ -287,20 +306,11 @@ void CartesianCommunicator::GlobalMax(double &d) int ierr = MPI_Allreduce(MPI_IN_PLACE,&d,1,MPI_DOUBLE,MPI_MAX,communicator); assert(ierr==0); } -void CartesianCommunicator::GlobalSum(float &f){ - int ierr=MPI_Allreduce(MPI_IN_PLACE,&f,1,MPI_FLOAT,MPI_SUM,communicator); - assert(ierr==0); -} void CartesianCommunicator::GlobalSumVector(float *f,int N) { int ierr=MPI_Allreduce(MPI_IN_PLACE,f,N,MPI_FLOAT,MPI_SUM,communicator); assert(ierr==0); } -void CartesianCommunicator::GlobalSum(double &d) -{ - int ierr = MPI_Allreduce(MPI_IN_PLACE,&d,1,MPI_DOUBLE,MPI_SUM,communicator); - assert(ierr==0); -} void CartesianCommunicator::GlobalSumVector(double *d,int N) { int ierr = MPI_Allreduce(MPI_IN_PLACE,d,N,MPI_DOUBLE,MPI_SUM,communicator);