C++ mpi module for stochmagnet_main Package
MPI_View.h
1 #ifndef MPI_View_H
2 #define MPI_View_H
3 
4 //inherited class object
5 #include "MPI_Object.h"
6 
7 //MPI types header
8 #include "MPI_Type.h"
9 
20 class MPI_View : public MPI_Object {
21 
22  //attributes
23 private :
24 
25  tMPIIOIndex mStart;
26  tMPIType mType;//type of the initial element used to make the view
27  tMPIView mView;
28  tBoolean mIsRegistered;
29 
30 public:
31  // CONSTRUCTORS
32 
36  mIsRegistered=false;
37  }
38 
39 
40  // DESTRUCTORS
43  virtual ~MPI_View(void) {
44  if (mIsRegistered) MPI_Type::Unregister(mView);
45 
46 
47  }
48 
49 public:
50  //New methods
51  //------------
55  inline static CORE_UniquePointer<MPI_View> New() {
56  CORE_UniquePointer<MPI_View> p(new MPI_View(),
58 
59  return p;
60  };
61 
62 public:
63 
64 
65  //ACCESSORS methods
66  //================
67 
70  inline const tMPIIOIndex& getStartIndex() const {
71  return mStart;
72  }
75  inline const tMPIType& getType() const {
76  return mType;
77  }
80  inline const tMPIView& getMPIView() const {
81  return mView;
82  }
83 
84 
95  template<int N,typename T>
96  inline tBoolean createSubArrayView(const std::array<int,N>& arraySize,
97  const std::array<int,N>& startElement,
98  const std::array<int,N>& subarraySize) {
99  mType=MPI_Type::GetPrimaryType<T>();
100  if (mIsRegistered) {
101  mIsRegistered=false;
102  MPI_Type::Unregister(mView);
103  }
104  tBoolean ret=(MPI_Type_create_subarray(N,arraySize.data(),subarraySize.data(),startElement.data(),MPI_ORDER_C,mType,&mView)==MPI_SUCCESS);
105 
106  MPI_Type::Register(mView);
107  mIsRegistered=true;
108  return ret;
109  }
110 
111 
126  template<typename T>
127  inline tBoolean createVariableStepView(const tMPICount& nElements,
128  const std::valarray<tMPICount>& elementSizes,
129  const std::valarray<tMPICount>& elementIndices) {
130  if (mIsRegistered) {
131  mIsRegistered=false;
132  MPI_Type::Unregister(mView);
133  }
134 
135  //create a type with holes
136  tBoolean ret=(MPI_Type::CreateVariableStepType<T>(nElements,elementSizes,elementIndices,mType)==MPI_SUCCESS);
137 
138  //resize the type
139  //size of type Y
140  int sizeofT;
141  MPI_Type::GetSize<T>(sizeofT);
142 
143  //get the lower bp=bound & the extent of type
144  tMPIByte lb,extent;
145  MPI_Type::GetExtent(mType,lb,extent);
146 
147  //add one T elements size
148  extent+=sizeofT;
149  MPI_Type::Resize(mType,lb,extent,mView);
150 
151  //update the original type of the original element of the view
152  mType=MPI_Type::GetPrimaryType<T>();
153 
154  //register the view
155  MPI_Type::Register(mView);
156  mIsRegistered=true;
157 
158  return ret;
159 
160  }
161 
162 };
163 
164 
165 #endif
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
This class is a base class of E-MicromM core package.
Definition: MPI_Object.h:32
static tMPIError Unregister(tMPIType &type)
unregister the type
Definition: MPI_Type.h:598
static tMPIError Resize(const tMPIType dataType, const tMPIByte &lb, const tMPIByte &extent, tMPIType &newDataType)
resize the type
Definition: MPI_Type.h:578
static tMPIError Register(tMPIType &type)
register the type
Definition: MPI_Type.h:592
static tMPIError GetExtent(const tMPIType &mpiType, tMPIByte &start, tMPIByte &mpiSize)
get the mpi size (in octet) between the first element (in octet) and the last element of the mpi type...
Definition: MPI_Type.h:630
This class describes a view as follow:
Definition: MPI_View.h:20
virtual ~MPI_View(void)
destroy
Definition: MPI_View.h:43
const tMPIType & getType() const
get the type of the element of the view
Definition: MPI_View.h:75
MPI_View()
create a root environment
Definition: MPI_View.h:35
const tMPIIOIndex & getStartIndex() const
get the start index
Definition: MPI_View.h:70
static CORE_UniquePointer< MPI_View > New()
create a new instance of class within an unique pointer
Definition: MPI_View.h:55
const tMPIView & getMPIView() const
get the mpi view of the view
Definition: MPI_View.h:80
tBoolean createSubArrayView(const std::array< int, N > &arraySize, const std::array< int, N > &startElement, const std::array< int, N > &subarraySize)
create a sub array view of an array with N dimension
Definition: MPI_View.h:96
tBoolean createVariableStepView(const tMPICount &nElements, const std::valarray< tMPICount > &elementSizes, const std::valarray< tMPICount > &elementIndices)
create a variable step view
Definition: MPI_View.h:127