Overture  Version 25
ParallelUtility.h
Go to the documentation of this file.
1 #ifndef PARALLEL_UTILITY_H
2 #define PARALLEL_UTILITY_H
3 
4 #include "GenericDataBase.h"
5 #include "wdhdefs.h" // some useful defines and constants
6 #include "mathutil.h" // define max, min, etc
7 #include "OvertureInit.h"
8 
9 #include "broadCast.h"
10 #include "display.h"
11 
12 #ifndef OV_USE_OLD_STL_HEADERS
13 #include <list>
14 #include <vector>
15 #else
16 #include <list.h>
17 #include <vector>
18 #endif
19 
20 doubleSerialArray& getLocalArrayWithGhostBoundaries( const doubleArray & u, doubleSerialArray & uLocal );
21 floatSerialArray& getLocalArrayWithGhostBoundaries( const floatArray & u, floatSerialArray & uLocal );
22 intSerialArray& getLocalArrayWithGhostBoundaries( const intArray & u, intSerialArray & uLocal );
23 
24 
26 {
27  public:
28 
29  // broadcast argc, argv to all processors in a communicator
30  static int broadCastArgs(int & argc, char **&argv, int sourceProcessor=0, MPI_Comm comm=MPI_COMM_WORLD );
31  static int broadCastArgsCleanup(int & argc, char **&argv, int sourceProcessor=0 );
32 
33  // get max over all processors in a communicator
34  static real getMaxValue(real value, int processor=-1, MPI_Comm comm=MPI_COMM_WORLD);
35  static int getMaxValue(int value, int processor=-1, MPI_Comm comm=MPI_COMM_WORLD);
36  static doubleLengthInt getMaxValue(doubleLengthInt value, int processor=-1, MPI_Comm comm=MPI_COMM_WORLD);
37 
38  // get min over all processors in a communicator
39  static real getMinValue(real value, int processor=-1, MPI_Comm comm=MPI_COMM_WORLD);
40  static int getMinValue(int value, int processor=-1, MPI_Comm comm=MPI_COMM_WORLD);
41  static doubleLengthInt getMinValue(doubleLengthInt value, int processor=-1, MPI_Comm comm=MPI_COMM_WORLD);
42 
43  // get sum over all processors in a communicator
44  static real getSum(real value, int processor=-1, MPI_Comm comm=MPI_COMM_WORLD);
45  static int getSum(int value, int processor=-1, MPI_Comm comm=MPI_COMM_WORLD);
46  static doubleLengthInt getSum(doubleLengthInt value, int processor=-1, MPI_Comm comm=MPI_COMM_WORLD);
47 
48  // get max of all array components over all processors in a communicator
49  static void getMaxValues(real *value, real *maxValue, int n, int processor=-1, MPI_Comm comm=MPI_COMM_WORLD);
50  static void getMaxValues(int *value, int *maxValue, int n, int processor=-1, MPI_Comm comm=MPI_COMM_WORLD);
51 
52  // get min of all array components over all processors in a communicator
53  static void getMinValues(real *value, real *minValue, int n, int processor=-1, MPI_Comm comm=MPI_COMM_WORLD);
54  static void getMinValues(int *value, int *minvalue, int n, int processor=-1, MPI_Comm comm=MPI_COMM_WORLD);
55 
56  // get sum of all array components over all processors in a communicator
57  static void getSums(real *value, real *sum, int n, int processor=-1, MPI_Comm comm=MPI_COMM_WORLD);
58  static void getSums(int *value, int *sum, int n, int processor=-1, MPI_Comm comm=MPI_COMM_WORLD);
59 
60  // Make the assignment dest(D[0],...,D[nd-1]) = src(S[0],...S[nd-1])
61  static int copy( intArray & dest, Index *D,
62  const intArray & src, Index *S, int nd );
63 
64  static int copy( floatArray & dest, Index *D,
65  const floatArray & src, Index *S, int nd );
66 
67  static int copy( doubleArray & dest, Index *D,
68  const doubleArray & src, Index *S, int nd );
69 
70 
71  static int getArgsFromFile(const aString & fileName, int & argc, char **&argv );
72 
73  static int deleteArgsFromFile(int & argc, char **&argv );
74 
75  static bool getLocalArrayBounds(const realArray & u, const realSerialArray & uLocal,
76  Index & I1, Index & I2, Index & I3,
77  int & n1a, int & n1b, int & n2a, int & n2b, int & n3a, int & n3b,
78  int option = 0 );
79 
80  static bool getLocalArrayBounds(const realArray & u, const realSerialArray & uLocal,
81  Index & I1, Index & I2, Index & I3,
82  int option = 0 );
83 
84  static bool getLocalArrayBounds(const realArray & u, const realSerialArray & uLocal,
85  Index & I1, Index & I2, Index & I3, Index &I4,
86  int & n1a, int & n1b, int & n2a, int & n2b, int & n3a, int & n3b, int & n4a, int & n4b,
87  int option = 0 );
88 
89  static bool getLocalArrayBounds(const realArray & u, const realSerialArray & uLocal,
90  Index & I1, Index & I2, Index & I3, Index & I4,
91  int option = 0 );
92 
93  static bool getLocalArrayBounds(const intArray & u, const intSerialArray & uLocal,
94  Index & I1, Index & I2, Index & I3,
95  int & n1a, int & n1b, int & n2a, int & n2b, int & n3a, int & n3b,
96  int option = 0 );
97 
98  static bool getLocalArrayBounds(const intArray & u, const intSerialArray & uLocal,
99  Index & I1, Index & I2, Index & I3,
100  int option = 0 );
101 
102  // Build v, a copy of the array u that lives on the processors defined by the Range P
103  static int redistribute(const intArray & u, intArray & v, const Range & P);
104  static int redistribute(const floatArray & u, floatArray & v, const Range & P);
105  static int redistribute(const doubleArray & u, doubleArray & v, const Range & P);
106 
107  // Build v, a copy of the array u that lives on the local processor
108  static int redistribute( const intArray & u, intSerialArray & v );
109  static int redistribute( const floatArray & u, floatSerialArray & v );
110  static int redistribute( const doubleArray & u, doubleSerialArray & v );
111 
112 };
113 
114 
115 
117 
118 class IndexBox
119 {
120 public:
121 IndexBox();
122 IndexBox(int i1a, int i1b, int i2a=0, int i2b=0, int i3a=0, int i3b=0, int i4a=0, int i4b=0);
123 ~IndexBox();
124 
125 inline int base(int d) const {return ab[d][0];} //
126 inline int bound(int d) const {return ab[d][1];} //
127 // return the total size: (number of elements in the array)
128 int size() const;
129 
130 inline int bb(int side, int d) const {return ab[d][side];} //
131 
132 void setBounds(int i1a, int i1b, int i2a=0, int i2b=0, int i3a=0, int i3b=0, int i4a=0, int i4b=0);
133 
134 static bool intersect(const IndexBox & a, const IndexBox & b, IndexBox & c);
135 
136 bool isEmpty() const;
137 
138 int processor; // processor number associated with this IndexBox
139 
140 protected:
141  int ab[MAX_DISTRIBUTED_DIMENSIONS][2]; // base and bounds
142 
143 };
144 
145 typedef std::vector<IndexBox> ListOfIndexBox;
146 
148 {
149 public:
150 
151 // copy functions to copy distributed array to local arrays (generalized P++ copy)
152 static int copyArray( const floatDistributedArray & u,
153  Index *Iv,
154  IndexBox *vBox, // bounds of v on each processor, vBox[p] p=0,1,..,numProc-1
155  floatSerialArray & vLocal );
156 static int copyArray( const doubleDistributedArray & u,
157  Index *Iv,
158  IndexBox *vBox, // bounds of v on each processor, vBox[p] p=0,1,..,numProc-1
159  doubleSerialArray & vLocal );
160 static int copyArray( const intDistributedArray & u,
161  Index *Iv,
162  IndexBox *vBox, // bounds of v on each processor, vBox[p] p=0,1,..,numProc-1
163  intSerialArray & vLocal );
164 
165 // copy functions to replace P++ distributed to distributed copies
166 static int copyArray( floatArray & dest, Index *D,
167  const floatArray & src, Index *S, int nd=4 );
168 static int copyArray( doubleArray & dest, Index *D,
169  const doubleArray & src, Index *S, int nd=4 );
170 static int copyArray( intArray & dest, Index *D,
171  const intArray & src, Index *S, int nd=4 );
172 
173 
174 // copy serial arrays uLocal into a distributed array, v (generalized P++ copy)
175 static int copyArray( const floatSerialArray & uLocal,
176  const Index *Jv,
177  const intSerialArray & uProcessorSet,
179  const Index *Iv );
180 static int copyArray( const doubleSerialArray & uLocal,
181  const Index *Jv,
182  const intSerialArray & uProcessorSet,
184  const Index *Iv );
185 static int copyArray( const intSerialArray & uLocal,
186  const Index *Jv,
187  const intSerialArray & uProcessorSet,
188  intDistributedArray & v,
189  const Index *Iv );
190 
191 // copy a serial array from one processor to another:
192 static int copyArray( floatSerialArray & dest, int destProcessor, floatSerialArray & src, int srcProcessor );
193 static int copyArray( doubleSerialArray & dest, int destProcessor, doubleSerialArray & src, int srcProcessor );
194 static int copyArray( intSerialArray & dest, int destProcessor, intSerialArray & src, int srcProcessor );
195 
196 
197 static void getLocalArrayInterval(const floatDistributedArray & u, int p, int *pv);
198 static void getLocalArrayInterval(const doubleDistributedArray & u, int p, int *pv);
199 static void getLocalArrayInterval(const intDistributedArray & u, int p, int *pv);
200 
201 // get local array bounds (no ghost points):
202 static bool getLocalArrayBox( int p, const floatDistributedArray & u, IndexBox & uBox );
203 static bool getLocalArrayBox( int p, const doubleDistributedArray & u, IndexBox & uBox );
204 static bool getLocalArrayBox( int p, const intDistributedArray & u, IndexBox & uBox );
205 
206 // get local array bounds including ghost points:
207 static bool getLocalArrayBoxWithGhost( int p, const floatDistributedArray & u, IndexBox & uBox );
208 static bool getLocalArrayBoxWithGhost( int p, const doubleDistributedArray & u, IndexBox & uBox );
209 static bool getLocalArrayBoxWithGhost( int p, const intDistributedArray & u, IndexBox & uBox );
210 
211 
212 static void copyCoarseToFine( const floatArray & uc, const floatArray & uf, Index *Iv,
213  floatSerialArray & uc2, int *ratio, int *ghost);
214 
215 static void copyCoarseToFine( const doubleArray & uc, const doubleArray & uf, Index *Iv,
216  doubleSerialArray & uc2, int *ratio, int *ghost);
217 
218 static void copyCoarseToFine( const intArray & uc, const intArray & uf, Index *Iv,
219  intSerialArray & uc2, int *ratio, int *ghost);
220 
221 
222 static void getAggregateArray( floatSerialArray & u, Index *Iv, floatSerialArray & u0, int p0);
223 static void getAggregateArray( doubleSerialArray & u, Index *Iv, doubleSerialArray & u0, int p0);
224 static void getAggregateArray( intSerialArray & u, Index *Iv, intSerialArray & u0, int p0);
225 
226 static int debug;
227 
228 };
229 
230 #endif