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 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16 
17 #ifndef escript_SubWorld_H
18 #define escript_SubWorld_H
19 
20 #include "AbstractDomain.h"
21 #include "AbstractReducer.h"
22 #include "EsysMPI.h"
23 
24 namespace escript
25 {
26 
47 class SubWorld : public REFCOUNT_BASE_CLASS(SubWorld)
48 {
49 public:
50  SubWorld(JMPI& globalcom, JMPI& comm, JMPI& corr,
51  unsigned int subworldcount, unsigned int local_id,
52  bool manualimport);
53 
54  ~SubWorld();
55 
56  void setDomain(Domain_ptr d);
59  JMPI& getCorrMPI();
60  void addJob(boost::python::object j); // add a Job to the current batch
61  char runJobs(std::string& errmsg); // run all jobs in the current batch
62  void clearJobs(); // remove all jobs in the current batch
63 
64  void addVariable(std::string&, Reducer_ptr& red);
65  void removeVariable(std::string& name);
66  void clearVariable(std::string& name);
67  std::list<std::pair<std::string, bool> > getVarList();
68  std::list<std::pair<std::string, std::string> > getVarInfo();
69  size_t getNumVars();
70 
71  bool localTransport(std::string& errmsg); // gather exported values from jobs
72  bool checkRemoteCompatibility(std::string& errmsg); // check to ensure values
73  // in all worlds are compatible
74 
75  bool deliverImports(std::string& errmsg); // load imports into Job objects
76  bool amLeader(); // true if this proc is the leader for its world
77 
78  DataTypes::real_t getScalarVariable(const std::string& name);
79  boost::python::object getLocalObjectVariable(const std::string& name);
80 
81  void debug(); // print out current state information
82 
83 
84 
85  bool synchVariableInfo(std::string& err);
86  bool synchVariableValues(std::string& err);
87  void resetInterest();
88 
89  void copyVariable(const std::string& src, const std::string& dest);
90 
91  void newRunJobs();
92 
93 private:
94  JMPI everyone; // communicator linking all procs in all subworlds
95  JMPI swmpi; // communicator linking all procs in this subworld
96  JMPI corrmpi; // communicator linking corresponding procs in all subworlds
97  // eg: If this proc is the first in its domain, then corrmpi
98  // links to the other "first in its domain" processes.
99  // (So one in each SubWorld).
101  std::vector<boost::python::object> jobvec; // jobs in the current batch
102 
103 
104  unsigned int swcount; // number of subwords
105  unsigned int localid; // position of this subworld in that sequence
106 
107  typedef std::map<std::string, Reducer_ptr> str2reduce;
108  typedef std::map<std::string, unsigned char> str2char;
109  str2reduce reducemap; // map: name ->reducer for that variable
110  str2char varstate; // using the state values from AbstractReducer.h
111 
112  bool manualimports;
113 
114 #ifdef ESYS_MPI
115  std::vector<unsigned char> globalvarinfo; // info about which worlds want which vars
116  // [vars on process0][vars on process 1][vars on ...]
117  typedef std::map<unsigned char, int> countmap;
118  typedef std::map<std::string, countmap> str2countmap;
119  str2countmap globalvarcounts;
120  bool globalinfoinvalid;
121 
122 
123  bool makeComm(MPI_Comm& sourcecom, JMPI& sub,std::vector<int>& members);
124 
125 
126  // a group with NEW nodes at the front and INT and OLDINT at the back
127  // NONE worlds get an empty communicator
128  bool makeGroupComm1(MPI_Comm& srccom, int vnum, char mystate, JMPI& com);
129 
130  // reduce on the first group and copy from cop[0] to others in cop
131  bool makeGroupReduceGroups(MPI_Comm& srccom, int vnum, char mystate, JMPI& red, JMPI& cop, bool& incopy);
132 
133 
134  // A group with a single OLD or OLDINT at the front and all the INT worlds
135  // following it
136  bool makeGroupComm2(MPI_Comm& srccom, int vnum, char mystate, JMPI& com, bool& ingroup);
137 
138 #endif
139 
140  // change the various views of a variable's state
141  void setMyVarState(const std::string& vname, char state);
142  void setVarState(const std::string& vname, char state, int swid);
143  void setAllVarsState(const std::string& name, char state);
144 };
145 
146 typedef boost::shared_ptr<SubWorld> SubWorld_ptr;
147 
148 } // namespace escript
149 
150 #endif
151 
escript::SubWorld::localid
unsigned int localid
Definition: SubWorld.h:128
escript::SubWorld::debug
void debug()
Definition: SubWorld.cpp:258
escript::DataTypes::real_t
double real_t
type of all real-valued scalars in escript
Definition: DataTypes.h:73
escript::SubWorld::manualimports
bool manualimports
Definition: SubWorld.h:135
NonReducedVariable.h
AbstractReducer.h
escript::SubWorld::swcount
unsigned int swcount
Definition: SubWorld.h:127
escript::SubWorld::SubWorld
SubWorld(JMPI &globalcom, JMPI &comm, JMPI &corr, unsigned int subworldcount, unsigned int local_id, bool manualimport)
Definition: SubWorld.cpp:34
escript::SubWorld::localTransport
bool localTransport(std::string &errmsg)
Definition: SubWorld.cpp:212
escript::SubWorld::getMPI
JMPI & getMPI()
Definition: SubWorld.cpp:50
escript::SubWorld::synchVariableValues
bool synchVariableValues(std::string &err)
Definition: SubWorld.cpp:606
escript::reducerstatus
Definition: AbstractReducer.h:39
escript::SubWorld::removeVariable
void removeVariable(std::string &name)
Definition: SubWorld.cpp:1015
escript::SubWorld::setDomain
void setDomain(Domain_ptr d)
Definition: SubWorld.cpp:60
escript::SubWorld::str2char
std::map< std::string, unsigned char > str2char
Definition: SubWorld.h:131
escript::SubWorld::getCorrMPI
JMPI & getCorrMPI()
Definition: SubWorld.cpp:55
escript::SubWorld::runJobs
char runJobs(std::string &errmsg)
Definition: SubWorld.cpp:953
escript::SubWorld::newRunJobs
void newRunJobs()
Definition: SubWorld.cpp:1053
escript::reducerstatus::NONE
const unsigned char NONE
Definition: AbstractReducer.h:55
ERROR
#define ERROR
Definition: finley/src/Mesh_readGmsh.cpp:32
escript::SubWorld::getLocalObjectVariable
boost::python::object getLocalObjectVariable(const std::string &name)
Definition: SubWorld.cpp:379
escript::SubWorld::swmpi
JMPI swmpi
Definition: SubWorld.h:118
escript::SubWorld::str2reduce
std::map< std::string, Reducer_ptr > str2reduce
Definition: SubWorld.h:130
escript::Domain_ptr
boost::shared_ptr< AbstractDomain > Domain_ptr
Definition: AbstractDomain.h:47
escript::SubWorld::setVarState
void setVarState(const std::string &vname, char state, int swid)
Definition: SubWorld.cpp:122
SplitWorldException.h
escript::SubWorld::getNumVars
size_t getNumVars()
Definition: SubWorld.cpp:983
escript::makeInfo
JMPI makeInfo(MPI_Comm comm, bool owncom)
Definition: EsysMPI.cpp:39
MPIDataReducer.h
REFCOUNT_BASE_CLASS
#define REFCOUNT_BASE_CLASS(x)
Definition: Pointers.h:29
escript::reducerstatus::INTERESTED
const unsigned char INTERESTED
Definition: AbstractReducer.h:56
MPI_MAX
#define MPI_MAX
Definition: EsysMPI.h:52
escript::SubWorld::clearVariable
void clearVariable(std::string &name)
Definition: SubWorld.cpp:1026
escript::SubWorld::getVarInfo
std::list< std::pair< std::string, std::string > > getVarInfo()
Definition: SubWorld.cpp:1071
escript::Reducer_ptr
boost::shared_ptr< AbstractReducer > Reducer_ptr
Definition: AbstractReducer.h:128
escript::SubWorld::domain
escript::Domain_ptr domain
Definition: SubWorld.h:123
escript::reducerstatus::OLD
const unsigned char OLD
Definition: AbstractReducer.h:57
escript::JMPI
boost::shared_ptr< JMPI_ > JMPI
Definition: EsysMPI.h:70
escript::SubWorld::addJob
void addJob(boost::python::object j)
Definition: SubWorld.cpp:70
escript::SubWorld::reducemap
str2reduce reducemap
Definition: SubWorld.h:132
escript::SubWorld::resetInterest
void resetInterest()
Definition: SubWorld.cpp:1038
escript::SplitWorldException
Definition: SplitWorldException.h:38
AbstractDomain.h
escript::SubWorld::deliverImports
bool deliverImports(std::string &errmsg)
Definition: SubWorld.cpp:158
escript::SubWorld::synchVariableInfo
bool synchVariableInfo(std::string &err)
Definition: SubWorld.cpp:804
escript::SubWorld::~SubWorld
~SubWorld()
Definition: SubWorld.cpp:46
escript::reducerstatus::OLDINTERESTED
const unsigned char OLDINTERESTED
Definition: AbstractReducer.h:58
escript::SubWorld::clearJobs
void clearJobs()
Definition: SubWorld.cpp:75
escript::SubWorld::addVariable
void addVariable(std::string &, Reducer_ptr &red)
Definition: SubWorld.cpp:989
SubWorld.h
escript::SubWorld::amLeader
bool amLeader()
Definition: SubWorld.cpp:797
escript::SubWorld::jobvec
std::vector< boost::python::object > jobvec
Definition: SubWorld.h:124
escript::SubWorld::copyVariable
void copyVariable(const std::string &src, const std::string &dest)
Definition: SubWorld.cpp:1087
escript::SubWorld_ptr
boost::shared_ptr< SubWorld > SubWorld_ptr
Definition: SubWorld.h:157
escript::SubWorld::checkRemoteCompatibility
bool checkRemoteCompatibility(std::string &errmsg)
Definition: SubWorld.cpp:416
escript::SubWorld::getDomain
Domain_ptr getDomain()
Definition: SubWorld.cpp:65
escript
Definition: AbstractContinuousDomain.cpp:22
escript::SubWorld::getVarList
std::list< std::pair< std::string, bool > > getVarList()
Definition: SubWorld.cpp:1061
MPIScalarReducer.h
escript::SubWorld::varstate
str2char varstate
Definition: SubWorld.h:133
escript::SubWorld::setAllVarsState
void setAllVarsState(const std::string &name, char state)
Definition: SubWorld.cpp:85
escript::reducerstatus::NEW
const unsigned char NEW
Definition: AbstractReducer.h:59
MPI_Comm
int MPI_Comm
Definition: EsysMPI.h:40
escript::SubWorld::getScalarVariable
DataTypes::real_t getScalarVariable(const std::string &name)
Definition: SubWorld.cpp:331
escript::AbstractDomain
Base class for all escript domains.
Definition: AbstractDomain.h:56
escript::getStringFromPyException
void getStringFromPyException(boost::python::error_already_set e, std::string &errormsg)
Definition: pyerr.cpp:38
escript::SubWorld::everyone
JMPI everyone
Definition: SubWorld.h:117
escript::SubWorld::corrmpi
JMPI corrmpi
Definition: SubWorld.h:119
pyerr.h
EsysMPI.h
escript::SubWorld::setMyVarState
void setMyVarState(const std::string &vname, char state)
Definition: SubWorld.cpp:80