OpenAtom  Version1.5a
pcBuilder.C
1 #include "pcBuilder.h"
2 #include "pcMaps.h"
3 #include "utility/MapFile.h"
4 #include "ckPairCalculator.decl.h"
5 #include "InputDataHandler.h"
6 
7 #include "ckmulticast.h"
8 
9 extern Config config;
10 /*
11  * @addtogroup PairCalculator
12  * @{
13  */
14 
15 namespace cp {
16  namespace paircalc {
17 
19 {
20  traceRegisterUserEvent("calcpairDGEMM", 210);
21  traceRegisterUserEvent("calcpairContrib", 220);
22  traceRegisterUserEvent("multiplyResultDGEMM1", 230);
23  traceRegisterUserEvent("multiplyResultDGEMM2", 240);
24  traceRegisterUserEvent("multiplyResultDGEMM1R", 250);
25 
26  createMap(mapCfg);
28 
29  pcHandle.mCastMgrGID = CProxy_CkMulticastMgr::ckNew(cfg.inputSpanningTreeFactor);
30 
31  #ifdef USE_COMLIB
32  // Setup the appropriate multicast strategy
33  Strategy *multistrat = new DirectMulticastStrategy();
34  if(cfg.isSymmetric)
35  mcastInstanceCP=ComlibRegister(multistrat);
36  else
37  mcastInstanceACP=ComlibRegister(multistrat);
38  #endif
39 
40  return pcHandle;
41 }
42 
43 
44 /// Hacky way to allow PC builders of each instance to access the maptable for instance 0 pc
45 namespace impl { MapType4 *dirtyGlobalMapTable4PCsym, *dirtyGlobalMapTable4PCasym; }
46 
47 /**
48  * Create the map for placing the paircalculator chare array elements. Also perform other housekeeping chores like dumping the maps to files etc.
49  */
51 {
52  bool maptype = cfg.isSymmetric;
53  int achunks = config.numChunksAsym;
55  { // evil trickery to use asym map code for phantom sym
56  maptype=false;
57  achunks=config.numChunksSym;
58  }
59 
60  MapType4 **inst0MapTable = cfg.isSymmetric ? &impl::dirtyGlobalMapTable4PCsym : &impl::dirtyGlobalMapTable4PCasym;
61  // Generate a map name
62  std::string mapName = cfg.isSymmetric ? "SymScalcMap" : "AsymScalcMap";
63  /// Get an appropriately constructed PeList from the supplied factory functor
64  PeList *availGlobG = mapCfg.getPeList();
65  availGlobG->reset();
66 
67  // Compute num PEs along the states dimension of GSpace
68  int pl = cfg.numStates / config.Gstates_per_pe;
69  // Compute num PEs along the planes dimension of GSpace
70  int pm = config.numPesPerInstance / pl;
71  // Compute the num of GSpace planes per PE
72  int planes_per_pe = cfg.numPlanes / pm;
73 
74  int size[4];
75  size[0] = cfg.numPlanes;
76  size[1] = cfg.numStates/cfg.grainSize;
77  size[2] = cfg.numStates/cfg.grainSize;
78  size[3] = achunks;
79  //-------------------------------------------------------------
80  // Populate maptable for the PC array
81 
82  // Start timing the map creation
83  double mapCreationTime = CmiWallTimer();
84 
85  MapType4 mapTable;
86  if (cfg.instanceIndex == 0)
87  {
88  mapTable.buildMap(cfg.numPlanes, cfg.numStates/cfg.grainSize, cfg.numStates/cfg.grainSize, achunks, cfg.grainSize);
89 
90  int success = 0;
91  if(config.loadMapFiles)
92  {
93  MapFile *mf = new MapFile(mapName.c_str(), 4, size, config.numPes, "TXYZ", 2, 1, 1, 1, cfg.grainSize);
94  success = mf->loadMap(mapName.c_str(), &mapTable);
95  delete mf;
96  }
97 
98  // If loading the map from a file failed, create a maptable
99  if(success == 0)
100  {
101  SCalcMapTable symTable = SCalcMapTable(&mapTable, availGlobG, cfg.numStates, cfg.numPlanes, cfg.grainSize, maptype, config.scalc_per_plane,
102  planes_per_pe, achunks, config.numChunksSym, mapCfg.gSpaceMap, config.useCuboidMap, config.useCentroidMap, mapCfg.boxSize);
103  }
104 
105  // Save a globally visible handle to the mapTable that builders of other PC instances can access
106  *inst0MapTable = new MapType4(mapTable);
107  }
108  // else, this is not the first instance. Simply translate the 0th instance
109  else
110  {
111  int x = mapCfg.mapOffset.getx();
112  int y = mapCfg.mapOffset.gety();
113  int z = mapCfg.mapOffset.getz();
114  if((CkNumPes()==1) && !mapCfg.isTorusFake)
115  mapTable = *(new MapType4(**inst0MapTable)); ///< Lazy way to avoid having to write an assignment operator for MapType4
116  else
117  mapTable.translate(*inst0MapTable, x, y, z, mapCfg.isTorusMap);
118  }
119 
120  /// Create a map group that will read and use this map table
121  CProxy_SCalcMap pcMapGrp = CProxy_SCalcMap::ckNew(mapTable);
122 
123  mapCreationTime = CmiWallTimer() - mapCreationTime;
124  CkPrintf("PairCalculator[%dx%dx%dx%d,%d] map created in %g\n", size[0], size[1], size[2], cfg.numChunks, cfg.isSymmetric, mapCreationTime);
125 
126  // If the user wants map dumps
127  if(config.dumpMapFiles)
128  {
129  MapFile *mf = new MapFile(mapName.c_str(), 4, size, config.numPes, "TXYZ", 2, 1, 1, 1, cfg.grainSize);
130  mf->dumpMap(&mapTable, cfg.instanceIndex);
131  delete mf;
132  }
133 
134  // If the user wants map coordinate dumps
135  if(config.dumpMapCoordFiles)
136  {
137  MapFile *mf = new MapFile((mapName+"_coord").c_str(), 4, size, config.numPes, "TXYZ", 2, 1, 1, 1, cfg.grainSize);
138  mf->dumpMapCoords(&mapTable, cfg.instanceIndex);
139  delete mf;
140  }
141 
142  // Record the group that will provide the procNum mapping function
143  pcHandle.mapperGID = pcMapGrp.ckGetGroupID();
144  delete availGlobG;
145 }
146 
147 
148 
149 /*
150 void Builder::createInputHandler(const pcConfig &cfg)
151 {
152  CkArrayOptions handlerOpts;
153  /// Create an empty input handler chare array that will accept all incoming messages from GSpace
154  handlerOpts.bindTo(pairCalculatorProxy);
155  CProxy_InputDataHandler<CollatorType,CollatorType> inputHandlerProxy = CProxy_InputDataHandler<CollatorType,CollatorType> ::ckNew(pairCalculatorProxy,handlerOpts);
156 }
157 */
158 
159 
160 
162 {
163  CkArrayOptions paircalcOpts,handlerOpts;
164  CProxy_PairCalculator pairCalculatorProxy;
166 
167  // Create an empty array but specify element locations using the map
168  paircalcOpts.setMap(pcHandle.mapperGID);
169  paircalcOpts.setAnytimeMigration(false);
170  pairCalculatorProxy = CProxy_PairCalculator::ckNew(inputHandlerProxy, cfg, paircalcOpts);
171 
172  #ifdef DEBUG_CP_PAIRCALC_CREATION
173  CkPrintf("Builder: Creating a%s paircalc instance\n", (cfg.isSymmetric?" symmetric":"n asymmetric") );
174  #endif
175  #ifdef CP_PAIRCALC_USES_COMPLEX_MATH
176  CkPrintf("Builder: Creating paircalcs for instance %d that use complex math\n", cfg.instanceIndex);
177  #else
178  CkPrintf("Builder: Creating paircalcs for instance %d that do not use complex math\n", cfg.instanceIndex);
179  #endif
180 
181  /// Create an empty input handler chare array that will accept all incoming messages from GSpace
182  handlerOpts.bindTo(pairCalculatorProxy);
183  inputHandlerProxy = CProxy_InputDataHandler<CollatorType,CollatorType> ::ckNew(pairCalculatorProxy,handlerOpts);
184 
185  // Initialize my set of array / group IDs
186  pcHandle.pcAID = pairCalculatorProxy.ckGetArrayID();
187  pcHandle.handlerAID = inputHandlerProxy.ckGetArrayID();
188 
189  // Compute the max value of the state dimension indices of the paircalc array
190  int pcMaxStateDimIndex = (cfg.numStates / cfg.grainSize - 1) * cfg.grainSize;
191  // Populate the sparse, 4D paircalc array
192  for(int numX = 0; numX < cfg.numPlanes; numX ++)
193  {
194  for (int s1 = 0; s1 <= pcMaxStateDimIndex; s1 += cfg.grainSize)
195  {
196  // Make the symmetric array a triangular prism of chares only if phantoms are not needed
197  int s2start = (cfg.isSymmetric && !cfg.arePhantomsOn) ? s1 : 0;
198  for (int s2 = s2start; s2 <= pcMaxStateDimIndex; s2 += cfg.grainSize)
199  {
200  for (int c = 0; c < cfg.numChunks; c++)
201  {
202  #ifdef DEBUG_CP_PAIRCALC_CREATION
203  CkPrintf("\tInserting PC element [%d %d %d %d %d]\n",numX,s1,s2,c,cfg.isSymmetric);
204  #endif
205  pairCalculatorProxy(numX,s1,s2,c).insert(inputHandlerProxy, cfg);
206  }
207  }
208  }
209  }
210 
211  /// Notify the runtime that we're done inserting all the PC elements
212  pairCalculatorProxy.doneInserting();
213 }
214 
215 
216 
217 
218  } // end namespace paircalc
219 } // end namespace cp
220 /*@}*/
221 #include "pcMaps.def.h"
222 
bool isSymmetric
Is this a symmetric or asymmetric paircalc instance.
Definition: pcConfig.h:30
CkGroupID mapperGID
The group providing procNum() for placing the objects of this paircalc array instance.
Definition: pcInstanceIDs.h:15
int numPlanes
The total number of planes in the system.
Definition: pcConfig.h:39
Definition: PeList.h:33
InstanceIDs build(const startup::PCMapConfig &mapCfg)
Trigger the creation of a pc array with the given configs, within the given pes/boxes etc...
Definition: pcBuilder.C:18
void createMap(const startup::PCMapConfig &mapCfg)
Create the mapping required to instantiate a PC array.
Definition: pcBuilder.C:50
const pcConfig cfg
The configs for the paircalc array that I am charged with building.
Definition: pcBuilder.h:36
Author: Abhinav S Bhatele Date Created: December 28th, 2006.
int inputSpanningTreeFactor
The branching factor of the spanning trees that carry the input msgs.
Definition: pcConfig.h:85
A container for assorted mapping inputs to pass around easily.
Definition: pcMapConfig.h:15
void createPairCalcs()
Create a paircalc array using info in the supplied pcConfig object.
Definition: pcBuilder.C:161
CkGroupID mCastMgrGID
The CkMulticast group that will handle gspace <–> pc comm.
Definition: pcInstanceIDs.h:19
int numStates
The total number of states in the system.
Definition: pcConfig.h:41
Definition: IntMap.h:26
int grainSize
The grain size along the states dimensions (plural) (number of states per PC chare) ...
Definition: pcConfig.h:45
int instanceIndex
The proxyOffset value of thisInstance of OpenAtom computations.
Definition: pcConfig.h:57
int numChunks
The number of chunks (4th dimension of decomposition)
Definition: pcConfig.h:43
InstanceIDs pcHandle
The result of an array build.
Definition: pcBuilder.h:38
Input handler chare array proxies.
bool arePhantomsOn
If this is a symmetric instance, should it use phantom chares to balance the BW path.
Definition: pcConfig.h:32
CkArrayID pcAID
The array IDs of the paircalc and its servant input handler arrays.
Definition: pcInstanceIDs.h:17
A tiny structure to hold the relevant IDs/ proxies required to interact with a paircalc instance...
Definition: pcInstanceIDs.h:11