escript  Revision_Unversioneddirectory
SubWorld.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2014-2016 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 "esysUtils/Esys_MPI.h"
21 #include "AbstractDomain.h"
22 #include "AbstractReducer.h"
23 
24 namespace escript
25 {
26 
47 class SubWorld : public boost::enable_shared_from_this<SubWorld>
48 {
49 public:
50  SubWorld(esysUtils::JMPI& globalcom, esysUtils::JMPI& comm, esysUtils::JMPI& corr, unsigned int subworldcount, unsigned int local_id, bool manualimport);
51  ~SubWorld();
52  void setDomain(Domain_ptr d);
56  void addJob(boost::python::object j); // add a Job to the current batch
57  char runJobs(std::string& errmsg); // run all jobs in the current batch
58  void clearJobs(); // remove all jobs in the current batch
59 
60  void addVariable(std::string&, Reducer_ptr& red);
61  void removeVariable(std::string& name);
62  void clearVariable(std::string& name);
63  std::list<std::pair<std::string, bool> > getVarList();
64  std::list<std::pair<std::string, std::string> > getVarInfo();
65  size_t getNumVars();
66 
67  bool localTransport(std::string& errmsg); // gather exported values from jobs
68  bool checkRemoteCompatibility(std::string& errmsg); // check to ensure values
69  // in all worlds are compatible
70 
71  bool deliverImports(std::string& errmsg); // load imports into Job objects
72  bool amLeader(); // true if this proc is the leader for its world
73 
74  double getScalarVariable(const std::string& name);
75  boost::python::object getLocalObjectVariable(const std::string& name);
76 
77  void debug(); // print out current state information
78 
79 
80 
81  bool synchVariableInfo(std::string& err);
82  bool synchVariableValues(std::string& err);
83  void resetInterest();
84 
85  void copyVariable(const std::string& src, const std::string& dest);
86 
87  void newRunJobs();
88 
89 private:
90  esysUtils::JMPI everyone; // communicator linking all procs in all subworlds
91  esysUtils::JMPI swmpi; // communicator linking all procs in this subworld
92  esysUtils::JMPI corrmpi; // communicator linking corresponding procs in all subworlds
93  // eg: If this proc is the first in its domain, then corrmpi
94  // links to the other "first in its domain" processes.
95  // (So one in each SubWorld).
97  std::vector<boost::python::object> jobvec; // jobs in the current batch
98 
99 
100  unsigned int swcount; // number of subwords
101  unsigned int localid; // position of this subworld in that sequence
102 
103 typedef std::map<std::string, Reducer_ptr> str2reduce;
104 typedef std::map<std::string, unsigned char> str2char;
105  str2reduce reducemap; // map: name ->reducer for that variable
106  str2char varstate; // using the state values from AbstractReducer.h
107 
109 
110 #ifdef ESYS_MPI
111  std::vector<unsigned char> globalvarinfo; // info about which worlds want which vars
112  // [vars on process0][vars on process 1][vars on ...]
113 typedef std::map<unsigned char, int> countmap;
114 typedef std::map<std::string, countmap> str2countmap;
115  str2countmap globalvarcounts;
116  bool globalinfoinvalid;
117 
118 
119  bool makeComm(MPI_Comm& sourcecom, esysUtils::JMPI& sub,std::vector<int>& members);
120 
121 
122  // a group with NEW nodes at the front and INT and OLDINT at the back
123  // NONE worlds get an empty communicator
124  bool makeGroupComm1(MPI_Comm& srccom, int vnum, char mystate, esysUtils::JMPI& com);
125 
126  // reduce on the first group and copy from cop[0] to others in cop
127  bool makeGroupReduceGroups(MPI_Comm& srccom, int vnum, char mystate, esysUtils::JMPI& red, esysUtils::JMPI& cop, bool& incopy);
128 
129 
130  // A group with a single OLD or OLDINT at the front and all the INT worlds
131  // following it
132  bool makeGroupComm2(MPI_Comm& srccom, int vnum, char mystate, esysUtils::JMPI& com, bool& ingroup);
133 
134 #endif
135 
136  // change the various views of a variable's state
137  void setMyVarState(const std::string& vname, char state);
138  void setVarState(const std::string& vname, char state, int swid);
139  void setAllVarsState(const std::string& name, char state);
140 };
141 
142 typedef boost::shared_ptr<SubWorld> SubWorld_ptr;
143 
144 
145 
146 }
147 #endif
Domain_ptr getDomain()
Definition: SubWorld.cpp:70
bool checkRemoteCompatibility(std::string &errmsg)
Definition: SubWorld.cpp:426
void addVariable(std::string &, Reducer_ptr &red)
Definition: SubWorld.cpp:1002
esysUtils::JMPI & getCorrMPI()
Definition: SubWorld.cpp:60
void resetInterest()
Definition: SubWorld.cpp:1051
boost::shared_ptr< AbstractDomain > Domain_ptr
Definition: AbstractDomain.h:36
Definition: AbstractContinuousDomain.cpp:24
esysUtils::JMPI corrmpi
Definition: SubWorld.h:92
void newRunJobs()
Definition: SubWorld.cpp:1066
SubWorld(esysUtils::JMPI &globalcom, esysUtils::JMPI &comm, esysUtils::JMPI &corr, unsigned int subworldcount, unsigned int local_id, bool manualimport)
Definition: SubWorld.cpp:41
bool synchVariableInfo(std::string &err)
Definition: SubWorld.cpp:816
esysUtils::JMPI swmpi
Definition: SubWorld.h:91
void clearJobs()
Definition: SubWorld.cpp:80
void setMyVarState(const std::string &vname, char state)
Definition: SubWorld.cpp:85
escript::Domain_ptr domain
Definition: SubWorld.h:96
bool localTransport(std::string &errmsg)
Definition: SubWorld.cpp:219
void setAllVarsState(const std::string &name, char state)
Definition: SubWorld.cpp:90
void copyVariable(const std::string &src, const std::string &dest)
Definition: SubWorld.cpp:1100
boost::shared_ptr< AbstractReducer > Reducer_ptr
Definition: AbstractReducer.h:117
int MPI_Comm
Definition: Esys_MPI.h:38
bool deliverImports(std::string &errmsg)
Definition: SubWorld.cpp:165
unsigned int localid
Definition: SubWorld.h:101
bool manualimports
Definition: SubWorld.h:108
boost::shared_ptr< SubWorld > SubWorld_ptr
Definition: SubWorld.h:142
std::list< std::pair< std::string, bool > > getVarList()
Definition: SubWorld.cpp:1074
std::vector< boost::python::object > jobvec
Definition: SubWorld.h:97
str2char varstate
Definition: SubWorld.h:106
void setVarState(const std::string &vname, char state, int swid)
Definition: SubWorld.cpp:129
bool synchVariableValues(std::string &err)
Definition: SubWorld.cpp:618
double getScalarVariable(const std::string &name)
Definition: SubWorld.cpp:341
void setDomain(Domain_ptr d)
Definition: SubWorld.cpp:65
void removeVariable(std::string &name)
Definition: SubWorld.cpp:1028
std::list< std::pair< std::string, std::string > > getVarInfo()
Definition: SubWorld.cpp:1084
std::map< std::string, unsigned char > str2char
Definition: SubWorld.h:104
esysUtils::JMPI everyone
Definition: SubWorld.h:90
str2reduce reducemap
Definition: SubWorld.h:105
std::map< std::string, Reducer_ptr > str2reduce
Definition: SubWorld.h:103
boost::python::object getLocalObjectVariable(const std::string &name)
Definition: SubWorld.cpp:389
Definition: SubWorld.h:47
~SubWorld()
Definition: SubWorld.cpp:51
void debug()
Definition: SubWorld.cpp:265
void clearVariable(std::string &name)
Definition: SubWorld.cpp:1039
char runJobs(std::string &errmsg)
Definition: SubWorld.cpp:966
unsigned int swcount
Definition: SubWorld.h:100
esysUtils::JMPI & getMPI()
Definition: SubWorld.cpp:55
size_t getNumVars()
Definition: SubWorld.cpp:996
bool amLeader()
Definition: SubWorld.cpp:809
boost::shared_ptr< JMPI_ > JMPI
Definition: Esys_MPI.h:79
void addJob(boost::python::object j)
Definition: SubWorld.cpp:75