Hitmap 1.3
 All Data Structures Namespaces Files Functions Variables Typedefs Friends Macros Groups Pages
hit_tile.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 _HitTile_
49 #define _HitTile_
50 
51 #include "hit_tileP.h"
52 
53 #ifdef __cplusplus
54  extern "C" {
55 #endif
56 
57 /* 1. ABSTRACT DATA-STRUCTURE DEFINITION */
58 
59 /* 1.a. GENERIC ABSTRACT TYPES */
60 
147 typedef struct HitTile HitTile;
148 
163 #define hit_tileNewType(baseType) hit_tileNewTypeInternal(baseType)
164 
174 #define HIT_FILE_INT 0
175 
179 #define HIT_FILE_LONG 1
180 
184 #define HIT_FILE_FLOAT 2
185 
189 #define HIT_FILE_DOUBLE 3
190 
191 /* 2.c.4. MODES FOR POSITION OF THE TILES IN THE FILE: COORDINATE SYSTEM */
196 #define HIT_FILE_TILE 0
197 
201 #define HIT_FILE_ARRAY 1
202 
203 /* 2.d. CONSTANTS FOR ALLOCATING VERTICES AND/OR EDGES IS SPARSE STRUCTURES */
208 #define HIT_VERTICES 1
209 
214 #define HIT_EDGES 2
215 
220 #define HIT_VERTICES_EDGES (HIT_VERTICES | HIT_EDGES)
221 
225 /* 3. NULL VARIABLES */
229 extern HitTile HIT_TILE_NULL;
230 
241 #define hit_tileIsNull(var) ((var).memStatus==HIT_MS_NULL)
242 
248 /* 4. VARIABLE MANAGEMENT */
249 /* 4.a. CREATE A TILE OVER A SINGLE VARIABLE OF ANY TYPE */
266 #define hit_tileSingle( tile, var, type ) hit_tileSingleInternal( tile, &var, sizeof( type ) )
267 
268 /* 4.b. DECLARING VARIABLES WITHOUT MEMORY YET: ARRAY */
286 #define hit_tileDomain( newVarP, baseType, numDims, ...) hit_tileDomainInternal( newVarP, sizeof(baseType), 0==strncmp("HitTile",#baseType,7), numDims, __VA_ARGS__)
287 
304 #define hit_tileDomainShape( newVarP, baseType, shape ) hit_tileDomainShapeInternal( newVarP, sizeof(baseType), 0==strncmp("HitTile",#baseType,7), shape )
305 
306 
307 /* 4.c. INITIALIZING VARIABLES: ARRAY */
319 #define hit_tileAlloc( var ) hit_tileAllocInternal( var, #var, __FILE__, __LINE__);
320 
336 #define hit_tileDomainAlloc(newVarP, baseType, numDims, ...) \
337  hit_tileDomainInternal(newVarP, sizeof(baseType), 0==strncmp("HitTile",#baseType,7), numDims, __VA_ARGS__); \
338  hit_tileAllocInternal( newVarP, #newVarP, __FILE__, __LINE__);
339 
354 #define hit_tileDomainShapeAlloc(newVarP, baseType, shape) \
355  hit_tileDomainShapeInternal(newVarP, sizeof(baseType), 0==strncmp("HitTile",#baseType,7), shape); \
356  hit_tileAllocInternal( newVarP, #newVarP, __FILE__, __LINE__);
357 
358 /* 4.e. FREE VARIABLE (FREE INTERNAL DATA BUFFER) */
369 #define hit_tileFree(var) { \
370  if ( (var).hierDepth ) { \
371  hit_tileFreeRecInternal(&(var)); \
372  } \
373  if ((var).memStatus==HIT_MS_OWNER) {\
374  free((var).memPtr); (var).memPtr=NULL; (var).data=NULL; (var).memStatus=HIT_MS_NOMEM;\
375  } \
376 }
377 
390 #define hit_tileFill( var, value ) hit_tileFillInternal( var, value, #var, __FILE__, __LINE__);
391 
392 /* 4.f. DUPLICATE A WHOLE VARIABLE WITH ITS MEMORY AND DATA */
404 #define hit_tileClone( newVar, oldVar ) hit_tileCloneInternal(newVar, oldVar, #oldVar, __FILE__, __LINE__)
405 
409 /* 4.g. SELECTIONS */
410 
416 /* 4.g.1. SELECTING FROM VARIABLES TO RETURN ANOTHER VARIABLE (LOCAL COORDINATES) */
434 #define hit_tileSelectNoBoundary( newVar, oldVar, shape ) \
435  hit_tileSelectInternal( newVar, oldVar, shape, HIT_NO_OUTOFBOUNDS_CHECK )
436 
453 #define hit_tileSelect( newVar, oldVar, shape ) \
454  hit_tileSelectInternal( newVar, oldVar, shape, HIT_OUTOFBOUNDS_CHECK )
455 
456 
457 /* 4.g.2. SELECTING FROM VARIABLES TO RETURN ANOTHER VARIABLE (GLOBAL COORDINATES) */
475 #define hit_tileSelectArrayCoordsNoBoundary( newVar, oldVar, shape ) \
476  hit_tileSelectArrayCoordsInternal( newVar, oldVar, shape, HIT_NO_OUTOFBOUNDS_CHECK )
477 
494 #define hit_tileSelectArrayCoords( newVar, oldVar, shape ) \
495  hit_tileSelectArrayCoordsInternal( newVar, oldVar, shape, HIT_OUTOFBOUNDS_CHECK )
496 
505 /* 8.8. INTERNAL: MACROS TO OBTAIN THE POSITION OF AN ELEMENT */
506 /* 8.8.1. TILE COORDINATES */
519 #define hit_tileElemAt(var,ndims,...) hit_tileElemAt##ndims(var,__VA_ARGS__)
520 
521 /* 8.8.2. ARRAY COORDINATES */
534 #define hit_tileElemAtArrayCoords(var,ndims,...) hit_tileElemAtArrayCoords##ndims(var,__VA_ARGS__)
535 
536 /* 8.8.3. TILE COORDINATES IN TILES WITH NO STRIDE */
558 #define hit_tileElemAtNoStride(var,ndims,...) hit_tileElemAtNoStride##ndims(var,__VA_ARGS__)
559 
568 /* 8.4. LOOPS FOR TRAVERSING COORDINATE SPACES */
576 #define hit_tileForDimDomainArray(tile, dim, index) for( index=hit_tileDimBegin(tile, dim); \
577  index<=hit_tileDimEnd(tile,dim); \
578  index=index+hit_tileDimStride(tile,dim) )
579 
587 #define hit_tileForDimDomain(tile, dim, index) for( index=0; \
588  index<hit_tileDimCard(tile,dim); \
589  index++ )
590 
599 /* 5. SHADOW COPY */
600 /* 5.a. UPDATE VALUES IN SHADOW COPY */
613 #define hit_tileUpdateToAncestor( shadow ) hit_tileUpdateFromToAncestorInternal( shadow, HIT_UPDATE_TO, #shadow, __FILE__, __LINE__ );
614 
627 #define hit_tileUpdateFromAncestor( shadow ) hit_tileUpdateFromToAncestorInternal( shadow, HIT_UPDATE_FROM, #shadow, __FILE__, __LINE__ );
628 
661 int hit_tileReduceDims(void *newVar, int numReductions);
662 
663 /* 7. MERGE/FUSION OF TILES WITH A TOUCHING BOUNDARY WITH THE SAME GEOMETRY */
664 /* GLUE TILES WITH TOUCHING BOUNDARIES OF THE SAME GEOMETRY */
687 void hit_tileGlue( void *tileInA, void *tileInB, void *tileOut );
688 
694 /*
695 * 8. Hit MACROS FOR ACCESING THE VARIABLES
696 */
697 
698 
704 /* 8.1. BASIC SHAPE DATA */
713 #define hit_tileDims(var) (hit_shapeDims((var).shape))
714 
723 #define hit_tileShape(var) ((var).shape)
724 
734 HitShape hit_tileShapeLocal( const void *inTile );
735 
736 
737 /* 8.2. CARDINALITIES OF A GIVEN DIMENSION */
738 /* 8.2.1. CARDINALITY OF A GIVEN DIMENSION */
750 #define hit_tileDimCard(var,dim) ((var).card[dim])
751 
752 /* 8.2.2. CARDINALITY OF THE WHOLE DOMAIN */
763 #define hit_tileCard(var) ((var).acumCard)
764 
765 
766 /* 8.3. SIGNATURE OF A GIVEN DIMENSION */
776 #define hit_tileDimSig(var,dim) (hit_shapeSig(hit_tileShape((var)),dim))
777 
786 #define hit_tileDimBegin(var,dim) (hit_tileDimSig(var,dim).begin)
787 
796 #define hit_tileDimEnd(var,dim) (hit_tileDimSig(var,dim).end)
797 
806 #define hit_tileDimStride(var,dim) (hit_tileDimSig(var,dim).stride)
807 
816 #define hit_tileDimLast(var,dim) (hit_tileDimCard(var,dim)-1)
817 
825 /* 8.10. CHECK IF ARRAY COORDINATES INDEX IS IN TILE */
836 #define hit_tileDimHasArrayCoord(var, dim, pos) \
837  ( pos>=hit_tileDimBegin(var,dim) && (pos<=hit_tileDimEnd(var,dim)) && \
838  ((pos-hit_tileDimBegin(var,dim))%hit_tileDimStride(var,dim) == 0) )
839 
850 #define hit_tileHasArrayCoords(var, ndims, ...) hit_tileHasArrayCoords##ndims(var, __VA_ARGS__)
851 
852 
853 /* 8.9. TRANSFORM COORDINATES: TILE TO ARRAY, ARRAY TO TILE */
864 #define hit_tileTile2Array(var, dim, pos) ((pos)*hit_tileDimStride(var,dim) + hit_tileDimBegin(var,dim))
865 
875 #define hit_tileArray2Tile(var, dim, pos) (((pos)-hit_tileDimBegin(var,dim))/ hit_tileDimStride(var,dim))
876 
885 
894 
905 static inline HitTile * hit_tileRoot( void * tileP ) {
906  HitTile *tile = (HitTile *)tileP;
907  while( tile->ref != NULL ) tile = tile->ref;
908  return tile;
909 }
910 
947 #define hit_tileFileWrite( var, file, coord ) \
948  hit_tileFileInternal( var, HIT_FILE_BINARY, HIT_FILE_WRITE, coord, HIT_FILE_UNKNOWN, 0, 0, file, #var, __FILE__, __LINE__)
949 
974 #define hit_tileFileRead( var, file, coord ) \
975  hit_tileFileInternal( var, HIT_FILE_BINARY, HIT_FILE_READ, coord, HIT_FILE_UNKNOWN, 0, 0, file, #var, __FILE__, __LINE__)
976 
977 
1011 #define hit_tileTextFileWrite( var, file, coord, datatype, s1, s2 ) \
1012  hit_tileFileInternal( var, HIT_FILE_TEXT, HIT_FILE_WRITE, coord, datatype, s1, s2, file, #var, __FILE__, __LINE__)
1013 
1045 #define hit_tileTextFileRead( var, file, coord, datatype, s1, s2 ) \
1046  hit_tileFileInternal( var, HIT_FILE_TEXT, HIT_FILE_READ, coord, datatype, s1, s2, file, #var, __FILE__, __LINE__)
1047 
1050 #ifdef __cplusplus
1051  }
1052 #endif
1053 
1054 /* END OF HEADER FILE _HitTile_ */
1055 #endif
int hit_tileReduceDims(void *newVar, int numReductions)
Definition: hit_tile.c:1296
void hit_tileGlue(void *tileInA, void *tileInB, void *tileOut)
Definition: hit_tile.c:1698
HitShape hit_tileShapeTile2Array(void *var, HitShape sh)
Definition: hit_tile.c:1622
HitShape hit_tileShapeArray2Tile(void *var, HitShape sh)
Definition: hit_tile.c:1640
HitShape hit_tileShapeLocal(const void *inTile)
Definition: hit_tile.c:1608
HitTile HIT_TILE_NULL
Definition: hit_tile.c:63