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