casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Applicator.h
Go to the documentation of this file.
1 //# Applicator.h: interface to parallelization infrastructure
2 //# Copyright (C) 1999,2000
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //#
27 //# $Id$
28 
29 #ifndef SYNTHESIS_APPLICATOR_H
30 #define SYNTHESIS_APPLICATOR_H
31 
32 //# Includes
33 
34 #include <map>
35 #include <casa/aips.h>
36 #include <casa/Arrays/Vector.h>
38 #include <casa/Containers/Record.h>
40 
41 namespace casa { //# NAMESPACE CASA - BEGIN
42 
43 //# Forward Declarations
44 class Algorithm;
45 
46 // <summary>
47 // Class which provides an interface to the parallelization infrastructure
48 // </summary>
49 
50 // <use visibility=local>
51 
52 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
53 // </reviewed>
54 
55 // <prerequisite>
56 // <li> Algorithm
57 // <li> PTransport
58 // </prerequisite>
59 //
60 // <etymology>
61 // Applies or controls the execution of parallelized algorithms.
62 // </etymology>
63 //
64 // <synopsis>
65 // The Applicator class provides the interface to parallel communication.
66 // It holds the parallel transport layer, and controls the execution of
67 // parallelized algorithms.
68 // </synopsis>
69 //
70 // <example>
71 // </example>
72 //
73 // <motivation>
74 // To provide a simple programming interface to parallelization, and
75 // to encapsulate the transport layer and parallel process control.
76 // </motivation>
77 //
78 //# <thrown>
79 //# <li>
80 //# <li>
81 //# </thrown>
82 //
83 //# <todo asof="1999/12/21">
84 //# <li> Document
85 //# </todo>
86 
87 
88 class Applicator {
89  public:
90  // Enum to define the process status table
91  enum Status {FREE, ASSIGNED};
92 
93  // Recognized signals
94  enum Signals {STOP = 0, DONE = -1};
95 
96  // Default constructor, and destructor
97  Applicator();
98  ~Applicator();
99 
100  // Initialization (includes parallel transport initialization)
101  void init(casacore::Int argc, casacore::Char *argv[]);
102  void initThreads(casacore::Int argc, casacore::Char *argv[]);
103  void initThreads();
104 
105  // define an Algorithm if we need too;
106  void defineAlgorithm(Algorithm *);
107 
108  // Status functions to indicate whether this Applicator is
109  // executing as a controller or worker process
112 
113  // true if executing serially
115 
116  // Return the number of processes
118 
119  // Assign the next free worker process to a specified Algorithm
121 
122  // Return the rank of the next process to complete the specified Algorithm
124 
125  // Signal that a worker process is done
126  void done();
127 
128  // Execute an algorithm directly
129  void apply(Algorithm &a);
130 
131  // Put and get methods to be executed on the parallel transport layer
137  casacore::Int put(const casacore::Float &n) {return comm->put(n);};
138  casacore::Int put(const casacore::Complex &n) {return comm->put(n);};
139  casacore::Int put(const casacore::DComplex &n) {return comm->put(n);};
140  casacore::Int put(const casacore::Double &n) {return comm->put(n);};
141  casacore::Int put(const casacore::Int &n) {return comm->put(n);};
142  casacore::Int put(const casacore::Bool &b) {return comm->put(b);};
143  casacore::Int put(const casacore::String &s) {return comm->put(s);};
144  casacore::Int put(const casacore::Record &r) {return comm->put(r);};
145 
151  casacore::Int get(casacore::Float &n) {return comm->get(n);};
152  casacore::Int get(casacore::Double &n) {return comm->get(n);};
153  casacore::Int get(casacore::Complex &n) {return comm->get(n);};
154  casacore::Int get(casacore::DComplex &n) {return comm->get(n);};
155  casacore::Int get(casacore::Int &n) {return comm->get(n);};
156  casacore::Int get(casacore::Bool &b) {return comm->get(b);};
157  casacore::Int get(casacore::String &s) {return comm->get(s);};
158  casacore::Int get(casacore::Record &r) {return comm->get(r);};
159 
160  private:
161  // Pointer to the parallel transport
162  PTransport *comm;
163 
164  // casacore::Map of known algorithm names and id.'s
165  std::map<casacore::String, casacore::Int> algorithmIds;
166  std::map<casacore::Int, Algorithm*> knownAlgorithms;
167 
168  // ID for the last Algorithm defined.
170 
171  // true if no more processes are free
173 
174  // true if executing in serial
176 
177  // Number of processes
179 
180  // Process status list
182 
183  // Executed by worker process waiting for an assigned task
184  void loop();
185 
186  // Fill algorithm map
187  void defineAlgorithms();
188 
189  // Utility functions for the current list of processes, and their status
190  void setupProcStatus();
192 };
193 
194 
195 } //# NAMESPACE CASA - END
196 
197 #endif
198 
199 
200 
201 
void init(casacore::Int argc, casacore::Char *argv[])
Initialization (includes parallel transport initialization)
casacore::Int put(const casacore::Bool &b)
Definition: Applicator.h:142
int Int
Definition: aipstype.h:50
casacore::Int put(const casacore::Array< casacore::Double > &an)
Definition: Applicator.h:133
void defineAlgorithms()
Fill algorithm map.
PTransport * comm
Pointer to the parallel transport.
Definition: Applicator.h:158
std::map< casacore::Int, Algorithm * > knownAlgorithms
Definition: Applicator.h:166
casacore::Vector< casacore::Int > procStatus
Process status list.
Definition: Applicator.h:181
casacore::Int nProcs
Number of processes.
Definition: Applicator.h:178
casacore::Int put(const casacore::Array< casacore::Int > &an)
Definition: Applicator.h:134
Defines a computational unit for parallel processing.
Definition: Algorithm.h:89
std::map< casacore::String, casacore::Int > algorithmIds
casacore::Map of known algorithm names and id.
Definition: Applicator.h:165
casacore::Int nextProcessDone(Algorithm &a, casacore::Bool &allDone)
Return the rank of the next process to complete the specified Algorithm.
Signals
Recognized signals.
Definition: Applicator.h:94
casacore::Bool nextAvailProcess(Algorithm &a, casacore::Int &rank)
Assign the next free worker process to a specified Algorithm.
void loop()
Executed by worker process waiting for an assigned task.
char Char
Definition: aipstype.h:46
casacore::Int LastID
ID for the last Algorithm defined.
Definition: Applicator.h:169
Class which provides an interface to the parallelization infrastructure.
Definition: Applicator.h:88
casacore::Int put(const casacore::String &s)
Definition: Applicator.h:143
Applicator()
Default constructor, and destructor.
casacore::Int findFreeProc(casacore::Bool &lastOne)
casacore::Int put(const casacore::Array< casacore::Complex > &an)
Definition: Applicator.h:135
virtual casacore::Int put(const casacore::Array< casacore::Float > &)=0
Get and put functions on the parallel data transport layer.
casacore::Int put(const casacore::Double &n)
Definition: Applicator.h:140
casacore::Int put(const casacore::Array< casacore::DComplex > &an)
Definition: Applicator.h:136
Status
Enum to define the process status table.
Definition: Applicator.h:91
casacore::Int put(const casacore::Int &n)
Definition: Applicator.h:141
double Double
Definition: aipstype.h:55
casacore::Int put(const casacore::Float &n)
Definition: Applicator.h:137
casacore::Bool usedAllThreads
true if no more processes are free
Definition: Applicator.h:172
void done()
Signal that a worker process is done.
casacore::Int put(const casacore::DComplex &n)
Definition: Applicator.h:139
A hierarchical collection of named fields of various types.
Definition: Record.h:180
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
Base class for parallel data transport models.
Definition: PTransport.h:81
float Float
Definition: aipstype.h:54
casacore::Bool isController()
Status functions to indicate whether this Applicator is executing as a controller or worker process...
casacore::Int numProcs()
Return the number of processes.
Definition: Applicator.h:117
casacore::Int put(const casacore::Array< casacore::Float > &an)
Put and get methods to be executed on the parallel transport layer.
Definition: Applicator.h:132
casacore::Bool isWorker()
String: the storage and methods of handling collections of characters.
Definition: String.h:223
void defineAlgorithm(Algorithm *)
define an Algorithm if we need too;
void apply(Algorithm &a)
Execute an algorithm directly.
casacore::Bool isSerial()
true if executing serially
Definition: Applicator.h:114
casacore::Int put(const casacore::Record &r)
Definition: Applicator.h:144
virtual casacore::Int get(casacore::Array< casacore::Float > &)=0
casacore::Bool serial
true if executing in serial
Definition: Applicator.h:175
casacore::Int put(const casacore::Complex &n)
Definition: Applicator.h:138
void setupProcStatus()
Utility functions for the current list of processes, and their status.