Hitmap 1.3
 All Data Structures Namespaces Files Functions Variables Typedefs Friends Macros Groups Pages
hit_utils.h
Go to the documentation of this file.
1 
13 /*
14  * <license>
15  *
16  * Hitmap v1.2
17  *
18  * This software is provided to enhance knowledge and encourage progress in the scientific
19  * community. It should be used only for research and educational purposes. Any reproduction
20  * or use for commercial purpose, public redistribution, in source or binary forms, with or
21  * without modifications, is NOT ALLOWED without the previous authorization of the copyright
22  * holder. The origin of this software must not be misrepresented; you must not claim that you
23  * wrote the original software. If you use this software for any purpose (e.g. publication),
24  * a reference to the software package and the authors must be included.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND ANY
27  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
29  * THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *
36  * Copyright (c) 2007-2015, Trasgo Group, Universidad de Valladolid.
37  * All rights reserved.
38  *
39  * More information on http://trasgo.infor.uva.es/
40  *
41  * </license>
42 */
43 
44 #ifndef _HitUtils_
45 #define _HitUtils_
46 
51 #define hit_clockSynchronize(lay) MPI_Barrier((lay).topo.pTopology->comm)
52 
55 #define hit_clockSynchronizeAll() MPI_Barrier( MPI_COMM_WORLD );
56 
60 typedef struct {
61  int state;
62  double seconds;
63  double min;
64  double max;
65  double avg;
66  double buffer;
67 } HitClock;
68 
70 #define HIT_CLOCK_RUNNING 0
71 
72 #define HIT_CLOCK_STOPPED 1
73 
78 #define hit_clockReset(c) { \
79  c.seconds = 0.0; \
80  c.state = HIT_CLOCK_STOPPED; \
81  }
82 
87 #define hit_clockStart(c) { \
88  c.seconds= MPI_Wtime(); \
89  c.state = HIT_CLOCK_RUNNING; \
90  }
91 
98 #define hit_clockMaxReduce(topo, c) { \
99  MPI_Reduce( &c.seconds, &c.buffer, 1, MPI_DOUBLE, \
100  MPI_MAX, 0, (topo).pTopology->comm ); \
101  c.seconds = c.buffer; \
102  }
103 
109 #define hit_clockStop(c) { \
110  c.seconds= MPI_Wtime() - c.seconds; \
111  c.state = HIT_CLOCK_STOPPED; \
112  }
113 
114 
115 
121 #define hit_clockContinue(c) { \
122  c.seconds = MPI_Wtime() - c.seconds; \
123  c.state = HIT_CLOCK_RUNNING; \
124  }
125 
130 #define hit_clockIsRunning(c) ( c.state == HIT_CLOCK_RUNNING )
131 
132 
139 #define hit_clockReduce(lay, c) { \
140  MPI_Reduce( &c.seconds, &c.buffer, 1, MPI_DOUBLE, \
141  MPI_MAX, 0, (lay).pTopology[0]->comm ); \
142  c.max = c.buffer; \
143  MPI_Reduce( &c.seconds, &c.buffer, 1, MPI_DOUBLE, \
144  MPI_MIN, 0, (lay).pTopology[0]->comm ); \
145  c.min = c.buffer; \
146  MPI_Reduce( &c.seconds, &c.buffer, 1, MPI_DOUBLE, \
147  MPI_SUM, 0, (lay).pTopology[0]->comm ); \
148  c.avg = c.buffer / hit_layNumActives( lay ); \
149  }
150 
151 /*
152 * All processors make a reduction to get the maximun, minimum and average
153 * time of their respective clock. Processor number 0 gets the reduced times
154 * @param c clock
155 */
156 #define hit_clockWorldReduce(c) { \
157  MPI_Reduce( &c.seconds, &c.buffer, 1, MPI_DOUBLE, \
158  MPI_MAX, 0, MPI_COMM_WORLD ); \
159  c.max = c.buffer; \
160  MPI_Reduce( &c.seconds, &c.buffer, 1, MPI_DOUBLE, \
161  MPI_MIN, 0, MPI_COMM_WORLD ); \
162  c.min = c.buffer; \
163  MPI_Reduce( &c.seconds, &c.buffer, 1, MPI_DOUBLE, \
164  MPI_SUM, 0, MPI_COMM_WORLD ); \
165  c.avg = c.buffer / hit_NProcs; \
166  }
167 
172 #define hit_clockPrint(c) { \
173  if (hit_Rank==0) printf("HitClock_%s: %14.6lf\n", #c, c.seconds); \
174  }
175 #define hit_clockPrintMax(c) { \
176  if (hit_Rank==0) printf("HitClock_%s Max: %14.6lf\n", #c, c.max); \
177  }
178 #define hit_clockPrintMin(c) { \
179  if (hit_Rank==0) printf("HitClock_%s Min: %14.6lf\n", #c, c.min); \
180  }
181 #define hit_clockPrintAvg(c) { \
182  if (hit_Rank==0) printf("HitClock_%s Avg: %14.6lf\n", #c, c.avg); \
183  }
184 
185 
190 #define hit_clockGetSeconds(c) (c.seconds)
191 #define hit_clockGetMaxSeconds(c) (c.max)
192 #define hit_clockGetMinSeconds(c) (c.min)
193 #define hit_clockGetAvgSeconds(c) (c.avg)
194 
195 
196 
197 
201 typedef struct {
202  int value;
203  int min;
204  int max;
205  int sum;
206  int avg;
207  int buffer;
208 } HitCounter;
209 
214 #define hit_counterValue(c) ((c).value)
215 
220 #define hit_counterReset(c) (c).value = 0
221 
227 #define hit_counterAdd(c,value) (c).value += (value)
228 
233 #define hit_counterInc(c) (c).value++
234 
239 #define hit_counterDec(c) (c).value--
240 
241 
248 #define hit_counterReduce(lay, c) { \
249  MPI_Reduce( &c.value, &c.buffer, 1, MPI_INT, \
250  MPI_MAX, 0, (lay).pTopology[0]->comm ); \
251  c.max = c.buffer; \
252  MPI_Reduce( &c.value, &c.buffer, 1, MPI_INT, \
253  MPI_MIN, 0, (lay).pTopology[0]->comm ); \
254  c.min = c.buffer; \
255  MPI_Reduce( &c.value, &c.buffer, 1, MPI_INT, \
256  MPI_SUM, 0, (lay).pTopology[0]->comm ); \
257  c.sum = c.buffer; \
258  c.avg = c.buffer / hit_layNumActives( lay ); \
259  }
260 
261 /*
262 * All processors make a reduction to get the maximun, minimum and average
263 * value of their respective counter. Processor number 0 gets the reduced values
264 * @param c counter
265 */
266 #define hit_counterWorldReduce(c) { \
267  MPI_Reduce( &c.value, &c.buffer, 1, MPI_INT, \
268  MPI_MAX, 0, MPI_COMM_WORLD ); \
269  c.max = c.buffer; \
270  MPI_Reduce( &c.value, &c.buffer, 1, MPI_INT, \
271  MPI_MIN, 0, MPI_COMM_WORLD ); \
272  c.min = c.buffer; \
273  MPI_Reduce( &c.value, &c.buffer, 1, MPI_INT, \
274  MPI_SUM, 0, MPI_COMM_WORLD ); \
275  c.sum = c.buffer; \
276  c.avg = c.buffer / hit_NProcs; \
277  }
278 
283 #define hit_counterPrint(c) { \
284  if (hit_Rank==0) printf("HitCounter_%s: %010d\n", #c, c.value); \
285  }
286 #define hit_counterPrintMax(c) { \
287  if (hit_Rank==0) printf("HitCounter_%s Max: %010d\n", #c, c.max); \
288  }
289 #define hit_counterPrintMin(c) { \
290  if (hit_Rank==0) printf("HitCounter_%s Min: %010d\n", #c, c.min); \
291  }
292 #define hit_counterPrintSum(c) { \
293  if (hit_Rank==0) printf("HitCounter_%s Sum: %010d\n", #c, c.sum); \
294  }
295 #define hit_counterPrintAvg(c) { \
296  if (hit_Rank==0) printf("HitCounter_%s Avg: %010d\n", #c, c.avg); \
297  }
298 
299 
304 #define hit_counterMax(c) (c.max)
305 #define hit_counterMin(c) (c.min)
306 #define hit_counterSum(c) (c.sum)
307 #define hit_counterAvg(c) (c.avg)
308 
309 /* END OF HEADER FILE _HitUtils_ */
310 #endif
int buffer
Definition: hit_utils.h:207
double max
Definition: hit_utils.h:64
int state
Definition: hit_utils.h:61
double avg
Definition: hit_utils.h:65
double seconds
Definition: hit_utils.h:62
double buffer
Definition: hit_utils.h:66
double min
Definition: hit_utils.h:63