C++ mpi module for stochmagnet_main Package
MPI_Run.h
1 #ifndef MPI_Run_H
2 #define MPI_Run_H
3 
4 //inherits header
5 #include "CORE_Run.h"
6 
7 //environement header
8 #include "MPI_GridEnvironment.h"
9 
10 //functions utilities header
11 #include "functions_array.h"
12 
24 class MPI_Run : public CORE_Run {
25 
26  //attributes
27 private :
28 
29  static CORE_UniquePointer<MPI_Environment> mEnvironment;
30 
31 public:
32  // CONSTRUCTORS
35  MPI_Run();
36 
37  // DESTRUCTORS
40  virtual ~MPI_Run(void);
41 
42 
43 public :
44  // CREATE class
45 
46 
47  //SET & GET methods
48 
49 
50 
51 
52  //MEMORY
53 
67  virtual tMemSize getMemorySize() const override {
68  return sizeof(*this)+getContentsMemorySize();
69  }
70 
71 
74  inline static void InitializeEnvironment(int argc,char *argv[],const tBoolean& isOpenMPEnabled) {
75  tString gridS="";
76  std::vector<tMPICoreId> coresGrid;
77  if (CORE_OptionsList::ReadOption(argc,argv,false,"cores-grid",gridS) &&
78  (gridS.length()>0) &&
79  (functions_array::parse(gridS,coresGrid)) &&
80  (coresGrid.size()<3) &&
81  (coresGrid.size()>0) &&
82  (functions_array::product(coresGrid)>=1) ) {
83 
84  switch(coresGrid.size()) {
85  case 1:
86  mEnvironment=MPI_GridEnvironment<1>::New({coresGrid[0]},argc,argv,isOpenMPEnabled);
87  break;
88  case 2:
89  mEnvironment=MPI_GridEnvironment<2>::New({coresGrid[0],coresGrid[1]},argc,argv,isOpenMPEnabled);
90  break;
91  case 3:
92  default:
93  mEnvironment=MPI_GridEnvironment<3>::New({coresGrid[0],coresGrid[1],coresGrid[2]},argc,argv,isOpenMPEnabled);
94  break;
95  }
96 
97  } else {
98  mEnvironment=MPI_Environment::New(argc,argv,isOpenMPEnabled);
99  }
100  }
103  inline static void InitializeEnvironment(int argc,char *argv[]) {
104  InitializeEnvironment(argc,argv,false);
105  }
108  inline static void FinalizeEnvironment() {
109  mEnvironment.reset();
110  }
111 
114  inline static MPI_Environment& GetEnvironment() {
115  return *mEnvironment.get();
116  }
117 
118  // running Methods
119 
123  static void SetLogOptions(const CORE_OptionsList& options);
124 
128  virtual void setLogOptions(const CORE_OptionsList& options) const override {
129  MPI_Run::SetLogOptions(options);
130  }
131 
136  virtual tBoolean printHelp(const CORE_OptionsList& options) const override {
137  int id;
139  if (id==0) {
140  CORE_Run::printHelp(options);
141  std::cout<<" usage mpiexec -n <nCores> "<<GetSoftName()<<" --file=<.grid file> load \n";
142  }
143  return true;
144  }
145 
146 
147 };
148 
149 
150 #endif
This class is an list of options.
Definition: CORE_OptionsList.h:36
static tBoolean ReadOption(int nArgs, char *argv[], const tBoolean &isCaseSensitive, const tString &optionName, tString &optionValue)
read the only the option with optionName in command line
Definition: CORE_OptionsList.cpp:260
This class is a Run class for core package.
Definition: CORE_Run.h:44
virtual tBoolean printHelp(const CORE_OptionsList &options) const
print the help
Definition: CORE_Run.cpp:209
virtual tMemSize getContentsMemorySize() const override
return the memory size in byte
Definition: CORE_Run.h:100
static const tString & GetSoftName()
get soft name
Definition: CORE_Run.h:115
This class is a Environment class to define MPI world.
Definition: MPI_Environment.h:36
static void GetCoreId(tMPICoreId &id)
get the id of the current process of common environment
Definition: MPI_Environment.h:210
static CORE_UniquePointer< MPI_Environment > New(int argc, char *argv[], const tBoolean &isOpenMPEnabled)
create a test class
Definition: MPI_Environment.h:116
static CORE_UniquePointer< SelfClass > New(const std::array< tMPICoreId, N > &nCoresPerDirection, int &argc, char *argv[], const tBoolean &isOpenMPEnabled)
create a new cart environment
Definition: MPI_GridEnvironment.h:129
This class is a Run class for MPI package.
Definition: MPI_Run.h:24
static MPI_Environment & GetEnvironment()
get the environment
Definition: MPI_Run.h:114
virtual tBoolean printHelp(const CORE_OptionsList &options) const override
print the help
Definition: MPI_Run.h:136
virtual void setLogOptions(const CORE_OptionsList &options) const override
create the output stream from the options
Definition: MPI_Run.h:128
virtual tMemSize getMemorySize() const override
return the memory size of the class and the memory size of all its attributes/associations
Definition: MPI_Run.h:67
static void FinalizeEnvironment()
finalize the environment
Definition: MPI_Run.h:108
static void SetLogOptions(const CORE_OptionsList &options)
create the output stream from the options
Definition: MPI_Run.cpp:21
static void InitializeEnvironment(int argc, char *argv[], const tBoolean &isOpenMPEnabled)
initialize the environment
Definition: MPI_Run.h:74
MPI_Run()
create
Definition: MPI_Run.cpp:9
static void InitializeEnvironment(int argc, char *argv[])
initialize the environment
Definition: MPI_Run.h:103
virtual ~MPI_Run(void)
destroy
Definition: MPI_Run.cpp:14