casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PTransport.h
Go to the documentation of this file.
1 //# PTransport.h: Base class for parallel data transport models
2 //# Copyright (C) 1998,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_PTRANSPORT_H
30 #define SYNTHESIS_PTRANSPORT_H
31 
32 //# Includes
33 #include <casa/aips.h>
34 #include <casa/Arrays/Array.h>
35 
36 namespace casacore{
37 
38 class Record;
39 }
40 
41 namespace casa { //# NAMESPACE CASA - BEGIN
42 
43 //# Forward Declarations
44 class Algorithm;
45 
46 // <summary>
47 // Base class for parallel data transport models
48 // </summary>
49 
50 // <use visibility=local> or <use visibility=export>
51 
52 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
53 // </reviewed>
54 
55 // <prerequisite>
56 // <li> SomeClass
57 // <li> SomeOtherClass
58 // <li> some concept
59 // </prerequisite>
60 //
61 // <etymology>
62 // </etymology>
63 //
64 // <synopsis>
65 // </synopsis>
66 //
67 // <example>
68 // </example>
69 //
70 // <motivation>
71 // </motivation>
72 //
73 //
74 //# <todo asof="yyyy/mm/dd">
75 //# <li> add this feature
76 //# <li> fix this bug
77 //# <li> start discussion of this possible extension
78 //# </todo>
79 
80 
81 class PTransport {
82  public:
83  // Default constructor and destructor
84  PTransport() : numprocs(0), myCpu(0), aWorker(0), aTag(0) {};
85  virtual ~PTransport() {}
86 
87  // Return the number of processes
89 
90  // Return the current process rank
91  casacore::Int cpu() {return myCpu;}
92 
93  // Set the properties of the current connection including
94  // source/destination and message tag.
96  void connectAnySource() {aWorker=anySource(); return;};
98  void setTag(casacore::Int tag) {aTag=tag; return;};
99  void setAnyTag() {aTag=anyTag(); return;};
100 
101  // Status functions for worker/controller designation
104 
105  // Default source and message tag values
106  virtual casacore::Int anyTag() = 0;
107  virtual casacore::Int anySource() = 0;
108 
109  // Define the rank of the controller process
110  virtual casacore::Int controllerRank() = 0;
111 
112  // Get and put functions on the parallel data transport layer
117  virtual casacore::Int put(const casacore::Array<casacore::Int> &) = 0;
118  virtual casacore::Int put(const casacore::Float &) = 0;
119  virtual casacore::Int put(const casacore::Double &) = 0;
120  virtual casacore::Int put(const casacore::Complex &) = 0;
121  virtual casacore::Int put(const casacore::DComplex &) = 0;
122  virtual casacore::Int put(const casacore::Int &) = 0;
123  virtual casacore::Int put(const casacore::String &) = 0;
124  virtual casacore::Int put(const casacore::Bool &) = 0;
125  virtual casacore::Int put(const casacore::Record &) = 0;
126 
132  virtual casacore::Int get(casacore::Float &) = 0;
133  virtual casacore::Int get(casacore::Double &) = 0;
134  virtual casacore::Int get(casacore::Complex &) = 0;
135  virtual casacore::Int get(casacore::DComplex &) = 0;
136  virtual casacore::Int get(casacore::Int &) = 0;
137  virtual casacore::Int get(casacore::String &) = 0;
138  virtual casacore::Int get(casacore::Bool &) = 0;
139  virtual casacore::Int get(casacore::Record &) = 0;
140 
141  protected:
142  // Number of processes
144 
145  // Rank of current process
147 
148  // Current source or destination process
150 
151  // Current message tag
153 };
154 
155 // Putting in the MPI Transport stuff only makes sense if we have MPI
156 
157 #ifdef HasMPI
158 // <summary>
159 // MPI data transport models
160 // </summary>
161 
162 // <use visibility=local>
163 
164 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
165 // </reviewed>
166 
167 // <prerequisite>
168 // <li> SomeClass
169 // <li> SomeOtherClass
170 // <li> some concept
171 // </prerequisite>
172 //
173 // <etymology>
174 // </etymology>
175 //
176 // <synopsis>
177 // </synopsis>
178 //
179 // <example>
180 // </example>
181 //
182 // <motivation>
183 // </motivation>
184 //
185 //
186 //# <todo asof="yyyy/mm/dd">
187 //# <li> add this feature
188 //# <li> fix this bug
189 //# <li> start discussion of this possible extension
190 //# </todo>
191 
192 class MPITransport : public PTransport {
193  public:
194  // Default constructor and destructor
195  MPITransport();
196  virtual ~MPITransport();
197 
198  // Construct from argv
199  MPITransport(casacore::Int, casacore::Char *argv[]);
200 
201  // Default source and message tag values
202  virtual casacore::Int anyTag();
203  virtual casacore::Int anySource();
204 
205  // Define the rank of the controller process
206  virtual casacore::Int controllerRank() {return 0;};
207 
208  // Get and put functions on the parallel data transport layer
209  virtual casacore::Int put(const casacore::Array<casacore::Float> &);
213  virtual casacore::Int put(const casacore::Array<casacore::Int> &);
214  virtual casacore::Int put(const casacore::Float &);
215  virtual casacore::Int put(const casacore::Double &);
216  virtual casacore::Int put(const casacore::Complex &);
217  virtual casacore::Int put(const casacore::DComplex &);
218  virtual casacore::Int put(const casacore::Int &);
219  virtual casacore::Int put(const casacore::String &);
220  virtual casacore::Int put(const casacore::Bool &);
221  virtual casacore::Int put(const casacore::Record &);
222 
228  virtual casacore::Int get(casacore::Float &);
229  virtual casacore::Int get(casacore::Double &);
230  virtual casacore::Int get(casacore::Complex &);
231  virtual casacore::Int get(casacore::DComplex &);
232  virtual casacore::Int get(casacore::Int &);
233  virtual casacore::Int get(casacore::String &);
234  virtual casacore::Int get(casacore::Bool &);
235  virtual casacore::Int get(casacore::Record &);
236 
237  private:
238  // Local work variables
239  casacore::Int sendTo, myOp, getFrom;
240 
241  // Utility functions to set default source/destination and tag values
242  void setSourceAndTag (casacore::Int &source, casacore::Int &tag);
243  void setDestAndTag (casacore::Int &dest, casacore::Int &tag);
244 };
245 #endif
246 
247 // <summary>
248 // Serial casacore::Data Transport Model
249 // </summary>
250 
251 // <use visibility=local>
252 
253 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
254 // </reviewed>
255 
256 // <prerequisite>
257 // <li> SomeClass
258 // <li> SomeOtherClass
259 // <li> some concept
260 // </prerequisite>
261 //
262 // <etymology>
263 // </etymology>
264 //
265 // <synopsis>
266 // </synopsis>
267 //
268 // <example>
269 // </example>
270 //
271 // <motivation>
272 // </motivation>
273 //
274 //
275 //# <todo asof="yyyy/mm/dd">
276 //# <li> add this feature
277 //# <li> fix this bug
278 //# <li> start discussion of this possible extension
279 //# </todo>
280 
281 // SerialTransport is your basic no-op. We're just passing the pointers
282 // to avoid unnecessary data copying.
283 
284 class SerialTransport : public PTransport {
285  public:
286  // Default constructor and destructor
288  {_data.resize(20);}
289  virtual ~SerialTransport(){}
290 
291  // Default source and message tag values
292  virtual casacore::Int anyTag() {return -1;};
293  virtual casacore::Int anySource() {return -1;};
294 
295  // Define the rank of the controller process
296  virtual casacore::Int controllerRank() {return 0;};
297 
298  // Get and put functions on the data transport layer
304  virtual casacore::Int put(const casacore::Float &);
305  virtual casacore::Int put(const casacore::Double &);
306  virtual casacore::Int put(const casacore::Complex &);
307  virtual casacore::Int put(const casacore::DComplex &);
308  virtual casacore::Int put(const casacore::Int &);
309  virtual casacore::Int put(const casacore::String &);
310  virtual casacore::Int put(const casacore::Bool &);
311  virtual casacore::Int put(const casacore::Record &);
312 
318  virtual casacore::Int get(casacore::Float &);
319  virtual casacore::Int get(casacore::Double &);
320  virtual casacore::Int get(casacore::Complex &);
321  virtual casacore::Int get(casacore::DComplex &);
322  virtual casacore::Int get(casacore::Int &);
323  virtual casacore::Int get(casacore::String &);
324  virtual casacore::Int get(casacore::Bool &);
325  virtual casacore::Int get(casacore::Record &);
326 
327  private:
332 
333  casacore::Int add2Queue(void *);
334  void *getFromQueue();
335 };
336 
337 
338 } //# NAMESPACE CASA - END
339 
340 #endif
341 
342 
casacore::uInt lastInQue
Definition: PTransport.h:330
casacore::Int connect(casacore::Int i)
Set the properties of the current connection including source/destination and message tag...
Definition: PTransport.h:95
casacore::Int aWorker
Current source or destination process.
Definition: PTransport.h:149
void setAnyTag()
Definition: PTransport.h:99
int Int
Definition: aipstype.h:50
virtual casacore::Int anyTag()=0
Default source and message tag values.
void connectAnySource()
Definition: PTransport.h:96
void setTag(casacore::Int tag)
Definition: PTransport.h:98
casacore::Bool isController()
Status functions for worker/controller designation.
Definition: PTransport.h:102
void connectToController()
Definition: PTransport.h:97
virtual ~PTransport()
Definition: PTransport.h:85
casacore::uInt outQue
Definition: PTransport.h:329
Putting in the MPI Transport stuff only makes sense if we have MPI.
Definition: PTransport.h:284
char Char
Definition: aipstype.h:46
casacore::Int myCpu
Rank of current process.
Definition: PTransport.h:146
SerialTransport()
Default constructor and destructor.
Definition: PTransport.h:287
virtual casacore::Int anyTag()
Default source and message tag values.
Definition: PTransport.h:292
PTransport()
Default constructor and destructor.
Definition: PTransport.h:84
casacore::uInt inQue
Definition: PTransport.h:328
virtual casacore::Int controllerRank()
Define the rank of the controller process.
Definition: PTransport.h:296
virtual casacore::Int put(const casacore::Array< casacore::Float > &)=0
Get and put functions on the parallel data transport layer.
double Double
Definition: aipstype.h:55
virtual casacore::Int anySource()
Definition: PTransport.h:293
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
void resize(size_t n, Bool forceSmaller, Bool copyElements)
Definition: Block.h:825
casacore::Int numThreads()
Return the number of processes.
Definition: PTransport.h:88
float Float
Definition: aipstype.h:54
virtual ~SerialTransport()
Definition: PTransport.h:289
casacore::Int cpu()
Return the current process rank.
Definition: PTransport.h:91
casacore::Int aTag
Current message tag.
Definition: PTransport.h:152
casacore::Bool isWorker()
Definition: PTransport.h:103
casacore::Int numprocs
Number of processes.
Definition: PTransport.h:143
String: the storage and methods of handling collections of characters.
Definition: String.h:223
virtual casacore::Int anySource()=0
virtual casacore::Int put(const casacore::Array< casacore::Float > &)
Get and put functions on the data transport layer.
virtual casacore::Int controllerRank()=0
Define the rank of the controller process.
casacore::PtrBlock< void * > _data
Definition: PTransport.h:331
unsigned int uInt
Definition: aipstype.h:51
casacore::Int add2Queue(void *)
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42