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