Hitmap 1.3
 All Data Structures Namespaces Files Functions Variables Typedefs Friends Macros Groups Pages
hit_tileP.h
Go to the documentation of this file.
1 // @cond INTERNAL
15 // @endcond
16 
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 _HitTileP_
49 #define _HitTileP_
50 
51 #include <stdio.h>
52 #include <string.h>
53 #include <stdarg.h>
54 #include <sys/types.h>
55 #include <sys/stat.h>
56 #include <fcntl.h>
57 
58 #include "hit_error.h"
59 #include "hit_shape.h"
60 #include "hit_bshape.h"
61 
62 
63 #ifdef __cplusplus
64  extern "C" {
65 #endif
66 
67 /* 0. TYPE CONSTANTS */
68 // @cond INTERNAL
69 #define HIT_TILE 0
70 #define HIT_C_TILE 1
71 #define HIT_M_TILE 2
72 #define HIT_GC_TILE 3
73 #define HIT_GB_TILE 4
74 #define HIT_MC_TILE 5
75 #define HIT_MB_TILE 6
76 // @endcond
77 
78 
79 /* 1. ABSTRACT DATA-STRUCTURE DEFINITION */
80 
81 // TODO: created by ismael @ 2017-12-19 16:41:29
82 // Add stream member to structure for cudaStream_t at GPU controllers
83 /* 1.a. GENERIC ABSTRACT TYPE */
84 typedef struct HitTile {
86  int type;
87  size_t baseExtent;
88  HitShape shape;
89  int card[HIT_MAXDIMS];
90  int acumCard;
91  int origAcumCard[HIT_MAXDIMS+1];
92  int qstride[HIT_MAXDIMS];
93  void *data;
94  void *dataVertices;
95  void *memPtr;
96  void *memPtrVertices;
97  struct HitTile *ref;
98  char memStatus;
99 /* ------------------------ CONTROLERS ---------------------------------------- */
100  void *refCntrl;
101  void *devData;
102  char inCntrlType;
103  char transferred;
104  char recover;
105  void *handler;
106  int hasPendingMoveTo;
107  int hasPendingMoveFrom;
108  int isCntrlBlocked;
109  unsigned int cntrlKernelCount;
110 /* ------------------------ MULTILEVEL TILES ---------------------------------------- */
111  char hierDepth;
112  struct HitTile *ancestor;
113  struct HitTile *unpadded;
114  int childBegin[HIT_MAXDIMS];
115  int childSize[HIT_MAXDIMS];
116 } HitTile ;
117 
118 // @cond INTERNAL
122 typedef HitTile *HitPTile;
123 
124 // TODO: created by ismael @ 2017-12-19 16:40:50
125 // Add stream member to structure for cudaStream_t at GPU controllers
138  #define hit_tileNewTypeInternal(baseType) \
139  typedef struct HitTile_##baseType { \
140  int type; \
141  size_t baseExtent; \
142  HitShape shape; \
143  int card[HIT_MAXDIMS]; \
144  int acumCard; \
145  int origAcumCard[HIT_MAXDIMS+1]; \
146  int qstride[HIT_MAXDIMS]; \
147  baseType *data; \
148  baseType *dataVertices; \
149  baseType *memPtr; \
150  baseType *memPtrVertices; \
151  struct HitTile_##baseType *ref; \
152  char memStatus; \
153  void *refCntrl; \
154  baseType *devData; \
155  char inCntrlType; \
156  char transferred; \
157  char recover; \
158  void *handler; \
159  int hasPendingMoveTo; \
160  int hasPendingMoveFrom; \
161  int isCntrlBlocked; \
162  unsigned int cntrlKernelCount; \
163  char hierDepth; \
164  struct HitTile *ancestor; \
165  struct HitTile *unpadded; \
166  int childBegin[HIT_MAXDIMS]; \
167  int childSize[HIT_MAXDIMS]; \
168  } HitTile_##baseType, *HitPTile_##baseType
169 
170 /* Declare the type for the hierarchical Tiles */
171 hit_tileNewTypeInternal(HitTile);
172 
173 /* 2.a CONSTANTS FOR MEMORY STATUS FIELD */
177 #define HIT_MS_NULL 0
178 #define HIT_MS_NOMEM 1
179 #define HIT_MS_OWNER 2
180 #define HIT_MS_NOT_OWNER 3
182 /* 2b.1. CONSTANTS FOR HIERARCHICAL DEPTH FIELD */
183 
186 #define HIT_NONHIERARCHICAL 0
188 /* 2b.2. CONSTANTS FOR MULTILEVEL CARDINALITIES */
189 #define HIT_MULTILEVEL_UNDEFINED_SIZES { 1, 1, 1, 1 }
190 #define HIT_MULTILEVEL_UNDEFINED_BEGINS { 0, 0, 0, 0 }
191 
192 /* 2c. CONSTANTS FOR READING/WRITING TILES IN FILES */
193 /* 2.c.1. FILE FORMAT: BINARY vs. TEXT */
195 #define HIT_FILE_BINARY 0
196 
197 #define HIT_FILE_TEXT 1
198 
199 /* 2.c.2. MODE OF FILE OPERATIONS */
200 #define HIT_FILE_READ 0
201 #define HIT_FILE_WRITE 1
202 
203 /* 2.c.3. TEXT FILES: ELEMENTS TYPE */
204 #define HIT_FILE_UNKNOWN -1
205 
206 /* 2d. CONSTANTS FOR MODE IN DATA UPDATE FROM/TO PARENT TILE */
207 #define HIT_UPDATE_FROM 0
208 #define HIT_UPDATE_TO 1
209 
210 /* 4.g. SELECTIONS */
212 #define HIT_OUTOFBOUNDS_CHECK 0
213 
214 #define HIT_NO_OUTOFBOUNDS_CHECK 1
215 
216 
217 // TODO: created by ismael @ 2017-12-19 16:40:12
218 // Add initialization for stream member as NULL
222 extern HitPTile HIT_TILE_NULL_POINTER;
223 //#define HIT_TILE_NULL_STATIC { 0, 0, HIT_SHAPE_NULL_STATIC, { 0,0,0,0 }, 0, { 0,0,0,0,0 }, { 0,0,0,0 }, NULL, NULL, NULL, NULL, NULL, HIT_MS_NULL, HIT_NONHIERARCHICAL, NULL, NULL, HIT_MULTILEVEL_UNDEFINED_BEGINS, HIT_MULTILEVEL_UNDEFINED_SIZES }
224 #define HIT_TILE_NULL_STATIC { 0, 0, HIT_SHAPE_NULL_STATIC, { 0,0,0,0 }, 0, { 0,0,0,0,0 }, { 0,0,0,0 }, NULL, NULL, NULL, NULL, NULL, HIT_MS_NULL, NULL, NULL, 0, 0, 0, NULL, 0, 0, 0, 0, HIT_NONHIERARCHICAL, NULL, NULL, HIT_MULTILEVEL_UNDEFINED_BEGINS, HIT_MULTILEVEL_UNDEFINED_SIZES }
225 
238 #define hit_tileClass(tile) ((tile).type)
239 
240 
241 /* PROTOTYPES OF INTERNAL FUNCTIONS */
242 
250 int hit_tileCheckBoundaryTileCoords(const void *tileP, HitShape sh);
251 
259 int hit_tileCheckBoundaryArrayCoords(const void *tileP, HitShape sh);
260 
261 /* @arturo apr 2016 */
262 void hit_tileSingleInternal( void *tileP, void *var, size_t size );
263 void hit_tileDomainInternal(void *newVarP, size_t baseExtent, int hierDepth, int numDims, ...);
264 void hit_tileDomainShapeInternal(void *newVarP, size_t baseExtent, int hierDepth, HitShape shape);
265 void hit_tileAllocInternal(void *newVarP, const char *name, const char *file, int numLine);
266 void hit_tileFreeRecInternal(void * var);
267 void hit_tileFillInternal(void * var, void * value, const char *name, const char *file, int numLine);
268 void hit_tileCloneInternal(void *newVar, const void *oldVar, const char *name, const char *file, int numLine);
269 void hit_tileUpdateFromToAncestorInternal(void *shadow, int fromTo, const char *name, const char *file, int numLine);
270 
271 // FILE OPERATIONS
272 int hit_tileFileInternal( void * varP, const int fileFormat, const int fileMode, const int tileMode, const int type, const int formatSize1, const int formatSize2, const char *fileName, const char *debugVarName, const char *debugCodeFile, int debugCodeNumLine);
273 
287 int hit_tileSelectInternal(void *newVar, const void *oldVar, HitShape sh, int out);
288 
302 int hit_tileSelectArrayCoordsInternal(void *newVar, const void *oldVar, HitShape sh, int out);
303 
304 // @endcond
305 
306 // @cond OLD
307 /* 6. SELECTING IFOUT OF BOUNDS (Deprecated v1.0) */
308 /* AVOID EVALUATION OF THE SECOND ARGUMENT IF POSSIBLE */
309 /* GLOBAL TEMPORAL VARIABLE */
310 #define hit_tileSelectOut(select1,select2) { if (!select1) select2; }
311 // @endcond
312 
313 
314 /* 8.5. ACCESS DATA ELEMENTS WITH TILE COORDINATES */
315 // @cond OLD
323 #define hit_tileGet(var,ndims,...) hit_tileElemAt(var,ndims,__VA_ARGS__)
324 
332 #define hit_tileSet(var,ndims,val,...) hit_tileElemAt(var,ndims,__VA_ARGS__) = (val)
333 
334 /* 8.6. ACCESS DATA ELEMENTS WITH ARRAY COORDINATES */
342 #define hit_tileGetArrayCoords(var,ndims,...) hit_tileElemAtArrayCoords(var,ndims,__VA_ARGS__)
343 
351 #define hit_tileSetArrayCoords(var,ndims,val,...) hit_tileElemAtArrayCoords(var,ndims,__VA_ARGS__) = (val)
352 
353 
354 /* 8.7. ACCESS DATA ELEMENTS WITH TILE COORDINATES IN TILES WITH NO STRIDE */
362 #define hit_tileGetNoStride(var,ndims,...) hit_tileElemAtNoStride(var,ndims,__VA_ARGS__)
363 
371 #define hit_tileSetNoStride(var,ndims,val,...) hit_tileElemAtNoStride(var,ndims,__VA_ARGS__) = (val)
372 // @endcond
373 
374 /* 8.8. INTERNAL: MACROS TO OBTAIN THE POSITION OF AN ELEMENT */
375 // @cond INTERNAL
376 /* 8.8.1. TILE COORDINATES */
377 #define hit_tileElemAt1(var, pos) ((var).data[(pos)*(var).qstride[0]])
378 
379 #define hit_tileElemAt2(var, pos1, pos2) ((var).data[(pos1)*(var).qstride[0]*(var).origAcumCard[1]+(pos2)*(var).qstride[1]])
380 
381 #define hit_tileElemAt3(var, pos1, pos2, pos3) ((var).data[(pos1)*(var).qstride[0]*(var).origAcumCard[1]+(pos2)*(var).qstride[1]*(var).origAcumCard[2]+(pos3)*(var).qstride[2]])
382 
383 #define hit_tileElemAt4(var, pos1, pos2, pos3, pos4) ((var).data[(pos1)*(var).qstride[0]*(var).origAcumCard[1]+(pos2)*(var).qstride[1]*(var).origAcumCard[2]+(pos3)*(var).qstride[2]*(var).origAcumCard[3]+(pos4)*(var).qstride[3]])
384 
385 /* 8.8.2. ARRAY COORDINATES */
386 #define hit_tileElemAtArrayCoords1(var, pos) ((var).data[ hit_tileArray2Tile(var,0,pos) ])
387 
388 #define hit_tileElemAtArrayCoords2(var, pos1, pos2) ((var).data[ hit_tileArray2Tile((var),0,(pos1))*(var).origAcumCard[1] + hit_tileArray2Tile((var), 1, (pos2))])
389 
390 #define hit_tileElemAtArrayCoords3(var, pos1, pos2, pos3) ((var).data[ hit_tileArray2Tile((var),0,(pos1))*(var).origAcumCard[1] + hit_tileArray2Tile((var), 1, (pos2))*(var).origAcumCard[2] + hit_tileArray2Tile((var), 2, (pos3))])
391 
392 #define hit_tileElemAtArrayCoords4(var, pos1, pos2, pos3, pos4) ((var).data[ hit_tileArray2Tile((var),0,(pos1))*(var).origAcumCard[1] + hit_tileArray2Tile((var), 1, (pos2))*(var).origAcumCard[2] + hit_tileArray2Tile((var), 2, (pos3))*(var).origAcumCard[3] + hit_tileArray2Tile((var), 3, (pos3))])
393 
394 /* 8.8.3. TILE COORDINATES IN TILES WITH NO STRIDE */
395 #define hit_tileElemAtNoStride1(var, pos) ((var).data[pos])
396 
397 #define hit_tileElemAtNoStride2(var, pos1, pos2) ((var).data[(pos1)*(var).origAcumCard[1]+(pos2)])
398 
399 #define hit_tileElemAtNoStride3(var, pos1, pos2, pos3) ((var).data[(pos1)*(var).origAcumCard[1]+(pos2)*(var).origAcumCard[2]+(pos3)])
400 
401 #define hit_tileElemAtNoStride4(var, pos1, pos2, pos3, pos4) ((var).data[(pos1)*(var).origAcumCard[1]+(pos2)*(var).origAcumCard[2]+(pos3)*(var).origAcumCard[3]+(pos4)])
402 
403 
404 /* 8.10. CHECK IF ARRAY COORDINATES INDEX IS IN TILE */
405 #define hit_tileHasArrayCoords1(var, pos) \
406  ( pos>=hit_tileDimBegin(var,0) && (pos<=hit_tileDimEnd(var,0)) && \
407  ((pos-hit_tileDimBegin(var,0))%hit_tileDimStride(var,0) == 0) )
408 
409 #define hit_tileHasArrayCoords2(var, pos0, pos1) \
410  ( pos0>=hit_tileDimBegin(var,0) && (pos0<=hit_tileDimEnd(var,0)) && \
411  pos1>=hit_tileDimBegin(var,1) && (pos1<=hit_tileDimEnd(var,1)) && \
412  ((pos0-hit_tileDimBegin(var,0))%hit_tileDimStride(var,0) == 0) && \
413  ((pos1-hit_tileDimBegin(var,1))%hit_tileDimStride(var,1) == 0) )
414 
415 #define hit_tileHasArrayCoords3(var, pos0, pos1, pos2) \
416  ( pos0>=hit_tileDimBegin(var,0) && (pos0<=hit_tileDimEnd(var,0)) && \
417  pos1>=hit_tileDimBegin(var,1) && (pos1<=hit_tileDimEnd(var,1)) && \
418  pos2>=hit_tileDimBegin(var,2) && (pos2<=hit_tileDimEnd(var,2)) && \
419  ((pos0-hit_tileDimBegin(var,0))%hit_tileDimStride(var,0) == 0) && \
420  ((pos1-hit_tileDimBegin(var,1))%hit_tileDimStride(var,1) == 0) && \
421  ((pos2-hit_tileDimBegin(var,2))%hit_tileDimStride(var,2) == 0) )
422 
423 #define hit_tileHasArrayCoords4(var, pos0, pos1, pos2, pos3) \
424  ( pos0>=hit_tileDimBegin(var,0) && (pos0<=hit_tileDimEnd(var,0)) && \
425  pos1>=hit_tileDimBegin(var,1) && (pos1<=hit_tileDimEnd(var,1)) && \
426  pos2>=hit_tileDimBegin(var,2) && (pos2<=hit_tileDimEnd(var,2)) && \
427  pos3>=hit_tileDimBegin(var,3) && (pos3<=hit_tileDimEnd(var,3)) && \
428  ((pos0-hit_tileDimBegin(var,0))%hit_tileDimStride(var,0) == 0) && \
429  ((pos1-hit_tileDimBegin(var,1))%hit_tileDimStride(var,1) == 0) && \
430  ((pos2-hit_tileDimBegin(var,2))%hit_tileDimStride(var,2) == 0) && \
431  ((pos3-hit_tileDimBegin(var,3))%hit_tileDimStride(var,3) == 0) )
432 
433 // @endcond
434 
435 #ifdef __cplusplus
436  }
437 #endif
438 
439 
440 /* END OF HEADER FILE _HitTile_ */
441 #endif
HitPTile HIT_TILE_NULL_POINTER
Definition: hit_tile.c:64
int hit_tileFileInternal(void *varP, const int fileFormat, const int fileMode, const int tileMode, const int type, const int formatSize1, const int formatSize2, const char *fileName, const char *debugVarName, const char *debugCodeFile, int debugCodeLine)
Definition: hit_tile.c:572
void hit_tileSingleInternal(void *tileP, void *varP, size_t size)
Definition: hit_tile.c:135
void hit_tileDomainShapeInternal(void *newVarP, size_t baseExtent, int hierDepth, HitShape shape)
Definition: hit_tile.c:200
int hit_tileCheckBoundaryArrayCoords(const void *tileP, HitShape sh)
Definition: hit_tile.c:1073
void hit_tileFillInternal(void *varP, void *value, const char *name, const char *file, int numLine)
Definition: hit_tile.c:342
#define HIT_MAXDIMS
Definition: hit_shape.h:72
void hit_tileDomainInternal(void *newVarP, size_t baseExtent, int hierDepth, int numDims,...)
Definition: hit_tile.c:162
struct HitTile HitTile
Definition: hit_tile.h:147
int hit_tileSelectInternal(void *newVarP, const void *oldVarP, HitShape sh, int out)
Definition: hit_tile.c:942
void hit_tileCloneInternal(void *newVarP, const void *oldVarP, const char *name, const char *file, int numLine)
Definition: hit_tile.c:819
int size[2]
Definition: SWcommon.c:57
int hit_tileCheckBoundaryTileCoords(const void *tileP, HitShape sh)
Definition: hit_tile.c:1095
void hit_tileUpdateFromToAncestorInternal(void *sh, int fromTo, const char *name, const char *file, int numLine)
Definition: hit_tile.c:1371
HitShape shape
void hit_tileAllocInternal(void *newVarP, const char *name, const char *file, int numLine)
Definition: hit_tile.c:243
int hit_tileSelectArrayCoordsInternal(void *newVarP, const void *oldVarP, HitShape sh, int out)
Definition: hit_tile.c:1116
void hit_tileFreeRecInternal(void *varP)
Definition: hit_tile.c:1658