C++ mpi module for stochmagnet_main Package
MPI_IOFile.h
1 #ifndef MPI_IOFile_H
2 #define MPI_IOFile_H
3 
4 //inherited class object
5 #include "MPI_Object.h"
6 
7 //environment header
8 #include "MPI_Environment.h"
9 
10 //MPI types header
11 #include "MPI_Type.h"
12 
13 //MPI error management header
14 #include "MPI_Error.h"
15 
16 //view header
17 #include "MPI_View.h"
18 
72 class MPI_IOFile : public MPI_Object {
73 
74  //attributes
75 public:
78  static const tMPIIOMode READ_ONLY=MPI_MODE_RDONLY;
81  static const tMPIIOMode WRITE_ONLY=MPI_MODE_WRONLY;
84  static const tMPIIOMode READ_WRITE=MPI_MODE_RDWR;
87  static const tMPIIOMode CREATE=MPI_MODE_CREATE;
90  static const tMPIErrorMode FATAL_ERROR;
93  static const tMPIErrorMode RETURN_ERROR;
94 
95 private :
96 
97  //name of the file
98  tString mFileName;
99  //file descriport
100  tMPIIOFile mFile;
101  //error afer instructions
102  tMPIError mError;
103 
104 public:
105  // CONSTRUCTORS
106 
110 
111  }
112 
113 
114  // DESTRUCTORS
117  virtual ~MPI_IOFile(void) {
118 
119 
120  }
121 public:
124  virtual tMemSize getMemorySize() const override{
125  return sizeof(*this)+getContentsMemorySize();
126  }
127 public:
128  //New methods
129  //------------
133  inline static CORE_UniquePointer<MPI_IOFile> New() {
134  CORE_UniquePointer<MPI_IOFile> p(new MPI_IOFile(),
136 
137  return p;
138  };
139 
140 public:
141 
142 public:
143 
144  //accessor
145  //=========
146 
150  inline void setFileName(const tString& fn) {
151  mFileName=fn;
152 
153  }
157  inline const tString& getFileName() const {
158  return mFileName;
159  }
162  inline const tMPIError& getError() const {
163  return mError;
164  }
165 
169  inline tMPIError setView(const MPI_View& view) {
170  return MPI_File_set_view(mFile,0,view.getType(),view.getMPIView(),"native",MPI_INFO_NULL);
171  }
176  inline tMPIError setView(const tMPIIOIndex& index,const MPI_View& view) {
177  return MPI_File_set_view(mFile,index,view.getType(),view.getMPIView(),"native",MPI_INFO_NULL);
178  }
179 
180  //opening & closing
181  //=================
182 
187  inline tBoolean open(const MPI_Environment& env,const tMPIIOMode& mode) {
188 
189  mError=MPI_File_open(env.getWorld(),mFileName.c_str(),mode,MPI_INFO_NULL,&mFile);
190  return (mError==MPI_SUCCESS);
191 
192  }
193 
200  inline static tBoolean Open(const MPI_Environment& env,
201  const tString& fn,const tMPIIOMode& mode,
202  tMPIIOFile& fdesc) {
203  return (MPI_File_open(env.getWorld(),fn.c_str(),mode,MPI_INFO_NULL,&fdesc)==MPI_SUCCESS);
204 
205  }
206 
210  inline static tMPIError Close(tMPIIOFile& f) {
211  return MPI_File_close(&f);
212  }
215  inline tBoolean close() {
216  mError=MPI_File_close(&mFile);
217  return (mError==MPI_SUCCESS);
218  }
219 
220  //write methods
221  //============
222 
232  template<typename T>
233  inline tBoolean writeAt(const tMPIIOIndex& pos,const std::valarray<T>& values,tMPIStatus& status) {
234  mError=MPI_File_write_at(mFile,pos,&values[0],values.size(),MPI_Type::GetPrimaryType<T>(),&status);
235  return (mError==MPI_SUCCESS);
236  }
245  template<typename T>
246  inline tBoolean iWriteAt(const tMPIIOIndex& pos,const std::valarray<T>& values,tMPIStatus& status) {
247  mError=MPI_File_iwrite_at(mFile,pos,&values[0],values.size(),MPI_Type::GetPrimaryType<T>(),&status);
248  return (mError==MPI_SUCCESS);
249  }
250 
251 
260  template<typename T>
261  inline tBoolean writeAll(const std::valarray<T>& values,tMPIStatus& status) {
262  mError=MPI_File_write_all(mFile,&values[0],values.size(),MPI_Type::GetPrimaryType<T>(),&status);
263  return (mError==MPI_SUCCESS);
264  }
271  inline tBoolean writeOrdered(const tString& str) {
272  std::valarray<tUChar> values;
273  values.resize(str.length());
274  memcpy(&values[0],str.c_str(),sizeof(tUChar)*values.size());
275  mError=MPI_File_write_ordered(mFile,&values[0],values.size(),MPI_Type::GetPrimaryType<tUChar>(),MPI_STATUS_IGNORE);
276  return (mError==MPI_SUCCESS);
277 
278  }
286  template<typename T>
287  inline tBoolean writeOrdered(const std::valarray<T>& values) {
288  mError=MPI_File_write_ordered(mFile,&values[0],values.size(),MPI_Type::GetPrimaryType<T>(),MPI_STATUS_IGNORE);
289  return (mError==MPI_SUCCESS);
290 
291  }
292 
293 
303  template<typename T>
304  inline tBoolean allWriteAt(const tMPIIOIndex& pos,const std::valarray<T>& values,tMPIStatus& status) {
305  mError=MPI_File_write_at_all(mFile,pos,&values[0],values.size(),MPI_Type::GetPrimaryType<T>(),&status);
306  return (mError==MPI_SUCCESS);
307  }
316  template<typename T>
317  inline tBoolean iAllWriteAt(const tMPIIOIndex& pos,const std::valarray<T>& values,tMPIStatus& status) {
318  mError=MPI_File_iwrite_at_all(mFile,pos,&values[0],values.size(),MPI_Type::GetPrimaryType<T>(),&status);
319  return (mError==MPI_SUCCESS);
320  }
321 
322  //read methods
323  //============
324 
333  template<typename T>
334  inline tBoolean readAt(const tMPIIOIndex& pos,std::valarray<T>& values,tMPIStatus& status) {
335  mError=MPI_File_read_at(mFile,pos,&values[0],values.size(),MPI_Type::GetPrimaryType<T>(),&status);
336  return (mError==MPI_SUCCESS);
337  }
338 
347  template<typename T>
348  inline tBoolean iReadAt(const tMPIIOIndex& pos,std::valarray<T>& values,tMPIRequest& request) {
349  mError=MPI_File_iread_at(mFile,pos,&values[0],values.size(),MPI_Type::GetPrimaryType<T>(),&request);
350  return (mError==MPI_SUCCESS);
351  }
352 
361  template<typename T>
362  inline tBoolean read(const tMPICount& n,T* values,tMPIStatus& status) {
363  mError=MPI_File_read(mFile,values,n,MPI_Type::GetPrimaryType<T>(),&status);
364  return (mError==MPI_SUCCESS);
365  }
366 
374  template<typename T>
375  inline tBoolean iRead(const tMPICount& n,T* values,tMPIRequest& request) {
376  mError=MPI_File_iread(mFile,values,n,MPI_Type::GetPrimaryType<T>(),&request);
377  return (mError==MPI_SUCCESS);
378  }
379 
380 
381 
392  template<typename T>
393  inline tBoolean allReadAt(const tMPIIOIndex& pos,std::valarray<T>& values,tMPIStatus& status) {
394  mError=MPI_File_read_at_all(mFile,pos,&values[0],values.size(),MPI_Type::GetPrimaryType<T>(),&status);
395  return (mError==MPI_SUCCESS);
396  }
405  template<typename T>
406  inline tBoolean iAllReadAt(const tMPIIOIndex& pos,std::valarray<T>& values,tMPIRequest& request) {
407  mError=MPI_File_iread_at_all(mFile,pos,&values[0],values.size(),MPI_Type::GetPrimaryType<T>(),&request);
408  return (mError==MPI_SUCCESS);
409  }
410 
420  template<typename T>
421  inline tBoolean allRead(const tMPICount& n,T* values,tMPIStatus& status) {
422  mError=MPI_File_read_all(mFile,values,n,MPI_Type::GetPrimaryType<T>(),&status);
423  return (mError==MPI_SUCCESS);
424  }
432  template<typename T>
433  inline tBoolean allRead(std::valarray<T>& values,tMPIStatus& status) {
434  mError=MPI_File_read_all(mFile,&values[0],values.size(),MPI_Type::GetPrimaryType<T>(),&status);
435  return (mError==MPI_SUCCESS);
436  }
444  template<typename T>
445  inline tBoolean iAllRead(const tMPICount& n,T* values,tMPIRequest& request) {
446  mError=MPI_File_iread_all(mFile,values,n,MPI_Type::GetPrimaryType<T>(),&request);
447  return (mError==MPI_SUCCESS);
448  }
449 
450 
460  template<typename T>
461  inline tBoolean sharedRead(const tMPICount& n,T* values,tMPIStatus& status) {
462  mError=MPI_File_read_shared(mFile,values,n,MPI_Type::GetPrimaryType<T>(),&status);
463  return (mError==MPI_SUCCESS);
464  }
474  template<typename T>
475  inline tBoolean iSharedRead(const tMPICount& n,T* values,tMPIRequest& request) {
476  mError=MPI_File_iread_shared(mFile,values,n,MPI_Type::GetPrimaryType<T>(),&request);
477  return (mError==MPI_SUCCESS);
478  }
479 
489  template<typename T>
490  inline tBoolean orderedRead(const tMPICount& n,T* values,tMPIStatus& status) {
491  mError=MPI_File_read_ordered(mFile,values,n,MPI_Type::GetPrimaryType<T>(),&status);
492  return (mError==MPI_SUCCESS);
493  }
502  template<typename T>
503  inline tBoolean orderedRead(std::valarray<T>& values,tMPIStatus& status) {
504  mError=MPI_File_read_ordered(mFile,values,values.size(),MPI_Type::GetPrimaryType<T>(),&status);
505  return (mError==MPI_SUCCESS);
506  }
515  template<typename T>
516  inline tBoolean iOrderedRead(const tMPICount& n,T* values,tMPIRequest& request) {
517  mError=MPI_File_iread_ordered(mFile,values,n,MPI_Type::GetPrimaryType<T>(),&request);
518  return (mError==MPI_SUCCESS);
519  }
520 
521  //file index management
522  //======================
523 
524  /* \brief get the position of the pointer of the file attached to one core
525  * @param[out] pos: core position of the cursor on file
526  */
527  tBoolean getCorePosition(tMPIIOIndex& pos) {
528  mError=MPI_File_get_position(mFile,&pos);
529  return (mError==MPI_SUCCESS);
530  }
531 
532  /* \brief set the position of the pointer of the file attached to one core
533  * @param[out] pos: core position of the cursor on file
534  */
535  tBoolean setCorePosition(const tMPIIOIndex& pos) {
536  mError=MPI_File_seek(mFile,pos,MPI_SEEK_SET);
537  return (mError==MPI_SUCCESS);
538  }
539  /* \brief set the position of the pointer of the file attached to one core
540  * @param[out] pos: core position of the cursor on file
541  */
542  tBoolean setCorePositionToEnd() {
543  mError=MPI_File_seek(mFile,0,MPI_SEEK_END);
544  return (mError==MPI_SUCCESS);
545  }
546  /* \brief mv the position of the pointer of the file attached to one core with displacement value
547  * @param[out] sds: displacement of the cursor on file
548  */
549  tBoolean moveCorePosition(const tMPIIOIndex& dis) {
550  mError=MPI_File_seek(mFile,dis,MPI_SEEK_CUR);
551  return (mError==MPI_SUCCESS);
552  }
553  /* \brief mv the position of the pointer of the file attached to one core with displacement value
554  * @param[out] dis: displacement of the cursor on file
555  */
556  tBoolean moveFromEndCorePosition(const tMPIIOIndex& dis) {
557  mError=MPI_File_seek(mFile,dis,MPI_SEEK_END);
558  return (mError==MPI_SUCCESS);
559  }
560 
564  tBoolean getEnvironmentPosition(tMPIIOIndex& pos) {
565  mError=MPI_File_get_position_shared(mFile,&pos);
566  return (mError==MPI_SUCCESS);
567  }
568 
572  tBoolean setEnvironmentPosition(const tMPIIOIndex& pos) {
573  mError=MPI_File_seek_shared(mFile,pos,MPI_SEEK_SET);
574  return (mError==MPI_SUCCESS);
575  }
576  /* \brief set the position of the pointer of the file attached to one core
577  * @param[out] pos: core position of the cursor on file
578  */
579  tBoolean setEnvironmentPositionToEnd() {
580  mError=MPI_File_seek_shared(mFile,0,MPI_SEEK_END);
581  return (mError==MPI_SUCCESS);
582  }
583  /* \brief mv the position of the pointer of the file attached to one core with displacement value
584  * @param[out] dis: displacement of the cursor on file
585  */
586  tBoolean moveEnvironmentPosition(const tMPIIOIndex& dis) {
587  mError=MPI_File_seek_shared(mFile,dis,MPI_SEEK_CUR);
588  return (mError==MPI_SUCCESS);
589  }
590  /* \brief mv the position of the pointer of the file attached to one core with displacement value
591  * @param[out] dis: displacement of the cursor on file
592  */
593  tBoolean moveFromEndEnvironmentPosition(const tMPIIOIndex& dis) {
594  mError=MPI_File_seek_shared(mFile,dis,MPI_SEEK_END);
595  return (mError==MPI_SUCCESS);
596  }
597 
598 
602  inline tBoolean getSize(tMPIIOIndex& s) const {
603  return (MPI_File_get_size(mFile,&s)==MPI_SUCCESS);
604  }
605 
606 
607  //error management
608  //==================
609 
613  inline void setErrorMode(const tMPIErrorMode& mode) {
614  MPI_File_set_errhandler(mFile,mode);
615  }
619  inline tString printError() const {
620  return MPI_Error::ToString(mError);
621  }
622 
623 };
624 
625 
626 #endif
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:278
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
static tString ToString(const tMPIError &err)
get the string representation of the error
Definition: MPI_Error.h:45
This class manges the reading & writing in one file.
Definition: MPI_IOFile.h:72
static const tMPIIOMode READ_WRITE
read and write mode
Definition: MPI_IOFile.h:84
tBoolean iAllWriteAt(const tMPIIOIndex &pos, const std::valarray< T > &values, tMPIStatus &status)
write the value at shared core by explicit file cursor position non blocking action
Definition: MPI_IOFile.h:317
tBoolean allWriteAt(const tMPIIOIndex &pos, const std::valarray< T > &values, tMPIStatus &status)
write the value at shared core by explicit file cursor position with blocking action
Definition: MPI_IOFile.h:304
const tString & getFileName() const
get the filename
Definition: MPI_IOFile.h:157
void setErrorMode(const tMPIErrorMode &mode)
set the error mode
Definition: MPI_IOFile.h:613
static tBoolean Open(const MPI_Environment &env, const tString &fn, const tMPIIOMode &mode, tMPIIOFile &fdesc)
open the file for the environment
Definition: MPI_IOFile.h:200
tBoolean allRead(const tMPICount &n, T *values, tMPIStatus &status)
read the value at implicit shared position with blocking action
Definition: MPI_IOFile.h:421
static CORE_UniquePointer< MPI_IOFile > New()
create a new instance of class within an unique pointer
Definition: MPI_IOFile.h:133
tBoolean close()
close the file
Definition: MPI_IOFile.h:215
static tMPIError Close(tMPIIOFile &f)
close the file
Definition: MPI_IOFile.h:210
tMPIError setView(const tMPIIOIndex &index, const MPI_View &view)
set the view
Definition: MPI_IOFile.h:176
tBoolean read(const tMPICount &n, T *values, tMPIStatus &status)
read the value at individual core by implplicit file cursor position with blocking action
Definition: MPI_IOFile.h:362
MPI_IOFile()
create a root environment
Definition: MPI_IOFile.h:109
tBoolean iAllReadAt(const tMPIIOIndex &pos, std::valarray< T > &values, tMPIRequest &request)
read the value at explicit shared position with none blocking action
Definition: MPI_IOFile.h:406
tBoolean iWriteAt(const tMPIIOIndex &pos, const std::valarray< T > &values, tMPIStatus &status)
write the value at individual core by explicit file cursor position non blocking action
Definition: MPI_IOFile.h:246
tBoolean orderedRead(const tMPICount &n, T *values, tMPIStatus &status)
read the value at implicit shared position and all the core execute the action with respect of there ...
Definition: MPI_IOFile.h:490
tBoolean iSharedRead(const tMPICount &n, T *values, tMPIRequest &request)
read the value at implicit shared position and all the core execute the action randomly with blocking...
Definition: MPI_IOFile.h:475
tBoolean open(const MPI_Environment &env, const tMPIIOMode &mode)
open the file for the environment
Definition: MPI_IOFile.h:187
tBoolean sharedRead(const tMPICount &n, T *values, tMPIStatus &status)
read the value at implicit shared position and all the core execute the action randomly with blocking...
Definition: MPI_IOFile.h:461
virtual tMemSize getMemorySize() const override
return the memory size of the class
Definition: MPI_IOFile.h:124
tString printError() const
print Error
Definition: MPI_IOFile.h:619
const tMPIError & getError() const
get the error of the last instruction
Definition: MPI_IOFile.h:162
tBoolean getEnvironmentPosition(tMPIIOIndex &pos)
get th eposition of the pointer of the file shared by all core of the environment
Definition: MPI_IOFile.h:564
tBoolean orderedRead(std::valarray< T > &values, tMPIStatus &status)
read the value at implicit shared position and all the core execute the action with respect of there ...
Definition: MPI_IOFile.h:503
tBoolean iAllRead(const tMPICount &n, T *values, tMPIRequest &request)
read the value at implicit shared position with none blocking action
Definition: MPI_IOFile.h:445
tBoolean getSize(tMPIIOIndex &s) const
get the size of the file
Definition: MPI_IOFile.h:602
tBoolean iRead(const tMPICount &n, T *values, tMPIRequest &request)
read the value at individual core by implicit file cursor position with blocking action
Definition: MPI_IOFile.h:375
tBoolean allReadAt(const tMPIIOIndex &pos, std::valarray< T > &values, tMPIStatus &status)
read the value at explicit shared position with blocking action
Definition: MPI_IOFile.h:393
static const tMPIIOMode READ_ONLY
read only mode
Definition: MPI_IOFile.h:78
tBoolean writeAll(const std::valarray< T > &values, tMPIStatus &status)
write the value at shared core by explicit file cursor position with blocking action
Definition: MPI_IOFile.h:261
static const tMPIErrorMode RETURN_ERROR
return error tag
Definition: MPI_IOFile.h:93
tBoolean writeAt(const tMPIIOIndex &pos, const std::valarray< T > &values, tMPIStatus &status)
write the value at individual core by explicit file cursor position with blocking action
Definition: MPI_IOFile.h:233
static const tMPIIOMode CREATE
file creation tag
Definition: MPI_IOFile.h:87
void setFileName(const tString &fn)
set the file name
Definition: MPI_IOFile.h:150
tBoolean allRead(std::valarray< T > &values, tMPIStatus &status)
read the value at implicit shared position with blocking action
Definition: MPI_IOFile.h:433
virtual ~MPI_IOFile(void)
destroy
Definition: MPI_IOFile.h:117
tMPIError setView(const MPI_View &view)
set the view
Definition: MPI_IOFile.h:169
tBoolean readAt(const tMPIIOIndex &pos, std::valarray< T > &values, tMPIStatus &status)
read the value at individual core by epplicit file cursor position with blocking action
Definition: MPI_IOFile.h:334
tBoolean setEnvironmentPosition(const tMPIIOIndex &pos)
get th eposition of the pointer of the file shared by all core of the environment
Definition: MPI_IOFile.h:572
static const tMPIErrorMode FATAL_ERROR
fatal error tag
Definition: MPI_IOFile.h:90
tBoolean iOrderedRead(const tMPICount &n, T *values, tMPIRequest &request)
read the value at implicit shared position and all the core execute the action with respect of there ...
Definition: MPI_IOFile.h:516
tBoolean writeOrdered(const std::valarray< T > &values)
write the value at shared core by explicit file cursor position with blocking action
Definition: MPI_IOFile.h:287
tBoolean iReadAt(const tMPIIOIndex &pos, std::valarray< T > &values, tMPIRequest &request)
read the value at individual core by explicit file cursor position with none blocking action
Definition: MPI_IOFile.h:348
tBoolean writeOrdered(const tString &str)
write the value at shared core by explicit file cursor position with blocking action
Definition: MPI_IOFile.h:271
static const tMPIIOMode WRITE_ONLY
write only mode
Definition: MPI_IOFile.h:81
This class is a base class of E-MicromM core package.
Definition: MPI_Object.h:32
This class describes a view as follow:
Definition: MPI_View.h:20
const tMPIType & getType() const
get the type of the element of the view
Definition: MPI_View.h:75
const tMPIView & getMPIView() const
get the mpi view of the view
Definition: MPI_View.h:80