escript  Revision_
SubWorld.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2014-2018 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014-2017 by Centre for Geoscience Computing (GeoComp)
14 * Development from 2019 by School of Earth and Environmental Sciences
15 **
16 *****************************************************************************/
17 
18 #ifndef escript_SubWorld_H
19 #define escript_SubWorld_H
20 
21 #include "AbstractDomain.h"
22 #include "AbstractReducer.h"
23 #include "EsysMPI.h"
24 
25 namespace escript
26 {
27 
48 class SubWorld : public REFCOUNT_BASE_CLASS(SubWorld)
49 {
50 public:
51  SubWorld(JMPI& globalcom, JMPI& comm, JMPI& corr,
52  unsigned int subworldcount, unsigned int local_id,
53  bool manualimport);
54 
55  ~SubWorld();
56 
57  void setDomain(Domain_ptr d);
59  JMPI& getMPI();
61  void addJob(boost::python::object j); // add a Job to the current batch
62  char runJobs(std::string& errmsg); // run all jobs in the current batch
63  void clearJobs(); // remove all jobs in the current batch
64 
65  void addVariable(std::string&, Reducer_ptr& red);
66  void removeVariable(std::string& name);
67  void clearVariable(std::string& name);
68  std::list<std::pair<std::string, bool> > getVarList();
69  std::list<std::pair<std::string, std::string> > getVarInfo();
70  size_t getNumVars();
71 
72  bool localTransport(std::string& errmsg); // gather exported values from jobs
73  bool checkRemoteCompatibility(std::string& errmsg); // check to ensure values
74  // in all worlds are compatible
75 
76  bool deliverImports(std::string& errmsg); // load imports into Job objects
77  bool amLeader(); // true if this proc is the leader for its world
78 
79  DataTypes::real_t getScalarVariable(const std::string& name);
80  boost::python::object getLocalObjectVariable(const std::string& name);
81 
82  void debug(); // print out current state information
83 
84 
85 
86  bool synchVariableInfo(std::string& err);
87  bool synchVariableValues(std::string& err);
88  void resetInterest();
89 
90  void copyVariable(const std::string& src, const std::string& dest);
91 
92  void newRunJobs();
93 
94 private:
95  JMPI everyone; // communicator linking all procs in all subworlds
96  JMPI swmpi; // communicator linking all procs in this subworld
97  JMPI corrmpi; // communicator linking corresponding procs in all subworlds
98  // eg: If this proc is the first in its domain, then corrmpi
99  // links to the other "first in its domain" processes.
100  // (So one in each SubWorld).
102  std::vector<boost::python::object> jobvec; // jobs in the current batch
103 
104 
105  unsigned int swcount; // number of subwords
106  unsigned int localid; // position of this subworld in that sequence
107 
108  typedef std::map<std::string, Reducer_ptr> str2reduce;
109  typedef std::map<std::string, unsigned char> str2char;
110  str2reduce reducemap; // map: name ->reducer for that variable
111  str2char varstate; // using the state values from AbstractReducer.h
112 
113  bool manualimports;
114 
115 #ifdef ESYS_MPI
116  std::vector<unsigned char> globalvarinfo; // info about which worlds want which vars
117  // [vars on process0][vars on process 1][vars on ...]
118  typedef std::map<unsigned char, int> countmap;
119  typedef std::map<std::string, countmap> str2countmap;
120  str2countmap globalvarcounts;
121  bool globalinfoinvalid;
122 
123 
124  bool makeComm(MPI_Comm& sourcecom, JMPI& sub,std::vector<int>& members);
125 
126 
127  // a group with NEW nodes at the front and INT and OLDINT at the back
128  // NONE worlds get an empty communicator
129  bool makeGroupComm1(MPI_Comm& srccom, int vnum, char mystate, JMPI& com);
130 
131  // reduce on the first group and copy from cop[0] to others in cop
132  bool makeGroupReduceGroups(MPI_Comm& srccom, int vnum, char mystate, JMPI& red, JMPI& cop, bool& incopy);
133 
134 
135  // A group with a single OLD or OLDINT at the front and all the INT worlds
136  // following it
137  bool makeGroupComm2(MPI_Comm& srccom, int vnum, char mystate, JMPI& com, bool& ingroup);
138 
139 #endif
140 
141  // change the various views of a variable's state
142  void setMyVarState(const std::string& vname, char state);
143  void setVarState(const std::string& vname, char state, int swid);
144  void setAllVarsState(const std::string& name, char state);
145 };
146 
147 typedef boost::shared_ptr<SubWorld> SubWorld_ptr;
148 
149 } // namespace escript
150 
151 #endif
152 
escript::SubWorld::localid
unsigned int localid
Definition: SubWorld.h:131
escript::SubWorld::debug
void debug()
Definition: SubWorld.cpp:259
escript::DataTypes::real_t
double real_t
type of all real-valued scalars in escript
Definition: DataTypes.h:76
escript::SubWorld::manualimports
bool manualimports
Definition: SubWorld.h:138
NonReducedVariable.h
AbstractReducer.h
escript::SubWorld::swcount
unsigned int swcount
Definition: SubWorld.h:130
escript::SubWorld::SubWorld
SubWorld(JMPI &globalcom, JMPI &comm, JMPI &corr, unsigned int subworldcount, unsigned int local_id, bool manualimport)
Definition: SubWorld.cpp:35
escript::SubWorld::localTransport
bool localTransport(std::string &errmsg)
Definition: SubWorld.cpp:213
escript::SubWorld::getMPI
JMPI & getMPI()
Definition: SubWorld.cpp:51
escript::SubWorld::synchVariableValues
bool synchVariableValues(std::string &err)
Definition: SubWorld.cpp:607
escript::reducerstatus
Definition: AbstractReducer.h:41
escript::SubWorld::removeVariable
void removeVariable(std::string &name)
Definition: SubWorld.cpp:1016
escript::SubWorld::setDomain
void setDomain(Domain_ptr d)
Definition: SubWorld.cpp:61
escript::SubWorld::str2char
std::map< std::string, unsigned char > str2char
Definition: SubWorld.h:134
escript::SubWorld::getCorrMPI
JMPI & getCorrMPI()
Definition: SubWorld.cpp:56
escript::SubWorld::runJobs
char runJobs(std::string &errmsg)
Definition: SubWorld.cpp:954
escript::SubWorld::newRunJobs
void newRunJobs()
Definition: SubWorld.cpp:1054
escript::reducerstatus::NONE
const unsigned char NONE
Definition: AbstractReducer.h:58
ERROR
#define ERROR
Definition: finley/src/Mesh_readGmsh.cpp:33
escript::SubWorld::getLocalObjectVariable
boost::python::object getLocalObjectVariable(const std::string &name)
Definition: SubWorld.cpp:380
escript::SubWorld::swmpi
JMPI swmpi
Definition: SubWorld.h:121
escript::SubWorld::str2reduce
std::map< std::string, Reducer_ptr > str2reduce
Definition: SubWorld.h:133
escript::Domain_ptr
boost::shared_ptr< AbstractDomain > Domain_ptr
Definition: AbstractDomain.h:53
escript::SubWorld::setVarState
void setVarState(const std::string &vname, char state, int swid)
Definition: SubWorld.cpp:123
SplitWorldException.h
escript::SubWorld::getNumVars
size_t getNumVars()
Definition: SubWorld.cpp:984
escript::makeInfo
JMPI makeInfo(MPI_Comm comm, bool owncom)
Definition: EsysMPI.cpp:41
MPIDataReducer.h
REFCOUNT_BASE_CLASS
#define REFCOUNT_BASE_CLASS(x)
Definition: Pointers.h:30
escript::reducerstatus::INTERESTED
const unsigned char INTERESTED
Definition: AbstractReducer.h:59
MPI_MAX
#define MPI_MAX
Definition: EsysMPI.h:53
escript::SubWorld::clearVariable
void clearVariable(std::string &name)
Definition: SubWorld.cpp:1027
escript::SubWorld::getVarInfo
std::list< std::pair< std::string, std::string > > getVarInfo()
Definition: SubWorld.cpp:1072
escript::Reducer_ptr
boost::shared_ptr< AbstractReducer > Reducer_ptr
Definition: AbstractReducer.h:130
escript::SubWorld::domain
escript::Domain_ptr domain
Definition: SubWorld.h:126
escript::reducerstatus::OLD
const unsigned char OLD
Definition: AbstractReducer.h:60
escript::JMPI
boost::shared_ptr< JMPI_ > JMPI
Definition: EsysMPI.h:71
escript::SubWorld::addJob
void addJob(boost::python::object j)
Definition: SubWorld.cpp:71
escript::SubWorld::reducemap
str2reduce reducemap
Definition: SubWorld.h:135
escript::SubWorld::resetInterest
void resetInterest()
Definition: SubWorld.cpp:1039
escript::SplitWorldException
Definition: SplitWorldException.h:40
AbstractDomain.h
escript::SubWorld::deliverImports
bool deliverImports(std::string &errmsg)
Definition: SubWorld.cpp:159
escript::SubWorld::synchVariableInfo
bool synchVariableInfo(std::string &err)
Definition: SubWorld.cpp:805
escript::SubWorld::~SubWorld
~SubWorld()
Definition: SubWorld.cpp:47
escript::reducerstatus::OLDINTERESTED
const unsigned char OLDINTERESTED
Definition: AbstractReducer.h:61
escript::SubWorld::clearJobs
void clearJobs()
Definition: SubWorld.cpp:76
escript::SubWorld::addVariable
void addVariable(std::string &, Reducer_ptr &red)
Definition: SubWorld.cpp:990
SubWorld.h
escript::SubWorld::amLeader
bool amLeader()
Definition: SubWorld.cpp:798
escript::SubWorld::jobvec
std::vector< boost::python::object > jobvec
Definition: SubWorld.h:127
escript::SubWorld::copyVariable
void copyVariable(const std::string &src, const std::string &dest)
Definition: SubWorld.cpp:1088
escript::SubWorld_ptr
boost::shared_ptr< SubWorld > SubWorld_ptr
Definition: SubWorld.h:159
escript::SubWorld::checkRemoteCompatibility
bool checkRemoteCompatibility(std::string &errmsg)
Definition: SubWorld.cpp:417
escript::SubWorld::getDomain
Domain_ptr getDomain()
Definition: SubWorld.cpp:66
escript
Definition: AbstractContinuousDomain.cpp:23
escript::SubWorld::getVarList
std::list< std::pair< std::string, bool > > getVarList()
Definition: SubWorld.cpp:1062
MPIScalarReducer.h
escript::SubWorld::varstate
str2char varstate
Definition: SubWorld.h:136
escript::SubWorld::setAllVarsState
void setAllVarsState(const std::string &name, char state)
Definition: SubWorld.cpp:86
escript::reducerstatus::NEW
const unsigned char NEW
Definition: AbstractReducer.h:62
MPI_Comm
int MPI_Comm
Definition: EsysMPI.h:41
escript::SubWorld::getScalarVariable
DataTypes::real_t getScalarVariable(const std::string &name)
Definition: SubWorld.cpp:332
escript::AbstractDomain
Base class for all escript domains.
Definition: AbstractDomain.h:62
escript::getStringFromPyException
void getStringFromPyException(boost::python::error_already_set e, std::string &errormsg)
Definition: pyerr.cpp:40
escript::SubWorld::everyone
JMPI everyone
Definition: SubWorld.h:120
escript::SubWorld::corrmpi
JMPI corrmpi
Definition: SubWorld.h:122
pyerr.h
EsysMPI.h
escript::SubWorld::setMyVarState
void setMyVarState(const std::string &vname, char state)
Definition: SubWorld.cpp:81