Hitmap 1.3
 All Data Structures Namespaces Files Functions Variables Typedefs Friends Macros Groups Pages
hit_mctile.c
Go to the documentation of this file.
1 
2 /*
3  * <license>
4  *
5  * Hitmap v1.2
6  *
7  * This software is provided to enhance knowledge and encourage progress in the scientific
8  * community. It should be used only for research and educational purposes. Any reproduction
9  * or use for commercial purpose, public redistribution, in source or binary forms, with or
10  * without modifications, is NOT ALLOWED without the previous authorization of the copyright
11  * holder. The origin of this software must not be misrepresented; you must not claim that you
12  * wrote the original software. If you use this software for any purpose (e.g. publication),
13  * a reference to the software package and the authors must be included.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
18  * THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  * Copyright (c) 2007-2015, Trasgo Group, Universidad de Valladolid.
26  * All rights reserved.
27  *
28  * More information on http://trasgo.infor.uva.es/
29  *
30  * </license>
31 */
32 
33 #include <hit_mctile.h>
34 #include <hit_cshape.h>
35 #include <hit_allocP.h>
36 
37 
38 
39 void hit_mcTileDomainShapeInternal(void * newVarP, size_t baseExtent, HitShape shape) {
40 
41  HitPTile newVar = (HitPTile)newVarP;
42  *newVar = HIT_TILE_NULL;
43 
44  // 1. Num of dimensions, Mark no memory status, and Null pointers.
45  newVar->shape = shape;
46  newVar->baseExtent = baseExtent;
47  newVar->memStatus = HIT_MS_NOMEM;
48  newVar->hierDepth = (char) HIT_NONHIERARCHICAL;
49  newVar->ref = NULL;
50  newVar->data = NULL;
51  newVar->memPtr = NULL;
52  newVar->type = HIT_MC_TILE;
53 
54 
55  // 2. Process Vertices and Edges cardinalities.
56  if(hit_cShapeNvertices(shape) > 0)
57  newVar->card[0] = hit_cShapeNZElems(shape);
58  //newVar->card[1] = hit_cShapeCard(shape,1);
59 
60 
61 }
62 
63 
64 void hit_mcTileAllocInternal(void *newVarP, const char *name, const char *file, int numLine) {
65 
66  HitPTile newVar = (HitPTile)newVarP;
67 
68  // 0. Skip alloc when Null.
69  if ( newVar->memStatus == HIT_MS_NULL) return;
70 
71  // 1. Check variable type, cannot have already its own memory.
72  if ( newVar->memStatus == HIT_MS_OWNER ){
73  hit_errInternal(__FUNCTION__,"Trying to reallocate a Tile: ",name,file,numLine);
74  }
75 
76  // 3. Allocate memory.
77  if(newVar->card[0] != 0){
78  // @arturo Ago 2015: New allocP interface
79  // hit_malloc(newVar->memPtr,(size_t)newVar->card[0] * newVar->baseExtent,void*);
80  hit_vmalloc(newVar->memPtr, (size_t)newVar->card[0] * newVar->baseExtent );
81  newVar->data = newVar->memPtr;
82  }
83 
84  // 4. Change memory status.
85  newVar->memStatus = HIT_MS_OWNER;
86 }
87 
88 
89 
90 int hit_mcTileElemAtIndex(void * varP, int row, int column){
91 
92  /* 1. Get the shape of the tile */
93  HitTile *var = (HitTile *)varP;
95 
96  int column_i;
97  hit_cShapeColumnIterator(column_i,shape,row){
98  int dst = hit_cShapeEdgeTarget(shape,column_i);
99  if(dst == column) return column_i;
100  }
101 
102  return -1;
103 }
104 
105 
106 int hit_mcTileGraphElemAtIndex(void * varP, int pos1, int pos2){
107 
108  /* 1. Get the shape of the tile */
109  HitTile *var = (HitTile *)varP;
110  HitShape shape = hit_tileShape(*var);
111 
112  int row = hit_cShapeCoordToLocal(shape,0,pos1);
113  int column = hit_cShapeCoordToLocal(shape,1,pos2);
114 
115  int column_i;
116  hit_cShapeColumnIterator(column_i,shape,row){
117 
118  int dst = hit_cShapeEdgeTarget(shape,column_i);
119  if(dst == column){
120  return column_i;
121  }
122  }
123  return -1;
124 }
125 
126 
127 
128 
129 void hit_mcTileClear(void * tileP){
130 
131  /* 1. Get the shape of the tile */
132  HitTile *tile = (HitTile *)tileP;
133  HitShape shape = hit_tileShape(*tile);
134  int nz = hit_cShapeNZElems(shape);
135 
136  bzero(tile->data, tile->baseExtent * (size_t) nz);
137 
138 }
139 
140 
141 
142 
143 
144 
#define hit_cShapeCoordToLocal(s, dim, elem)
Definition: hit_cshape.h:263
#define hit_cShapeEdgeTarget(s, edge)
#define hit_cShapeColumnIterator(var, shape, row)
Definition: hit_cshape.h:403
void hit_mcTileDomainShapeInternal(void *newVarP, size_t baseExtent, HitShape shape)
Definition: hit_mctile.c:39
#define hit_cShapeNvertices(shape)
Hitmap functions to allocate memory.
#define hit_cShapeNZElems(shape)
Definition: hit_cshape.h:126
int hit_mcTileGraphElemAtIndex(void *varP, int pos1, int pos2)
Definition: hit_mbtile.c:99
HitShape shape
int hit_mcTileElemAtIndex(void *varP, int local1, int local2)
Definition: hit_mbtile.c:86
#define hit_vmalloc(ptr, size)
Definition: hit_allocP.h:72
HitTile HIT_TILE_NULL
Definition: hit_tile.c:63
void hit_mcTileAllocInternal(void *newVarP, const char *name, const char *file, int numLine)
Definition: hit_mctile.c:64
void hit_mcTileClear(void *tileP)
Definition: hit_mctile.c:129
#define hit_errInternal(routine, text, extraParam, file, numLine)
Definition: hit_error.h:63
#define hit_tileShape(var)
Definition: hit_tile.h:723