Hitmap 1.3
 All Data Structures Namespaces Files Functions Variables Typedefs Friends Macros Groups Pages
hit_topology.h
Go to the documentation of this file.
1 
17 /*
18  * <license>
19  *
20  * Hitmap v1.2
21  *
22  * This software is provided to enhance knowledge and encourage progress in the scientific
23  * community. It should be used only for research and educational purposes. Any reproduction
24  * or use for commercial purpose, public redistribution, in source or binary forms, with or
25  * without modifications, is NOT ALLOWED without the previous authorization of the copyright
26  * holder. The origin of this software must not be misrepresented; you must not claim that you
27  * wrote the original software. If you use this software for any purpose (e.g. publication),
28  * a reference to the software package and the authors must be included.
29  *
30  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND ANY
31  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
32  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
33  * THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
34  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  *
40  * Copyright (c) 2007-2015, Trasgo Group, Universidad de Valladolid.
41  * All rights reserved.
42  *
43  * More information on http://trasgo.infor.uva.es/
44  *
45  * </license>
46 */
47 
48 #ifndef _HitTopology_
49 #define _HitTopology_
50 
51 #include <stdio.h>
52 
53 #include "hit_shape.h"
54 #include "hit_error.h"
55 #include "hit_mpi.h"
56 
57 #ifdef __cplusplus
58  extern "C" {
59 #endif
60 
61 /* 1. PHYSICAL TOPOLOGY */
62 /* CURRENTLY, ONLY HOMOGENEOUS SYSTEM SUPPORT */
63 
64 /* 1.1. PHYSICAL TOPOLOGY DATA STRUCTURE */
65 // @cond INTERNAL
69 typedef struct HitPTopology {
70  int numUses;
71  int numProcs;
72  int selfRank;
73  MPI_Comm comm;
74  struct HitPTopology *next;
75  // @arturo 2015/01/07 New fields (Redistribute functionalities)
76  struct HitPTopology *global;
77  MPI_Group antiCommGroup;
78 } HitPTopology;
79 
80 
81 /* 1.2. Hit PHYSICAL TOPOLOGY GLOBAL VARIABLE */
85 extern HitPTopology *HIT_TOPOLOGY_INFO;
86 
87 /* 1.3. Hit PHYSICAL TOPOLOGY NULL CONSTANTS */
91 extern HitPTopology HIT_PTOPOLOGY_NULL;
92 
93 // @arturo 2015/01/03 Add constant for new fields
95 #define HIT_PTOPOLOGY_NULL_STATIC { 0,0,0, MPI_COMM_NULL, NULL, NULL, MPI_GROUP_EMPTY }
96 
97 /* 1.4. Hit PHYSICAL TOPOLOGY COMPARATORS */
102 #define hit_ptopoCmp(a,b) ((a)->comm == (b)->comm)
103 
107 #define hit_ptopoIsNull(a) ((a)->comm == MPI_COMM_NULL)
108 
109 /* 1.5. SPLIT PHYSICAL TOPOLOGY */
113 HitPTopology *hit_ptopSplit( HitPTopology *in, int group );
114 
115 /* 1.6. DUPLICATE A PTOPOLOGY OBJECT */
119 HitPTopology *hit_ptopDup( HitPTopology *in );
120 
121 /* 1.7. FREE A PTOPOLOGY OBJECT */
125 void hit_ptopFree( HitPTopology **in );
126 // @endcond
127 
128 
129 /* 2. RANKS IN MULTIDIMENSIONAL GRID */
130 /* 2.1. STRUCTURE */
134 typedef struct HitRanks {
136 } HitRanks;
137 
138 /* 2.2. HitRank NULL VALUE */
142 extern int HIT_RANK_NULL;
144 #define HIT_RANK_NULL_STATIC -1
145 
146 /* 2.3 HitRanks NULL VALUE*/
152 extern HitRanks HIT_RANKS_NULL;
154 #define HIT_RANKS_NULL_STATIC { { HIT_RANK_NULL_STATIC, HIT_RANK_NULL_STATIC, HIT_RANK_NULL_STATIC, HIT_RANK_NULL_STATIC } }
155 
160 
161 
162 /* 2.4. HitRanks CONSTRUCTOR FUNCTIONS */
169 #define hit_ranks( numDims, ... ) hit_ranks##numDims( __VA_ARGS__ )
170 
176 static inline HitRanks hit_ranks1( int r1 ) {
177  HitRanks res = { { r1, HIT_RANK_NULL_STATIC, HIT_RANK_NULL_STATIC, HIT_RANK_NULL_STATIC } };
178  return res;
179 }
186 static inline HitRanks hit_ranks2( int r1, int r2 ) {
187  HitRanks res = { { r1, r2, HIT_RANK_NULL_STATIC, HIT_RANK_NULL_STATIC } };
188  return res;
189 }
197 static inline HitRanks hit_ranks3( int r1, int r2, int r3 ) {
198  HitRanks res = { { r1, r2, r3, HIT_RANK_NULL_STATIC } };
199  return res;
200 }
209 static inline HitRanks hit_ranks4( int r1, int r2, int r3, int r4 ) {
210  HitRanks res = { { r1, r2, r3, r4 } };
211  return res;
212 }
213 
214 /* 2.4. HitRanks COMPARE */
220 #define hit_ranksCmp(a,b) ((a).rank[0] == (b).rank[0] && (a).rank[1] == (b).rank[1] && (a).rank[2] == (b).rank[2] && (a).rank[3] == (b).rank[3])
221 
222 /* 2.5. HitRanks DIMENSION COORDINATE */
228 #define hit_ranksDim( ranks, dim ) (ranks.rank[dim])
229 
230 
231 
232 
233 
234 /* 3. Hit ARRAY VIRTUAL TOPOLOGY */
235 /* CURRENTLY: ONLY MULTI-DIMENSIONAL GRID TOPOLOGIES */
236 
237 /* 3.1. TOPOLOGY DATA STRUCTURE */
243 typedef struct HitTopology {
244  int type;
245  int numDims;
247  // @arturo 2015/01/22
248  //int periods[HIT_MAXDIMS]; /**< Periodic dimension flag. (TODO: DEPRECATED) */
249  HitRanks self;
250  // @arturo 2015/01/22
251  //int linearRank; /**< Linear rank for the current processor. */
252  int active;
253  HitPTopology *pTopology;
254 } HitTopology;
255 
256 
257 // Hit TOPOLOGY TYPES
261 #define HIT_TOPOLOGY_PLAIN 1
262 
266 #define HIT_TOPOLOGY_SQUARE 2
267 
271 #define HIT_TOPOLOGY_ARRAY2DCOMP 3
272 
276 #define HIT_TOPOLOGY_ARRAYDIMS 4
277 
281 #define HIT_TOPOLOGY_DUMMYDIMS 5
282 
283 
287 #define HIT_TOPOLOGY_PLAIN_POWER2 10
288 
289 
290 /* 3.2. Hit TOPOLOGY NULL VALUE */
295 
296 // @arturo 2015/01/22
298 #define HIT_TOPOLOGY_NULL_STATIC {0, 0, { 0, 0, 0, 0 }, { { -1, -1, -1, -1} }, 0, NULL }
299 
300 /* 3.3. Hit TOPOLOGY GENERATION */
308 #define hit_topology( name, ... ) hit_topology_##name(HIT_TOPOLOGY_INFO, ##__VA_ARGS__ )
309 
310 /* 3.4. Hit PREDEFINED TOPOLOGY FUNCTIONS */
311 
312 /* 3.4.1 Hit PLAIN TOPOLOGY */
319 HitTopology hit_topology_plug_topPlain( HitPTopology *topo );
320 
321 /* 3.4.1 Hit PLAIN TOPOLOGY */
328 HitTopology hit_topology_plug_topPlainPower2( HitPTopology *topo );
329 
330 /* 3.4.1 Hit SQUARE TOPOLOGY */
337 HitTopology hit_topology_plug_topSquare( HitPTopology *topo );
338 
339 /* 3.4.1 Hit COMPLETE 2D ARRAY TOPOLOGY */
349 
350 /* 3.4.1 Hit X-D ARRAY TOPOLOGY */
361 HitTopology hit_topology_plug_topArrayDims( HitPTopology *topo , int dims );
362 
363 /* 3.4.1 Hit X-D DUMMY ARRAY TOPOLOGY */
364 HitTopology hit_topology_plug_topDummyDims( HitPTopology *topo, int dims, int* virprocelems );
365 
374 #define hit_topology_plug_topArray2D(topo) hit_topology_plug_topArrayDims(topo, 2);
375 
384 #define hit_topology_plug_topArray3D(topo) hit_topology_plug_topArrayDims(topo, 3);
385 
394 #define hit_topology_plug_topArray4D(topo) hit_topology_plug_topArrayDims(topo, 4);
395 
396 /* 3.5. Hit ACCESS TO TOPOLOGY INFORMATION */
397 /* 3.5.1. ACTIVE */
401 #define hit_topSelfActive(topo) (topo.active)
402 
403 /* 3.5.2. NUM DIMENSIONS */
407 #define hit_topDims(topo) (topo.numDims)
408 
409 /* 3.5.3. CARDINALITY OF A DIMENSION */
413 #define hit_topDimCard(topo, i) (topo.card[i])
414 
415 /* 3.5.4. TOPOLOGY CARDINALITY */
419 int hit_topCard(HitTopology topo);
420 
421 /* 3.5.5. SELF RANK */
425 #define hit_topRanks(topo) (topo.self)
426 
427 /* 3.5.6. SELF COORDITATES */
431 #define hit_topDimRank(topo, i) (topo.self.rank[i])
432 
433 /* 3.5.7. SELF RANK IN LINEAR FORM */
437 // @arturo 2015/01/22
438 //#define hit_topSelfRankInternal(topo) (topo.linearRank)
439 #define hit_topSelfRankInternal(topo) ( (topo).pTopology->selfRank )
440 
441 /* 3.6 FREE TOPOLOGY METHOD */
445 void hit_topFree( HitTopology topo );
446 
447 /* 3.7. COMPUTE NEIGHBORS */
451 int hit_topDimNeighbor(HitTopology topo, int dim, int shift );
452 
453 /* 3.8. CONVERSIONS OF RANKS */
454 /* 3.8.1 MULTIDIMENSIONAL RANKS TO LINEAL */
458 int hit_topRankInternal(HitTopology topo, HitRanks ranks );
459 
460 /* 3.8.2 LINEAL TO MULTIDIMENSIONAL RANKS */
464 HitRanks hit_topRanksInternal( HitTopology topo, int linealRank );
465 
466 /* 3.9 LOOPs and IFs SHORTCUTS */
467 /* 3.9.1. LOOPS ACROSS VIRTUAL PROCESSORS */
471 #define hit_topDimForeach(topo, dim, index) for( index=0; index<topo.card[dim]; index++)
472 
473 /* 3.9.2 CHECK IF THE LOCAL PROCESSOR IS ACTIVATED
474  * USED TO DO SOMETHING ONLY FOR ACTIVATED PROCESSORS IN THE TOPOLOGY */
478 #define hit_topImActive( topo ) ((topo).active)
479 
480 /* 3.9.3 CHECK IF THE LOCAL PROCESSOR IS THE LEADER (rank 0) */
484 // @arturo 2015/01/22
485 //#define hit_topImLeader( topo ) ((topo).linearRank==0)
486 #define hit_topImLeader( topo ) ((topo).pTopology->selfRank == 0 )
487 
488 
492 #define hit_topInactiveWarning( topo ) \
493  if ( hit_topImLeader(topo) ) { \
494  int numInactive = HIT_TOPOLOGY_INFO.numProcs - hit_topCard( topo ); \
495  if ( numInactive > 0 ) { \
496  char message[256]; \
497  sprintf( message, "%d Processors inactive in topology \"%s\"", numInactive, #topo); \
498  hit_warning( message, __FILE__, __LINE__ ); \
499  } \
500  }
501 
502 #ifdef __cplusplus
503 }
504 #endif
505 
506 /* END OF HEADER FILE _HitTopology_ */
507 #endif
HitTopology hit_topology_plug_topSquare(HitPTopology *topo)
Definition: hit_topology.c:176
HitPTopology HIT_PTOPOLOGY_NULL
Definition: hit_topology.c:63
HitTopology hit_topology_plug_topPlainPower2(HitPTopology *topo)
Definition: hit_topology.c:156
HitRanks HIT_RANKS_LEADER
HitPTopology * hit_ptopSplit(HitPTopology *in, int group)
Definition: hit_topology.c:80
int hit_topRankInternal(HitTopology topo, HitRanks ranks)
Definition: hit_topology.c:415
int rank[HIT_MAXDIMS]
Definition: hit_topology.h:135
HitPTopology * pTopology
Definition: hit_topology.h:253
HitPTopology * HIT_TOPOLOGY_INFO
Definition: hit_topology.c:60
struct HitRanks HitRanks
HitTopology hit_topology_plug_topDummyDims(HitPTopology *topo, int dims, int *virprocelems)
Definition: hit_topology.c:319
#define HIT_RANK_NULL_STATIC
Definition: hit_topology.h:144
HitRanks HIT_RANKS_NULL
Definition: hit_topology.c:68
#define HIT_MAXDIMS
Definition: hit_shape.h:72
int HIT_RANK_NULL
Definition: hit_topology.c:67
HitPTopology * hit_ptopDup(HitPTopology *in)
Definition: hit_topology.c:74
int dims[2]
Definition: SWpar_ref.c:187
MPI_Comm comm
Definition: SWpar_ref.c:193
HitRanks hit_topRanksInternal(HitTopology topo, int linealRank)
Definition: hit_topology.c:438
void hit_topFree(HitTopology topo)
Definition: hit_topology.c:129
HitTopology hit_topology_plug_topPlain(HitPTopology *topo)
Definition: hit_topology.c:139
void hit_ptopFree(HitPTopology **in)
Definition: hit_topology.c:109
HitTopology hit_topology_plug_topArrayDims(HitPTopology *topo, int dims)
Definition: hit_topology.c:249
int card[HIT_MAXDIMS]
Definition: hit_topology.h:246
int hit_topDimNeighbor(HitTopology topo, int dim, int shift)
Definition: hit_topology.c:376
int hit_topCard(HitTopology topo)
Definition: hit_topology.c:361
struct HitTopology HitTopology
HitTopology hit_topology_plug_topArray2DComplete(HitPTopology *topo)
Definition: hit_topology.c:207
HitTopology HIT_TOPOLOGY_NULL
Definition: hit_topology.c:64