From b6ad1bafc77c98ece3b533986c21e7c751f1328f Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Fri, 20 Oct 2023 19:24:38 -0400 Subject: [PATCH] Normal memory SendToRecvFrom asynchronous for use in general stencil code --- Grid/communicator/Communicator_base.h | 8 ++++++ Grid/communicator/Communicator_mpi3.cc | 38 ++++++++++++++++++++++++++ Grid/communicator/Communicator_none.cc | 11 ++++++++ 3 files changed, 57 insertions(+) diff --git a/Grid/communicator/Communicator_base.h b/Grid/communicator/Communicator_base.h index b98424a1..cd682dd0 100644 --- a/Grid/communicator/Communicator_base.h +++ b/Grid/communicator/Communicator_base.h @@ -138,6 +138,14 @@ public: //////////////////////////////////////////////////////////// // Face exchange, buffer swap in translational invariant way //////////////////////////////////////////////////////////// + void CommsComplete(std::vector &list); + void SendToRecvFromBegin(std::vector &list, + void *xmit, + int dest, + void *recv, + int from, + int bytes,int dir); + void SendToRecvFrom(void *xmit, int xmit_to_rank, void *recv, diff --git a/Grid/communicator/Communicator_mpi3.cc b/Grid/communicator/Communicator_mpi3.cc index e7d7a96d..ec004a9b 100644 --- a/Grid/communicator/Communicator_mpi3.cc +++ b/Grid/communicator/Communicator_mpi3.cc @@ -306,6 +306,44 @@ void CartesianCommunicator::GlobalSumVector(double *d,int N) int ierr = MPI_Allreduce(MPI_IN_PLACE,d,N,MPI_DOUBLE,MPI_SUM,communicator); assert(ierr==0); } + +void CartesianCommunicator::SendToRecvFromBegin(std::vector &list, + void *xmit, + int dest, + void *recv, + int from, + int bytes,int dir) +{ + MPI_Request xrq; + MPI_Request rrq; + + assert(dest != _processor); + assert(from != _processor); + + int tag; + + tag= dir+from*32; + int ierr=MPI_Irecv(recv, bytes, MPI_CHAR,from,tag,communicator,&rrq); + assert(ierr==0); + list.push_back(rrq); + + tag= dir+_processor*32; + ierr =MPI_Isend(xmit, bytes, MPI_CHAR,dest,tag,communicator,&xrq); + assert(ierr==0); + list.push_back(xrq); +} +void CartesianCommunicator::CommsComplete(std::vector &list) +{ + int nreq=list.size(); + + if (nreq==0) return; + + std::vector status(nreq); + int ierr = MPI_Waitall(nreq,&list[0],&status[0]); + assert(ierr==0); + list.resize(0); +} + // Basic Halo comms primitive void CartesianCommunicator::SendToRecvFrom(void *xmit, int dest, diff --git a/Grid/communicator/Communicator_none.cc b/Grid/communicator/Communicator_none.cc index a06e054d..7e7dfac8 100644 --- a/Grid/communicator/Communicator_none.cc +++ b/Grid/communicator/Communicator_none.cc @@ -91,6 +91,17 @@ void CartesianCommunicator::SendToRecvFrom(void *xmit, { assert(0); } +void CartesianCommunicator::CommsComplete(std::vector &list){ assert(0);} +void CartesianCommunicator::SendToRecvFromBegin(std::vector &list, + void *xmit, + int dest, + void *recv, + int from, + int bytes,int dir) +{ + assert(0); +} + void CartesianCommunicator::AllToAll(int dim,void *in,void *out,uint64_t words,uint64_t bytes) { bcopy(in,out,bytes*words);