www.cemf.ir
IOPattern.hpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 #ifndef __IOPattern_hpp__
22 #define __IOPattern_hpp__
23 
24 
25 
26 #include "types.hpp"
27 
28 namespace pFlow
29 {
30 
31 
32 class IOPattern
33 {
34 public:
35 
52  enum IOType : int
53  {
57  AllProcessorsDifferent = 8 // this is used for << and >> operators for
58  // standard input and output streams
59  };
60 
61 private:
62 
64 
65  int globalSize_ = 1;
66 
67  int globalRank_ = 0;
68 
69  bool isMaster_ = true;
70 
71  bool isParallel_ = false;
72 
73 public:
74 
76 
77  IOPattern(const IOPattern&)=default;
78 
79  IOPattern(IOPattern&&) = default;
80 
81  IOPattern& operator=(const IOPattern&)=default;
82 
83  IOPattern& operator=(IOPattern&&)=default;
84 
85  ~IOPattern() = default;
86 
87  inline
89  {
90  return ioType_ == MasterProcessorOnly;
91  }
92 
93  inline
95  {
96  return ioType_ == AllProcessorsSimilar;
97  }
98 
99  inline
101  {
103  }
104 
105  inline
107  {
109  }
110 
111  inline
112  bool isMaster()const
113  {
114  return isMaster_;
115  }
116 
117  inline
118  bool isParallel()const
119  {
120  return isParallel_;
121  }
122 
123  inline
124  bool thisCallRead()const
125  {
126  if(isMasterProcessorOnly() && !isMaster())return false;
127  return true;
128  }
129 
130  inline
131  bool thisCallWrite()const
132  {
133  if(isMasterProcessorOnly()&& !isMaster())return false;
134  return true;
135  }
136 
137  inline
138  bool thisProcReadData()const
139  {
140  if(isMasterProcessorOnly() && !isMaster())return false;
141  if(isMasterProcessorDistribute()&& !isMaster())return false;
142  return true;
143  }
144 
145  inline
146  bool thisProcWriteData()const
147  {
148  if(isAllProcessorsDifferent()) return true;
149  return isMaster();
150  }
151 
152  inline
153  bool thisProcReadHeader()const
154  {
155  return thisProcReadData();
156  }
157 
158  inline
160  {
161  return isMaster();
162  }
163 
164  inline
165  auto globalSize()const
166  {
167  return globalSize_;
168  }
169 
170  inline
171  auto globalRank()const
172  {
173  return globalRank_;
174  }
175 
176  static
177  word exeMode();
178 
179 
180 };
181 
182 }
183 
184 #endif //__IOPattern_hpp__
pFlow::IOPattern::thisProcReadHeader
bool thisProcReadHeader() const
Definition: IOPattern.hpp:153
pFlow::IOPattern::isAllProcessorSimilar
bool isAllProcessorSimilar() const
Definition: IOPattern.hpp:94
pFlow::IOPattern::IOPattern
IOPattern(IOPattern::IOType iotype)
Definition: IOPattern.cpp:23
pFlow::IOPattern::thisCallRead
bool thisCallRead() const
Definition: IOPattern.hpp:124
pFlow::IOPattern::globalSize_
int globalSize_
Definition: IOPattern.hpp:65
types.hpp
pFlow::IOPattern::globalSize
auto globalSize() const
Definition: IOPattern.hpp:165
pFlow::IOPattern::~IOPattern
~IOPattern()=default
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::IOPattern::ioType_
IOType ioType_
Definition: IOPattern.hpp:63
pFlow::IOPattern::globalRank
auto globalRank() const
Definition: IOPattern.hpp:171
pFlow::IOPattern::isMasterProcessorOnly
bool isMasterProcessorOnly() const
Definition: IOPattern.hpp:88
pFlow::IOPattern::isParallel
bool isParallel() const
Definition: IOPattern.hpp:118
pFlow::IOPattern::IOType
IOType
Type of input/output.
Definition: IOPattern.hpp:52
pFlow
Definition: demGeometry.hpp:27
pFlow::IOPattern::globalRank_
int globalRank_
Definition: IOPattern.hpp:67
pFlow::IOPattern::thisProcWriteHeader
bool thisProcWriteHeader() const
Definition: IOPattern.hpp:159
pFlow::IOPattern::isAllProcessorsDifferent
bool isAllProcessorsDifferent() const
Definition: IOPattern.hpp:106
pFlow::IOPattern::isMasterProcessorDistribute
bool isMasterProcessorDistribute() const
Definition: IOPattern.hpp:100
pFlow::IOPattern::AllProcessorsDifferent
@ AllProcessorsDifferent
Definition: IOPattern.hpp:57
pFlow::IOPattern::thisCallWrite
bool thisCallWrite() const
Definition: IOPattern.hpp:131
pFlow::IOPattern
Definition: IOPattern.hpp:32
pFlow::IOPattern::isMaster_
bool isMaster_
Definition: IOPattern.hpp:69
pFlow::IOPattern::exeMode
static word exeMode()
Definition: IOPattern.cpp:32
pFlow::IOPattern::thisProcReadData
bool thisProcReadData() const
Definition: IOPattern.hpp:138
pFlow::IOPattern::thisProcWriteData
bool thisProcWriteData() const
Definition: IOPattern.hpp:146
pFlow::IOPattern::isParallel_
bool isParallel_
Definition: IOPattern.hpp:71
pFlow::IOPattern::operator=
IOPattern & operator=(const IOPattern &)=default
pFlow::IOPattern::AllProcessorsSimilar
@ AllProcessorsSimilar
Definition: IOPattern.hpp:55
pFlow::IOPattern::isMaster
bool isMaster() const
Definition: IOPattern.hpp:112
pFlow::IOPattern::MasterProcessorDistribute
@ MasterProcessorDistribute
Definition: IOPattern.hpp:56
pFlow::IOPattern::MasterProcessorOnly
@ MasterProcessorOnly
Definition: IOPattern.hpp:54