www.cemf.ir
localProcessors.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 #ifndef __pFlowProcessors_hpp__
21 #define __pFlowProcessors_hpp__
22 
23 
24 #include "processors.hpp"
25 #include "types.hpp"
26 
27 #ifdef pFlow_Build_MPI
28  #include "mpi.h"
29 #endif
30 
31 
32 namespace pFlow
33 {
34 
36 :
37  public processors
38 {
39 private:
40 
41 #ifdef pFlow_Build_MPI
42  MPI_Comm parrentCommunicator_;
43 
44  MPI_Comm localCommunicator_;
45 #endif
46 
47  int localSize_ = 1 ;
48 
49  int localRank_ = 0;
50 
51  bool isPartOfLocal_ = true;
52 
54 
55 public:
56 
60  localProcessors(const word& name);
61 
62 
68  const word& name,
69  const std::vector<int>& ranks);
70 
71  #ifdef pFlow_Build_MPI
73  MPI_Comm parrentComm,
74  const word& name,
75  const std::vector<int>& ranks);
76  #endif
77 
78  // - Access
79 
81  inline
82  const auto& name()const
83  {
84  return name_;
85  }
86 
87  inline
88  auto localRank()const
89  {
90  return localRank_;
91  }
92 
93  inline
94  auto localSize()const
95  {
96  return localSize_;
97  }
98 
99  // - Methods
100 
101  inline
102  bool localMaster()const
103  {
104  return localRank_ == localMasterNo();
105  }
106 
107  inline
108  int localMasterNo()const
109  {
110  return 0;
111  }
112 
113  inline
114  bool localParallel()const
115  {
116  return localSize_>1;
117  }
118 
119  inline
120  const char* localRunTypeName()
121  {
122  if(localParallel())
123  return "MPI";
124  else
125  return "regular";
126  }
127 
128  inline
129  bool isThisActive()const
130  {
131  return isPartOfLocal_;
132  }
133 
134  #ifdef pFlow_Build_MPI
135  inline
136  auto parrentCommunicator()const
137  {
138  return parrentCommunicator_;
139  }
140 
141  inline
142  auto localCommunicator()const
143  {
144  return localCommunicator_;
145  }
146  #endif
147 
148  static
149  bool builtForMPI()
150  {
151  #ifdef pFlow_Build_MPI
152  return true;
153  #else
154  return false;
155  #endif
156  }
157 };
158 
159 }
160 
161 #endif
pFlow::localProcessors::builtForMPI
static bool builtForMPI()
Definition: localProcessors.hpp:149
pFlow::localProcessors::name
const auto & name() const
return name of the local communicator
Definition: localProcessors.hpp:82
pFlow::localProcessors::localMasterNo
int localMasterNo() const
Definition: localProcessors.hpp:108
pFlow::localProcessors::localRank
auto localRank() const
Definition: localProcessors.hpp:88
processors.hpp
pFlow::localProcessors::localParallel
bool localParallel() const
Definition: localProcessors.hpp:114
pFlow::localProcessors::localRank_
int localRank_
Definition: localProcessors.hpp:49
types.hpp
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::processors
This class holds the information about the global execution world and number of processors in communi...
Definition: processors.hpp:51
pFlow::localProcessors::localMaster
bool localMaster() const
Definition: localProcessors.hpp:102
pFlow
Definition: demGeometry.hpp:27
pFlow::localProcessors::localRunTypeName
const char * localRunTypeName()
Definition: localProcessors.hpp:120
pFlow::localProcessors::localProcessors
localProcessors(const word &name)
Construct a local processor communication similar to global with specified name.
Definition: localProcessors.cpp:22
pFlow::localProcessors::localSize
auto localSize() const
Definition: localProcessors.hpp:94
pFlow::localProcessors::name_
word name_
Definition: localProcessors.hpp:53
pFlow::localProcessors
Definition: localProcessors.hpp:35
pFlow::localProcessors::isThisActive
bool isThisActive() const
Definition: localProcessors.hpp:129
pFlow::localProcessors::localSize_
int localSize_
Definition: localProcessors.hpp:47
pFlow::localProcessors::isPartOfLocal_
bool isPartOfLocal_
Definition: localProcessors.hpp:51