casa
$Rev:20696$
|
00001 //# Applicator.h: interface to parallelization infrastructure 00002 //# Copyright (C) 1999,2000 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# 00027 //# $Id$ 00028 00029 #ifndef SYNTHESIS_APPLICATOR_H 00030 #define SYNTHESIS_APPLICATOR_H 00031 00032 //# Includes 00033 00034 #include <casa/aips.h> 00035 #include <casa/Arrays/Vector.h> 00036 #include <lattices/Lattices/Lattice.h> 00037 #include <casa/Containers/OrderedMap.h> 00038 #include <casa/Containers/Record.h> 00039 #include <synthesis/Parallel/PTransport.h> 00040 00041 namespace casa { //# NAMESPACE CASA - BEGIN 00042 00043 //# Forward Declarations 00044 class Algorithm; 00045 00046 // <summary> 00047 // Class which provides an interface to the parallelization infrastructure 00048 // </summary> 00049 00050 // <use visibility=local> 00051 00052 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00053 // </reviewed> 00054 00055 // <prerequisite> 00056 // <li> Algorithm 00057 // <li> PTransport 00058 // </prerequisite> 00059 // 00060 // <etymology> 00061 // Applies or controls the execution of parallelized algorithms. 00062 // </etymology> 00063 // 00064 // <synopsis> 00065 // The Applicator class provides the interface to parallel communication. 00066 // It holds the parallel transport layer, and controls the execution of 00067 // parallelized algorithms. 00068 // </synopsis> 00069 // 00070 // <example> 00071 // </example> 00072 // 00073 // <motivation> 00074 // To provide a simple programming interface to parallelization, and 00075 // to encapsulate the transport layer and parallel process control. 00076 // </motivation> 00077 // 00078 //# <thrown> 00079 //# <li> 00080 //# <li> 00081 //# </thrown> 00082 // 00083 //# <todo asof="1999/12/21"> 00084 //# <li> Document 00085 //# </todo> 00086 00087 00088 class Applicator { 00089 public: 00090 // Enum to define the process status table 00091 enum Status {FREE, ASSIGNED}; 00092 00093 // Recognized signals 00094 enum Signals {STOP = 0, DONE = -1}; 00095 00096 // Default constructor, and destructor 00097 Applicator(); 00098 ~Applicator(); 00099 00100 // Initialization (includes parallel transport initialization) 00101 void init(Int argc, Char *argv[]); 00102 void initThreads(Int argc, Char *argv[]); 00103 void initThreads(); 00104 00105 // define an Algorithm if we need too; 00106 void defineAlgorithm(Algorithm *); 00107 00108 // Status functions to indicate whether this Applicator is 00109 // executing as a controller or worker process 00110 Bool isController(); 00111 Bool isWorker(); 00112 00113 // True if executing serially 00114 Bool isSerial() {return serial;}; 00115 00116 // Return the number of processes 00117 Int numProcs() {return nProcs;}; 00118 00119 // Assign the next free worker process to a specified Algorithm 00120 Bool nextAvailProcess(Algorithm &a, Int &rank); 00121 00122 // Return the rank of the next process to complete the specified Algorithm 00123 Int nextProcessDone(Algorithm &a, Bool &allDone); 00124 00125 // Signal that a worker process is done 00126 void done(); 00127 00128 // Execute an algorithm directly 00129 void apply(Algorithm &a); 00130 00131 // Put and get methods to be executed on the parallel transport layer 00132 Int put(const Array<Float> &an) {return comm->put(an);}; 00133 Int put(const Array<Double> &an) {return comm->put(an);}; 00134 Int put(const Array<Int> &an) {return comm->put(an);}; 00135 Int put(const Array<Complex> &an) {return comm->put(an);}; 00136 Int put(const Array<DComplex> &an) {return comm->put(an);}; 00137 Int put(const Float &n) {return comm->put(n);}; 00138 Int put(const Complex &n) {return comm->put(n);}; 00139 Int put(const DComplex &n) {return comm->put(n);}; 00140 Int put(const Double &n) {return comm->put(n);}; 00141 Int put(const Int &n) {return comm->put(n);}; 00142 Int put(const Bool &b) {return comm->put(b);}; 00143 Int put(const String &s) {return comm->put(s);}; 00144 Int put(const Record &r) {return comm->put(r);}; 00145 00146 Int get(Array<Float> &an) {return comm->get(an);}; 00147 Int get(Array<Double> &an) {return comm->get(an);}; 00148 Int get(Array<Complex> &an) {return comm->get(an);}; 00149 Int get(Array<DComplex> &an) {return comm->get(an);}; 00150 Int get(Array<Int> &an) {return comm->get(an);}; 00151 Int get(Float &n) {return comm->get(n);}; 00152 Int get(Double &n) {return comm->get(n);}; 00153 Int get(Complex &n) {return comm->get(n);}; 00154 Int get(DComplex &n) {return comm->get(n);}; 00155 Int get(Int &n) {return comm->get(n);}; 00156 Int get(Bool &b) {return comm->get(b);}; 00157 Int get(String &s) {return comm->get(s);}; 00158 Int get(Record &r) {return comm->get(r);}; 00159 00160 private: 00161 // Pointer to the parallel transport 00162 PTransport *comm; 00163 00164 // Map of known algorithm names and id.'s 00165 OrderedMap<String, Int> algorithmIds; 00166 OrderedMap<Int, Algorithm*> knownAlgorithms; 00167 00168 // ID for the last Algorithm defined. 00169 Int LastID; 00170 00171 // True if no more processes are free 00172 Bool usedAllThreads; 00173 00174 // True if executing in serial 00175 Bool serial; 00176 00177 // Number of processes 00178 Int nProcs; 00179 00180 // Process status list 00181 Vector<Int> procStatus; 00182 00183 // Executed by worker process waiting for an assigned task 00184 void loop(); 00185 00186 // Fill algorithm map 00187 void defineAlgorithms(); 00188 00189 // Utility functions for the current list of processes, and their status 00190 void setupProcStatus(); 00191 Int findFreeProc(Bool &lastOne); 00192 }; 00193 00194 00195 } //# NAMESPACE CASA - END 00196 00197 #endif 00198 00199 00200 00201