casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DistSIIterBot.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
2 //# DistSIIterBot.h: Parallel imaging iteration control
3 //# Copyright (C) 2016
4 //# Associated Universities, Inc. Washington DC, USA.
5 //#
6 //# This library is free software; you can redistribute it and/or modify it
7 //# under the terms of the GNU Library General Public License as published by
8 //# the Free Software Foundation; either version 2 of the License, or (at your
9 //# option) any later version.
10 //#
11 //# This library is distributed in the hope that it will be useful, but WITHOUT
12 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 //# License for more details.
15 //#
16 //# You should have received a copy of the GNU Library General Public License
17 //# along with this library; if not, write to the Free Software Foundation,
18 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
19 //#
20 //# Correspondence concerning AIPS++ should be addressed as follows:
21 //# Internet email: aips2-request@nrao.edu.
22 //# Postal address: AIPS++ Project Office
23 //# National Radio Astronomy Observatory
24 //# 520 Edgemont Road
25 //# Charlottesville, VA 22903-2475 USA
26 //#
27 #ifndef DIST_S_I_ITER_BOT_H_
28 #define DIST_S_I_ITER_BOT_H_
29 
31 // .casarc interface
33 
34 // System utilities (for profiling macros)
35 #include <casa/OS/HostInfo.h>
36 #include <sys/time.h>
37 #if defined(DBUS_CPP)
38 #include <dbus-cpp/dbus.h> /*for DBus::Variant... probably can be removed with *_adaptor class*/
39 #else
40 #include <dbus-c++/dbus.h>
41 #endif
42 
43 // Include files for the DBus Service
44 //#include <casadbus/interfaces/SynthImager.adaptor.h>
45 
46 #ifdef INTERACTIVE_ITERATION
47 #include <casadbus/interfaces/SynthImager.adaptor.h>
48 #endif
51 #include <mutex>
52 
53 namespace casa { //# NAMESPACE CASA - BEGIN
54 
56  : public SIIterBot_state {
57 private:
58  // make DistSIIterBot_state uncopyable...
61 
62 public:
63  DistSIIterBot_state(std::shared_ptr<SIIterBot_callback>, MPI_Comm);
65 
68  int cleanComplete();
74 
77 
78  int rank;
79  int commSize;
80 
81 protected:
83 
85 
90 };
91 
92 struct ExecRecord {
94  bool updatedModelFlag);
95 
96  ExecRecord(const casacore::Record &rec);
97 
99 
100  // Don't modify the following fields, including their order, without a
101  // corresponding change in the computation of datatype()!
103  int iterDone;
106 
107  void reduce(const ExecRecord *rec) {
108  iterDone += rec->iterDone;
109  maxCycleIterDone = std::max(maxCycleIterDone, rec->maxCycleIterDone);
110  peakResidual = std::max(peakResidual, rec->peakResidual);
111  updatedModelFlag |= rec->updatedModelFlag;
112  };
113 
114  // It might be nice to have static class members to hold the MPI datatype
115  // and reduction op, but since they can only be computed at run-time, that
116  // would require a mutex and lock (the computation would have to be in a
117  // critical section). In turn that would require acquiring the lock every
118  // time the datatype is accessed, which is something that we'd like to
119  // avoid.
121  int blocklengths[3] UNUSED_WITHOUT_MPI = { 1, 2, 1 };
122  MPI_Aint displacements[3] UNUSED_WITHOUT_MPI = {
123  offsetof(struct ExecRecord, peakResidual),
124  offsetof(struct ExecRecord, iterDone),
125  offsetof(struct ExecRecord, updatedModelFlag) };
126  MPI_Datatype types[3] UNUSED_WITHOUT_MPI =
127  { MPI_FLOAT, MPI_INT, MPI_BOOL };
128  MPI_Datatype dt;
129  MPI_Type_create_struct(3, blocklengths, displacements, types, &dt);
130  MPI_Datatype result;
131  // to capture padding for alignment of structures, we resize dt
132  MPI_Type_create_resized(dt, 0, sizeof(struct ExecRecord),
133  &result);
134  MPI_Type_free(&dt);
135  return result;
136  };
137 
138  static MPI_Op reduceOp() {
139  MPI_Op result;
141  static_cast<MPI_User_function *>(ExecRecord::reduceOpFun),
142  true,
143  &result);
144  return result;
145  };
146 
147  static void reduceOpFun(void *invec, void *inoutvec, int *len,
148  MPI_Datatype *datatype __attribute__((unused))) {
149  const ExecRecord *exin = static_cast<const ExecRecord *>(invec);
150  ExecRecord *exinout = static_cast<ExecRecord *>(inoutvec);
151  int cnt = *len; // OpenMPI at least doesn't like it if you directly
152  // decrement the value pointed to by *len -- not sure
153  // that the standard says anything about doing that
154  while (cnt-- > 0) {
155  exinout->reduce(exin);
156  ++exinout;
157  ++exin;
158  }
159  };
160 };
161 
163  DetailsRecord(const casacore::Record &rec);
164 
166 
167  // Don't modify the following fields, including their order, without a
168  // corresponding change in the computation of datatype()!
169  float threshold;
172  float loopGain;
173  float cycleFactor;
177  int niter;
180  int iterDone;
184  int cleanState; // 0: stopped, 1: paused, 2: running
186 
188  int blocklengths[3] UNUSED_WITHOUT_MPI = { 8, 8, 1 };
189  MPI_Aint displacements[3] UNUSED_WITHOUT_MPI = {
190  offsetof(struct DetailsRecord, threshold),
191  offsetof(struct DetailsRecord, niter),
192  offsetof(struct DetailsRecord, interactiveMode) };
193  MPI_Datatype types[3] UNUSED_WITHOUT_MPI =
194  { MPI_FLOAT, MPI_INT, MPI_BOOL };
195  MPI_Datatype dt;
196  MPI_Type_create_struct(3, blocklengths, displacements, types, &dt);
197  MPI_Datatype result;
198  // to capture padding for alignment of structures, we resize dt
199  MPI_Type_create_resized(dt, 0, sizeof(struct DetailsRecord),
200  &result);
201  MPI_Type_free(&dt);
202  return result;
203  };
204 };
205 
207  ControlRecord(int niter, int cycleNiter,
208  float threshold, float cycleThreshold,
209  float loopGain, bool stopFlag);
210 
211  ControlRecord(const casacore::Record &rec);
212 
214 
215  // Don't modify the following fields, including their order, without a
216  // corresponding change in the computation of datatype()!
217  float threshold;
219  float loopGain;
220  int niter;
223 
224  // It might be nice to have static class members to hold the MPI datatype
225  // and reduction op, but since they can only be computed at run-time, that
226  // would require a mutex and lock, since the computation would have to be in
227  // a critical section. In turn that would require acquiring the lock every
228  // time the datatype is accessed, which is something that we'd like to
229  // avoid.
231  int blocklengths[3] UNUSED_WITHOUT_MPI = { 3, 2, 1 };
232  MPI_Aint displacements[3] UNUSED_WITHOUT_MPI = {
233  offsetof(struct ControlRecord, threshold),
234  offsetof(struct ControlRecord, niter),
235  offsetof(struct ControlRecord, stopFlag)};
236  MPI_Datatype types[3] UNUSED_WITHOUT_MPI =
237  { MPI_FLOAT, MPI_INT, MPI_BOOL };
238  MPI_Datatype dt;
239  MPI_Type_create_struct(3, blocklengths, displacements, types, &dt);
240  MPI_Datatype result;
241  // to capture padding for alignment of structures, we resize dt
242  MPI_Type_create_resized(dt, 0, sizeof(struct ControlRecord),
243  &result);
244  MPI_Type_free(&dt);
245  return result;
246  };
247 };
248 
249 } //# NAMESPACE CASA - END
250 
251 #endif // DIST_S_I_ITER_BOT_H_
DistSIIterBot_state(const DistSIIterBot_state &)
make DistSIIterBot_state uncopyable...
void mergeCycleInitializationRecord(casacore::Record &)
A 1-D Specialization of the Array class.
casacore::Record asRecord()
casacore::Record asRecord()
int MPI_Comm
Definition: MPIGlue.h:59
MPI_BOOL_TYPE stopFlag
std::ptrdiff_t MPI_Aint
Definition: MPIGlue.h:63
#define MPI_Op_create(a, b, po)
Definition: MPIGlue.h:112
static void reduceOpFun(void *invec, void *inoutvec, int *len, MPI_Datatype *datatype __attribute__((unused)))
#define max(a, b)
Definition: hio.h:44
void mergeCycleInitializationRecords(const casacore::Vector< casacore::Record > &)
DetailsRecord(const casacore::Record &rec)
#define MPI_Type_create_resized(a, b, c, pd)
Definition: MPIGlue.h:109
#define UNUSED_WITHOUT_MPI
This header file is intended to facilitate writing source modules that use MPI, so that they can also...
Definition: MPIGlue.h:52
#define MPI_BOOL_TYPE
Definition: MPIGlue.h:53
static MPI_Datatype datatype()
It might be nice to have static class members to hold the MPI datatype and reduction op...
casacore::Record asRecord()
static MPI_Op reduceOp()
float threshold
Don&#39;t modify the following fields, including their order, without a corresponding change in the compu...
#define MPI_Type_free(pd)
Definition: MPIGlue.h:110
void mergeCycleExecutionRecords(const casacore::Vector< casacore::Record > &)
static MPI_Datatype datatype()
ControlRecord(int niter, int cycleNiter, float threshold, float cycleThreshold, float loopGain, bool stopFlag)
void reduce(const ExecRecord *rec)
int MPI_Datatype
Definition: MPIGlue.h:61
#define MPI_FLOAT
Definition: MPIGlue.h:56
int MPI_Op
Definition: MPIGlue.h:62
casacore::Record getDetailsRecord()
#define MPI_BOOL
Definition: MPIGlue.h:54
casacore::Record getSummaryRecord()
Functions for runtime parameter modification.
float threshold
Don&#39;t modify the following fields, including their order, without a corresponding change in the compu...
MPI_BOOL_TYPE interactiveMode
void mergeCycleExecutionRecord(casacore::Record &)
MPI_BOOL_TYPE updatedModelFlag
ExecRecord(int iterDone, int maxCycleIterDone, float peakResidual, bool updatedModelFlag)
A hierarchical collection of named fields of various types.
Definition: Record.h:180
void mergeMinorCycleSummary(const casacore::Array< casacore::Double > &)
MPI_Datatype detailsRecordDatatype
Definition: DistSIIterBot.h:88
MPI_Datatype controlRecordDatatype
Definition: DistSIIterBot.h:89
casacore::Record getMinorCycleControls()
#define MPI_Type_create_struct(a, b, c, d, pd)
Definition: MPIGlue.h:108
static MPI_Datatype datatype()
It might be nice to have static class members to hold the MPI datatype and reduction op...
#define MPI_INT
Definition: MPIGlue.h:55
DistSIIterBot_state & operator=(const DistSIIterBot_state &)
MPI_Datatype execRecordDatatype
Definition: DistSIIterBot.h:86
float peakResidual
Don&#39;t modify the following fields, including their order, without a corresponding change in the compu...