C++ mpi module for stochmagnet_main Package
MPI_RAMIO.h
1 #ifndef MPI_RAMIO_H
2 #define MPI_RAMIO_H
3 
4 //inherited header
5 #include "MPI_Object.h"
6 
7 //mpi environment header
8 #include "MPI_Environment.h"
9 
10 //mpi type header
11 #include "MPI_Type.h"
12 
22 template<typename T>
23 class MPI_RAMIO : public MPI_Object {
24 
25  //attributes
26 private :
27  std::valarray<T> mMemory;
28  int mMPITSize;//MPI size of T
29  MPI_Win mWin;//ramWindow
30 public:
31  // CONSTRUCTORS
35  MPI_Type::GetSize<T>(mMPITSize);
36  }
37 
38  // DESTRUCTORS
41  virtual ~MPI_RAMIO(void) {
42 
43  }
44 
48  MPI_RAMIO<T>& operator=(const T& value) {
49  if (value==0) {
50  memset(&mMemory[0],0,sizeof(T)*mMemory.size());
51  } else {
52  for(auto& v:mMemory) {
53  v=value;
54  }
55  }
56  return *this;
57  }
58 
59 
64  inline void openRAMWindow(const MPI_Environment& env,const tMPICount& n) {
65  mMemory.resize(n);
66  MPI_Win_create(&mMemory[0],(tMPIByte) mMPITSize*n,mMPITSize,MPI_INFO_NULL,env.getWorld(),&mWin);
67  }
70  inline void closeRAMWindow() {
71  MPI_Win_free(&mWin);
72 
73  }
76  inline void flush() {
77  MPI_Win_fence(0,mWin);
78  }
79 
80  //IO methods
81  //===============
82 
87  inline void read(std::valarray<T>& values,const tMPICoreId& srcCore) {
88  MPI_Get(&values[0],values.size(),MPI_Type::GetPrimaryType<T>(),
89  srcCore,0,values.size(),MPI_Type::GetPrimaryType<T>(),mWin);
90  }
95  inline void write(const std::valarray<T>& values,const tMPICoreId& destCore) {
96  MPI_Put(&values[0],values.size(),MPI_Type::GetPrimaryType<T>(),
97  destCore,0,values.size(),MPI_Type::GetPrimaryType<T>(),mWin);
98  }
99 
100 
101 
102 };
103 
104 #endif
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 base class of E-MicromM core package.
Definition: MPI_Object.h:32
This class is a class to modify directctly memory between 2 cores.
Definition: MPI_RAMIO.h:23
void closeRAMWindow()
close a ram window
Definition: MPI_RAMIO.h:70
MPI_RAMIO()
create
Definition: MPI_RAMIO.h:34
void openRAMWindow(const MPI_Environment &env, const tMPICount &n)
open a ram window of size n within the core this
Definition: MPI_RAMIO.h:64
void flush()
open the asscess
Definition: MPI_RAMIO.h:76
virtual ~MPI_RAMIO(void)
destroy
Definition: MPI_RAMIO.h:41
void read(std::valarray< T > &values, const tMPICoreId &srcCore)
read the memory
Definition: MPI_RAMIO.h:87
void write(const std::valarray< T > &values, const tMPICoreId &destCore)
read the memory
Definition: MPI_RAMIO.h:95
MPI_RAMIO< T > & operator=(const T &value)
initialize the RAM values
Definition: MPI_RAMIO.h:48