escript  Revision_
AbstractReducer.h
Go to the documentation of this file.
1 /*****************************************************************************
2 *
3 * Copyright (c) 2014-2016 by The University of Queensland
4 * http://www.uq.edu.au
5 *
6 * Primary Business: Queensland, Australia
7 * Licensed under the Apache License, version 2.0
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
11 * Development 2012-2013 by School of Earth Sciences
12 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
13 *
14 *****************************************************************************/
15 
16 #ifndef __ESCRIPT_ABSTRACTREDUCER_H__
17 #define __ESCRIPT_ABSTRACTREDUCER_H__
18 
19 #include <escript/Data.h>
20 #include <escript/EsysMPI.h>
21 
22 #include <boost/shared_ptr.hpp>
23 
24 namespace escript
25 {
26 
27 
28 namespace reducerstatus
29 {
30 
31 // Because these may be used in loops, the values must form a contiguous block (except ERROR)
32 const unsigned char NONE=0; // I have no value for this var and no interest in it
33 const unsigned char INTERESTED=1; // I am interested in this variable but I have no value for it
34 const unsigned char OLD=2; // I have a copy from elsewhere but no new values to contribute
35 const unsigned char OLDINTERESTED=3; // interested but only have a cached copy (no new values)
36 const unsigned char NEW=4; // I have a new value for this variable
37 const unsigned char ERROR='!'; // Something bad happened
38 }
39 
40 // There is currently no way to get a completely generic result out of this
42 {
43 public:
44  virtual ~AbstractReducer() {}
45  // Is the value compatible with this reduction function?
46  // does not guarantee the value is compatible with
47  // other values added so far
48  virtual bool valueCompatible(boost::python::object v)=0;
49  // merge the parameter with the answer we already have
50  virtual bool reduceLocalValue(boost::python::object v, std::string& errstring)=0;
51  // clear previous result ready for a new set of reductions
52  virtual void reset()=0;
53 
54  virtual std::string description()=0;
55 
56  // converse with other subworlds to ensure subtype information matches
57  // The main problem case here would be Data on different function spaces
58  // same communicator requirements for reduceRemoteValues
59  // Must give the same answer when called on any process in the subworlds
60  // Must only be called on
61  virtual bool checkRemoteCompatibility(JMPI& mpi_info, std::string& errstring)=0;
62  // Some reducers need to know what domain they are operating in
63  virtual void setDomain(Domain_ptr dom) {}
64 
65 
66 #ifdef ESYS_MPI
67  // send from proc 0 in the communicator to all others
68  // second param is true if we have rank o
69  virtual bool groupSend(MPI_Comm& com, bool imsending)=0;
70 
71  // reduction with some procs submitting identity values
72  virtual bool groupReduce(MPI_Comm& com, char mystate)=0;
73 #endif
74 
75  // call to merge with values on other subworlds
76  // It does not take a value argument because local values should have
77  // already been added with reduceLocal
78  // Must only be called on participating SubWorlds
79  // the mpi_info holds a communicator linking corresponding processes
80  // in every participating subworld
81  virtual bool reduceRemoteValues(MPI_Comm& comm)=0;
82 
83  // true if at least one localValue has been added
84  // used to check if this subworld should participate in remote merges
85  bool hasValue();
86 
87  // true if reductions could fail for some reason other than MPI failure
88  // for example SET type variables
89  virtual bool canClash();
90 
91  // Get a value for this variable from another process
92  // This is not a reduction and will replace any existing value
93  virtual bool recvFrom(int localid, int source, JMPI& mpiinfo)=0;
94 
95  // Send a value to this variable to another process
96  // This is not a reduction and will replace any existing value
97  virtual bool sendTo(int localid, int target, JMPI& mpiinfo)=0;
98 
99  virtual double getDouble();
100 
101  virtual boost::python::object getPyObj()=0;
102 
103  // notify the reducer that a new runJobs() call is being executed
104  virtual void newRunJobs();
105 
106  virtual void clear();
107 
108  virtual void copyValueFrom(boost::shared_ptr<AbstractReducer>& src)=0;
109 
110 protected:
113  static const int PARAMTAG;
114 };
115 
116 
117 typedef boost::shared_ptr<AbstractReducer> Reducer_ptr;
118 
119 }
120 
121 #endif // __ESCRIPT_ABSTRACTREDUCER_H__
122 
const unsigned char OLD
Definition: AbstractReducer.h:34
const unsigned char NEW
Definition: AbstractReducer.h:36
virtual void setDomain(Domain_ptr dom)
Definition: AbstractReducer.h:63
boost::shared_ptr< AbstractDomain > Domain_ptr
Definition: AbstractDomain.h:36
Definition: AbstractContinuousDomain.cpp:22
Definition: AbstractReducer.h:41
boost::shared_ptr< JMPI_ > JMPI
Definition: EsysMPI.h:71
const unsigned char ERROR
Definition: AbstractReducer.h:37
boost::shared_ptr< AbstractReducer > Reducer_ptr
Definition: AbstractReducer.h:117
const unsigned char NONE
Definition: AbstractReducer.h:32
int MPI_Comm
Definition: EsysMPI.h:41
bool had_an_export_this_round
Definition: AbstractReducer.h:112
bool valueadded
Definition: AbstractReducer.h:111
const unsigned char OLDINTERESTED
Definition: AbstractReducer.h:35
static const int PARAMTAG
Definition: AbstractReducer.h:113
virtual ~AbstractReducer()
Definition: AbstractReducer.h:44
const unsigned char INTERESTED
Definition: AbstractReducer.h:33