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