1 #ifndef MPI_CanonicalGridEnvironment_H
2 #define MPI_CanonicalGridEnvironment_H
5 #include "MPI_GridEnvironment.h"
8 #include "core_numeric.h"
44 std::array<tMPICoreId,2*N> mFaceNeighbors;
103 mem+=
sizeof(tMPICoreId)*mFaceNeighbors.size();
124 inline static CORE_UniquePointer<SelfClass>
New(
const std::array<tMPICoreId,N>& nCoresPerDirection,
125 const std::array<tBoolean,N>& isPeriodicPerDirection,
126 int& argc,
char * argv[],
const tBoolean& isOpenMPEnabled) {
128 CORE_UniquePointer<SelfClass> p(
new SelfClass(argc,argv,isOpenMPEnabled),
133 MPI_Cart_create(MPI_COMM_WORLD,
134 (
int) N,nCoresPerDirection.data(),isPeriodicPerDirection.data(),
138 if (p->getWorld()==MPI_COMM_NULL) {
153 const std::array<tMPICoreId,N>& nCoresPerDirection) {
155 std::array<tMPIBoolean,N> periodicity;
156 for(
auto& Vi:periodicity) Vi=0;
158 return New(parent,nCoresPerDirection,periodicity,
true);
169 const std::array<tMPICoreId,N>& nCoresPerDirection,
170 const std::array<tMPIBoolean,N>& isPeriodicPerDirection,
171 const int& canCoreIdBeChanged) {
172 CORE_UniquePointer<SelfClass> p(
new SelfClass(),
178 (
int) N,nCoresPerDirection.data(),isPeriodicPerDirection.data(),
182 if (p->getWorld()==MPI_COMM_NULL) {
199 const std::array<tMPICoreId,N>& nCoresPerDirection,
200 const std::array<tBoolean,N>& isPeriodicPerDirection,
201 const int& canCoreIdBeChanged) {
202 std::array<int,N> periods;
204 for(
auto& Pk:periods) {
205 Pk=isPeriodicPerDirection[k];
208 return New(parent,nCoresPerDirection,periods,canCoreIdBeChanged);
217 CORE_UniquePointer<SelfClass> p(
new SelfClass(),
220 std::array<int,N+1> dims;
221 for(
auto& Dk:dims) Dk=1;
223 MPI_Cart_sub(parent.
getWorld(),&dims[0],&p->getWorld());
224 if (p->getWorld()==MPI_COMM_NULL) {
269 const std::array<tMPICoreId,N>& indices,
280 std::array<tMPICoreId,N> neighborIndices=indices;
283 tMPICoreId *iFaceNeighbors=mFaceNeighbors.data();
286 tBoolean isInsideBound;
290 tMPICoreId neighborCoreId;
294 const tMPICoreId* iIndices=indices.data();
296 tMPICoreId *iNeighborIndices=neighborIndices.data();
299 const tBoolean* iIsPeriodic=
isPeriodic.data();
301 for (
const auto& Nk:nGrids) {
306 for(eps=-1;eps<2;eps+=2) {
311 (*iNeighborIndices)=(*iIndices);
312 (*iNeighborIndices)+=eps;
315 (*iNeighborIndices)+=Nk;
316 (*iNeighborIndices)%=Nk;
319 isInsideBound=((*iNeighborIndices)>=0) && ((*iNeighborIndices)<Nk);
322 MPI_Cart_rank(this->
getWorld(),neighborIndices.data(),&neighborCoreId);
325 (*iFaceNeighbors)=neighborCoreId;
327 (*iFaceNeighbors)=NULL_CORE;
335 (*iNeighborIndices)=(*iIndices);
356 return mFaceNeighbors[f];
363 inline void getFaceNeighbors(
const tUCInt& k,tMPICoreId& previousNeighbor,tMPICoreId& nextNeighbor)
const {
364 const tMPICoreId *iNeighbors=&mFaceNeighbors[k+k];
365 previousNeighbor=*iNeighbors;iNeighbors++;
366 nextNeighbor=*iNeighbors;
373 return mFaceNeighbors;
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
This class is a grid Environment of templated dimension N=1,2,3.
Definition: MPI_CanonicalGridEnvironment.h:32
virtual void initialize()
initialize the environment
Definition: MPI_CanonicalGridEnvironment.h:251
static CORE_UniquePointer< SelfClass > New(const MPI_Environment &parent, const std::array< tMPICoreId, N > &nCoresPerDirection, const std::array< tMPIBoolean, N > &isPeriodicPerDirection, const int &canCoreIdBeChanged)
create a new cart grid environment
Definition: MPI_CanonicalGridEnvironment.h:168
virtual ~MPI_CanonicalGridEnvironment(void)
destroy
Definition: MPI_CanonicalGridEnvironment.h:77
static CORE_UniquePointer< SelfClass > New(const MPI_CanonicalGridEnvironment< N+1 > &parent, const tUCInt &dir)
create a hyper plan of the grids perpendicular to dir
Definition: MPI_CanonicalGridEnvironment.h:215
virtual tMemSize getContentsMemorySize() const override
return the memory size of the included associations
Definition: MPI_CanonicalGridEnvironment.h:101
MPI_CanonicalGridEnvironment(int &argc, char *argv[], const tBoolean &isOpenMPEnabled)
create a root environment
Definition: MPI_CanonicalGridEnvironment.h:69
static CORE_UniquePointer< SelfClass > New(const MPI_Environment &parent, const std::array< tMPICoreId, N > &nCoresPerDirection)
create a new cart grid environment
Definition: MPI_CanonicalGridEnvironment.h:152
void getFaceNeighbors(const tUCInt &k, tMPICoreId &previousNeighbor, tMPICoreId &nextNeighbor) const
get the neighbor cores
Definition: MPI_CanonicalGridEnvironment.h:363
MPI_CanonicalGridEnvironment()
create a root environment
Definition: MPI_CanonicalGridEnvironment.h:54
static CORE_UniquePointer< SelfClass > New(const MPI_Environment &parent, const std::array< tMPICoreId, N > &nCoresPerDirection, const std::array< tBoolean, N > &isPeriodicPerDirection, const int &canCoreIdBeChanged)
create a new cart grid environment
Definition: MPI_CanonicalGridEnvironment.h:198
const tMPICoreId & getFaceNeighbor(const tUCInt &f) const
get the neighbor core
Definition: MPI_CanonicalGridEnvironment.h:355
const std::array< tMPICoreId, 2 *N > & getFaceNeighbors() const
get the face neighbor cores
Definition: MPI_CanonicalGridEnvironment.h:372
virtual tMemSize getMemorySize() const override
return the memory size of the class
Definition: MPI_CanonicalGridEnvironment.h:89
static CORE_UniquePointer< SelfClass > New(const std::array< tMPICoreId, N > &nCoresPerDirection, const std::array< tBoolean, N > &isPeriodicPerDirection, int &argc, char *argv[], const tBoolean &isOpenMPEnabled)
create a new cart environment
Definition: MPI_CanonicalGridEnvironment.h:124
void setFaceNeighbors(const std::array< tMPICoreId, N > &nGrids, const std::array< tMPICoreId, N > &indices, const std::array< tBoolean, N > &isPeriodic)
set the face neighbors from directional neighbors
Definition: MPI_CanonicalGridEnvironment.h:268
This class is a Environment class to define MPI world.
Definition: MPI_Environment.h:36
const tMPIComm & getWorld() const
get the world of the environment for reading
Definition: MPI_Environment.h:165
This class is a grid Environment of templated dimension N=1,2,3.
Definition: MPI_GridEnvironment.h:34
const std::array< tMPICoreId, N > & getGridSize() const
get the grids number
Definition: MPI_GridEnvironment.h:200
const std::array< tBoolean, N > & getGridPeriodicity() const
return the periodicity of the grid
Definition: MPI_GridEnvironment.h:356
const std::array< tMPICoreId, N > & getIndices() const
get the indices of the current core within the grid environment
Definition: MPI_GridEnvironment.h:219
virtual void initialize()
initialize the environment
Definition: MPI_GridEnvironment.h:388
virtual tMemSize getContentsMemorySize() const override
return the memory size of the included associations
Definition: MPI_GridEnvironment.h:112
const tBoolean & isPeriodic(const tUCInt &k) const
return true if the grid is periodic in direction k
Definition: MPI_GridEnvironment.h:363