escript  Revision_
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 "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);
58  JMPI& getMPI();
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 
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 
Domain_ptr getDomain()
Definition: SubWorld.cpp:66
bool checkRemoteCompatibility(std::string &errmsg)
Definition: SubWorld.cpp:417
void addVariable(std::string &, Reducer_ptr &red)
Definition: SubWorld.cpp:990
JMPI & getCorrMPI()
Definition: SubWorld.cpp:56
void resetInterest()
Definition: SubWorld.cpp:1039
boost::shared_ptr< AbstractDomain > Domain_ptr
Definition: AbstractDomain.h:36
Definition: AbstractContinuousDomain.cpp:22
void newRunJobs()
Definition: SubWorld.cpp:1054
bool synchVariableInfo(std::string &err)
Definition: SubWorld.cpp:805
boost::shared_ptr< JMPI_ > JMPI
Definition: EsysMPI.h:71
#define REFCOUNT_BASE_CLASS(x)
Definition: Pointers.h:30
void clearJobs()
Definition: SubWorld.cpp:76
void setMyVarState(const std::string &vname, char state)
Definition: SubWorld.cpp:81
escript::Domain_ptr domain
Definition: SubWorld.h:100
SubWorld(JMPI &globalcom, JMPI &comm, JMPI &corr, unsigned int subworldcount, unsigned int local_id, bool manualimport)
Definition: SubWorld.cpp:35
bool localTransport(std::string &errmsg)
Definition: SubWorld.cpp:213
void setAllVarsState(const std::string &name, char state)
Definition: SubWorld.cpp:86
void copyVariable(const std::string &src, const std::string &dest)
Definition: SubWorld.cpp:1088
boost::shared_ptr< AbstractReducer > Reducer_ptr
Definition: AbstractReducer.h:117
JMPI everyone
Definition: SubWorld.h:94
bool deliverImports(std::string &errmsg)
Definition: SubWorld.cpp:159
unsigned int localid
Definition: SubWorld.h:105
bool manualimports
Definition: SubWorld.h:112
boost::shared_ptr< SubWorld > SubWorld_ptr
Definition: SubWorld.h:146
JMPI swmpi
Definition: SubWorld.h:95
std::list< std::pair< std::string, bool > > getVarList()
Definition: SubWorld.cpp:1062
std::vector< boost::python::object > jobvec
Definition: SubWorld.h:101
str2char varstate
Definition: SubWorld.h:110
void setVarState(const std::string &vname, char state, int swid)
Definition: SubWorld.cpp:123
bool synchVariableValues(std::string &err)
Definition: SubWorld.cpp:607
void setDomain(Domain_ptr d)
Definition: SubWorld.cpp:61
void removeVariable(std::string &name)
Definition: SubWorld.cpp:1016
std::list< std::pair< std::string, std::string > > getVarInfo()
Definition: SubWorld.cpp:1072
std::map< std::string, unsigned char > str2char
Definition: SubWorld.h:108
int MPI_Comm
Definition: EsysMPI.h:41
str2reduce reducemap
Definition: SubWorld.h:109
std::map< std::string, Reducer_ptr > str2reduce
Definition: SubWorld.h:107
Definition: SubWorld.h:47
~SubWorld()
Definition: SubWorld.cpp:47
void debug()
Definition: SubWorld.cpp:259
void clearVariable(std::string &name)
Definition: SubWorld.cpp:1027
char runJobs(std::string &errmsg)
Definition: SubWorld.cpp:954
unsigned int swcount
Definition: SubWorld.h:104
JMPI & getMPI()
Definition: SubWorld.cpp:51
size_t getNumVars()
Definition: SubWorld.cpp:984
JMPI corrmpi
Definition: SubWorld.h:96
boost::python::object getLocalObjectVariable(const std::string &name)
Definition: SubWorld.cpp:380
bool amLeader()
Definition: SubWorld.cpp:798
DataTypes::real_t getScalarVariable(const std::string &name)
Definition: SubWorld.cpp:332
double real_t
type of all real-valued scalars in escript
Definition: DataTypes.h:50
void addJob(boost::python::object j)
Definition: SubWorld.cpp:71