1 #ifndef MPI_CartEnvironment_H
2 #define MPI_CartEnvironment_H
5 #include "MPI_DirectionalGridEnvironment.h"
29 template<tUCInt N,tUCInt D=1>
89 inline static CORE_UniquePointer<SelfClass>
New(
const std::array<tMPICoreId,N>& nCoresPerDirection,
90 const std::array<tBoolean,N>& isPeriodicPerDirection,
91 int& argc,
char * argv[],
const tBoolean& isOpenMPEnabled) {
93 CORE_UniquePointer<SelfClass> p(
new SelfClass(argc,argv,isOpenMPEnabled),
98 MPI_Cart_create(MPI_COMM_WORLD,
99 (
int) N,nCoresPerDirection.data(),isPeriodicPerDirection.data(),
103 if (p->getWorld()==MPI_COMM_NULL) {
118 const std::array<tMPICoreId,N>& nCoresPerDirection) {
120 std::array<tMPIBoolean,N> periodicity;
121 for(
auto& Vi:periodicity) Vi=0;
123 return New(parent,nCoresPerDirection,periodicity,
true);
134 const std::array<tMPICoreId,N>& nCoresPerDirection,
135 const std::array<tBoolean,N>& isPeriodicPerDirection,
136 const int& canCoreIdBeChanged) {
137 std::array<int,N> periods;
139 for(
auto& Pk:periods) {
140 Pk=isPeriodicPerDirection[k];
143 return New(parent,nCoresPerDirection,periods,canCoreIdBeChanged);
153 const std::array<tMPICoreId,N>& nCoresPerDirection,
154 const std::array<tMPIBoolean,N>& isPeriodicPerDirection,
155 const int& canCoreIdBeChanged) {
156 CORE_UniquePointer<SelfClass> p(
new SelfClass(),
162 (
int) N,nCoresPerDirection.data(),isPeriodicPerDirection.data(),
166 if (p->getWorld()==MPI_COMM_NULL) {
182 CORE_UniquePointer<SelfClass> p(
new SelfClass(),
185 std::array<int,N+1> dims;
186 for(
auto& Dk:dims) Dk=1;
188 MPI_Cart_sub(parent.
getWorld(),&dims[0],&p->getWorld());
189 if (p->getWorld()==MPI_COMM_NULL) {
233 const std::array<tBoolean,N>& periodicity ) {
239 std::map<tUCInt,tMPICoreId> neighbors;
242 const tBoolean *iPeriod=
null;
248 tMPICoreId nextCoreId;
250 std::array<tCInt,N> dir;
254 tBoolean isInsideBounds;
257 std::array<tMPICoreId,N> neighborIndices;
258 tMPICoreId *iNeighborIndices;
259 const tMPICoreId *iNk=nGrids.data();
269 iPeriod=periodicity.data();
277 iNeighborIndices=neighborIndices.data();
278 for(
const auto& i:indices) {
280 (*iNeighborIndices)=i;
282 (*iNeighborIndices)+=(*iDir);
285 (*iNeighborIndices)+=(*iNk);
286 (*iNeighborIndices)%=(*iNk);
289 isInsideBounds=isInsideBounds && ((*iNeighborIndices)>=0) && ((*iNeighborIndices)<(*iNk));
298 nextCoreId=NULL_CORE;
299 if (isInsideBounds) {
302 MPI_Cart_rank(this->
getWorld(),neighborIndices.data(),&nextCoreId);
307 if (nextCoreId!=NULL_CORE) neighbors[index]=nextCoreId;
317 memset(dir.data(),0,
sizeof(tCInt)*N);
318 std::map<tUCInt,tMPICoreId>::iterator iNeighbors=neighbors.find(this->
GetDirectionIndex(dir));
319 if (iNeighbors!=neighbors.end()) neighbors.erase(iNeighbors);
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
This class is a cart Environment of templated dimension N.
Definition: MPI_CartEnvironment.h:30
virtual void initialize()
initialize the environment
Definition: MPI_CartEnvironment.h:217
void buildNeighborCoresList(const std::array< tMPICoreId, N > &nGrids, const std::array< tMPICoreId, N > &indices, const std::array< tBoolean, N > &periodicity)
build the neighbors with depth D
Definition: MPI_CartEnvironment.h:232
virtual tMemSize getMemorySize() const
return the memory size of the class
Definition: MPI_CartEnvironment.h:203
static CORE_UniquePointer< SelfClass > New(const MPI_Environment &parent, const std::array< tMPICoreId, N > &nCoresPerDirection)
create a new cart environment
Definition: MPI_CartEnvironment.h:117
virtual ~MPI_CartEnvironment(void)
destroy
Definition: MPI_CartEnvironment.h:69
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_CartEnvironment.h:89
static CORE_UniquePointer< MPI_CartEnvironment< N > > 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_CartEnvironment.h:152
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_CartEnvironment.h:133
MPI_CartEnvironment(int &argc, char *argv[], const tBoolean &isOpenMPEnabled)
create a root environment
Definition: MPI_CartEnvironment.h:60
static CORE_UniquePointer< SelfClass > New(const MPI_CartEnvironment< N+1, D > &parent, const tUCInt &dir)
create a hyper plan of the grids perpendicular to dir
Definition: MPI_CartEnvironment.h:180
MPI_CartEnvironment()
create a root environment
Definition: MPI_CartEnvironment.h:44
This class is a grid Environment of templated dimension N=1,2,3.
Definition: MPI_DirectionalGridEnvironment.h:30
virtual tMemSize getContentsMemorySize() const override
return the memory size of the included associations
Definition: MPI_DirectionalGridEnvironment.h:105
static tUCInt GetMaximumDirectionalNeighborsNumber()
get the maximum direction number : (2*D+1)^N when D is the neighbor Depth (D=0,1,2)
Definition: MPI_DirectionalGridEnvironment.h:191
static tUCInt GetDirectionIndex(const std::array< tCInt, N > &dir)
get the direction index from dir index=dir[0]+1+3*(dir[1]+1+3*(dir[2]+1)) in {0,27}
Definition: MPI_DirectionalGridEnvironment.h:287
virtual void initialize()
initialize the environment
Definition: MPI_DirectionalGridEnvironment.h:303
void setDirectionalNeighbors(const std::map< tUCInt, tMPICoreId > &neighbors)
set neighbors grids per face
Definition: MPI_DirectionalGridEnvironment.h:267
static void GetDirection(const tUCInt &index, std::array< tCInt, N > &dir)
get the direction dir from index: index=dir[0]+1+D*(dir[1]+1+3*(dir[2]+1)) in {0,27}
Definition: MPI_DirectionalGridEnvironment.h:279
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
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