Hitmap 1.3
 All Data Structures Namespaces Files Functions Variables Typedefs Friends Macros Groups Pages
layWeighted.c
Go to the documentation of this file.
1 /*
2  * This file is intended as a demonstation of weighted layouts and layout groups.
3  * @author Eduardo Rodriguez Gutiez
4  * @version 0.01, 04/23/2016
5  */
6 
7 #include <stdio.h>
8 #include "hitmap.h"
9 
10 hit_tileNewType(int);
11 
12 
13 void printHitTile(HitLayout globalLayout, HitTile_int aTile)
14 {
15  int i;
16 
17  if (hit_layImActive(globalLayout))
18  {
19  printf("--------- Data for process %i ---------\n", hit_Rank);
20  printf("[%i:%i:%i (%i)]", hit_tileDimBegin(aTile, 0), hit_tileDimEnd(aTile, 0),
21  hit_tileDimStride(aTile, 0), hit_tileDimCard(aTile, 0));
22  for(i = 0; i < hit_tileDimCard(aTile, 0); i++)
23  printf("%i ", hit_tileElemAt(aTile, 1, i));
24  printf("\n");
25  fflush(stdout);
26  hit_comBarrier(globalLayout);
27  }
28 }
29 
30 char hit_layCmp(HitLayout lay1, HitLayout lay2){
31 
32  return (lay1.type == lay2.type) && (lay1.active == lay2.active) && (lay1.group == lay2.group) &&
33  (lay1.leader == lay2.leader) && (hit_ranksCmp(lay1.leaderRanks,lay2.leaderRanks));
34 
35 }
36 
38 
39 }
40 
41 int main(int argc, char* argv[])
42 {
43 
44  //https://www.infor.uva.es/~eduardo/blog/index.php/2016/05/09/debugging-mpi-programs-with-gdb/
45  /*int iax = 0;
46  char hostname[256];
47  gethostname(hostname, sizeof(hostname));
48  printf("PID %d on %s ready for attach\n", getpid(), hostname);
49  fflush(stdout);
50  while (0 == iax)
51  sleep(5);*/
52 
53  hit_comInit( &argc, &argv );
54 
55  HitTile_int globalTile, myTile;
56  HitShape globalShape, myShape;
57  HitShape myDimWeightedShape, myDimDummyWeightedShape, myWeightedShape;
58  HitLayout globalLayout, dimWeightedLayout, dimDummyWeightedLayout, weightedLayout;
59  HitTopology globalTopology, dummyTopology;
60  int i;
61  //float weights[20] = {1,5,8,4,2,9,7,2,7,0,8,4,5,8,7,5,1,8,3,7};
62  float weights[4] = {2,2,4,2};//Normalizar con hitNProcs
63  //float weights[hit_NProcs] = {2,2,4,2};//Normalizar con hitNProcs
64 
65  if (argc < 2)
66  {
67  printf("Usage: %s <cells>\n^[[31mCells argument mising.^[[0m\n", argv[0]);
68  return -1;
69  }
70  int cells = atoi(argv[1]);
71 
72  hit_tileDomain(&globalTile, int, 1, cells);
73  globalTopology = hit_topology(plug_topPlain);
74  int dummyProcElems[1] = {4};
75  dummyTopology = hit_topology(plug_topDummyDims, 1, dummyProcElems);
76  globalShape = hit_tileShape(globalTile);
77  //globalLayout = hit_layout(plug_layBlocks, globalTopology, globalShape);
78 
79  //activesTopology = hit_layActivesTopology(globalLayout);
80  //globalLayout = hit_layout(plug_layContiguous, globalTopology, globalShape, weights);
81  //dimWeightedLayout = hit_layout(plug_layDimWeighted, activesTopology, globalShape, restrictDim, weights);
82  int restrictDim = 0;
83  dimWeightedLayout = hit_layout(plug_layDimWeighted, globalTopology, globalShape, restrictDim, weights);
84  dimDummyWeightedLayout = hit_layout(plug_layDimWeighted, dummyTopology, globalShape, restrictDim, weights);
85  if (hit_layCmp(dimDummyWeightedLayout, HIT_LAYOUT_NULL))
86  printf("El resultado de aplicar layDimWeighted a topDummyDims es null");
87 
88  //dimWeightedLayout = hit_layout(plug_layBlocks, globalTopology, globalShape);
89  //weightedLayout = hit_layout(plug_layWeighted, activesTopology, globalShape, weights);
90  //dimWeightedLayout = hit_layout(plug_layWeighted, globalTopology, globalShape, weights);
91 
92  printf("[%i:%i:%i (%i)]", hit_tileDimBegin(globalTile, 0), hit_tileDimEnd(globalTile, 0),
93  hit_tileDimStride(globalTile, 0), hit_tileDimCard(globalTile, 0));
94 
95  myDimWeightedShape = hit_layShape(dimWeightedLayout);
96 
97  HitSig aSig;
98  int j;
99  for (j = 0; j < 4; j++){
100  //myDimDummyWeightedShape = hit_layShape(dimDummyWeightedLayout);
101  myDimDummyWeightedShape = hit_layShapeNeighbor(dimDummyWeightedLayout, 0, j); //j = shift
102  printf("\n%i dimension, virtual_rank %i",hit_shapeDims(myDimDummyWeightedShape), j);
103  for (i = 0; i < hit_shapeDims(myDimDummyWeightedShape); i++){
104  aSig = hit_shapeSig(myDimDummyWeightedShape, i);
105  printf("[%i:%i:%i (%i)]", aSig.begin, aSig.end, aSig.stride, hit_sigCard(aSig));
106  }
107  }
108  printf("\n");
109 
110  //myWeightedShape = hit_layShape(weightedLayout);
111  hit_tileSelect(&myTile, &globalTile, myDimWeightedShape);
112  //hit_tileSelect(&myTile, &globalTile, myweightedShape);
113  hit_tileAlloc(&myTile);
114 
115  /*myShape = hit_layShape(groupLayouts[hit_Rank]);
116  hit_tileSelect(&myTile, &globalTile, myShape);
117  hit_tileAlloc(&myTile);*/
118 
119  //Fill the array with some values (e.g. its local indexes)
120  for(i = 0; i < hit_tileDimCard(myTile, 0); i++)
121  hit_tileElemAt(myTile, 1, i) = i;
122  printHitTile(dimWeightedLayout, myTile);
123  //printHitTile(weightedLayout, myTile);
124  if(hit_layImActive(dimWeightedLayout))
125  hit_comBarrier(dimWeightedLayout);
126  /*if(hit_layImActive(weightedLayout))
127  hit_comBarrier(weightedLayout);*/
128 
129  //printf("Hola"); fflush(stdout);
130  hit_tileFree(myTile);
131  hit_shapeFree(myDimWeightedShape);
132  //hit_shapeFree(myWeightedShape);
133  hit_layFree(dimWeightedLayout);
134  //hit_layFree(weightedLayout);
135  //hit_layFree(globalLayout);
136  //XXX: ESTA TOPOLOGIA NO SE PUEDE LIBERAR PORQUE ES NULL hit_topFree(dummyTopology);
137  hit_topFree(globalTopology);
138  hit_comFinalize();
139  return 0;
140 }
HitLayout HIT_LAYOUT_NULL
Definition: hit_layout.c:71
#define hit_layShape(lay)
Definition: hit_layout.h:650
#define hit_tileDimStride(var, dim)
Definition: hit_tile.h:806
#define hit_tileNewType(baseType)
Definition: hit_tile.h:163
HitRanks leaderRanks
Definition: hit_layout.h:268
#define hit_Rank
Definition: hit_com.h:140
#define hit_tileElemAt(var, ndims,...)
Definition: hit_tile.h:519
#define hit_tileAlloc(var)
Definition: hit_tile.h:319
#define hit_topology(name,...)
Definition: hit_topology.h:308
#define hit_sigCard(sig)
Definition: hit_sig.h:162
Definition: hit_sig.h:79
#define hit_ranksCmp(a, b)
Definition: hit_topology.h:220
#define hit_layShapeNeighbor(lay, dim, shift)
Definition: hit_layout.h:727
#define hit_tileSelect(newVar, oldVar, shape)
Definition: hit_tile.h:453
int begin
Definition: hit_sig.h:80
char leader
Definition: hit_layout.h:267
#define hit_tileDimCard(var, dim)
Definition: hit_tile.h:750
#define hit_shapeDims(shape)
Definition: hit_sshape.h:364
#define hit_tileDimBegin(var, dim)
Definition: hit_tile.h:786
void hit_topFree(HitTopology topo)
Definition: hit_topology.c:129
int end
Definition: hit_sig.h:81
void hit_layPrint(HitLayout lay)
Definition: layWeighted.c:37
void hit_comInit(int *pargc, char **pargv[])
Definition: hit_com.c:111
#define hit_layImActive(lay)
Definition: hit_layout.h:797
#define hit_tileDomain(newVarP, baseType, numDims,...)
Definition: hit_tile.h:286
#define hit_tileDimEnd(var, dim)
Definition: hit_tile.h:796
void hit_layFree(HitLayout lay)
Definition: hit_layout.c:2251
int main(int argc, char *argv[])
Definition: cannonAsync.c:62
int stride
Definition: hit_sig.h:82
#define hit_comBarrier(lay)
Definition: hit_com.h:1027
#define hit_layout(name, topo,...)
Definition: hit_layout.h:415
int active
Definition: hit_layout.h:263
HitLayout lay
Definition: heat.c:107
#define hit_shapeSig(shape, dim)
Definition: hit_sshape.h:400
void printHitTile(HitLayout globalLayout, HitTile_int aTile)
Definition: layWeighted.c:13
#define hit_tileFree(var)
Definition: hit_tile.h:369
void hit_shapeFree(HitShape s)
Definition: hit_shape.c:84
#define hit_tileShape(var)
Definition: hit_tile.h:723
void hit_comFinalize()
Definition: hit_com.c:159
char hit_layCmp(HitLayout lay1, HitLayout lay2)
Definition: layWeighted.c:30