NAMD
RecBisection.h
Go to the documentation of this file.
1 
7 #ifndef RECBISECTION_H
8 #define RECBISECTION_H
9 
10 #include "converse.h"
11 
12 class PatchMap;
13 
14 #if USE_TOPOMAP
15 /******
16  NAMD likes the X dimension to be the largest, followed by Y and
17  then Z. This structure stores the relationsip between x,y,z and
18  virtualx, virtualy and virtualz.
19 ***************/
20 
21 struct DimensionMap {
22  int x;
23  int y;
24  int z;
25 };
26 
27 
28 inline void findOptimalDimensions(int X, int Y, int Z,
29  int & new_X, int & new_Y, int &new_Z,
30  DimensionMap &dm) {
31  if(X == Y && Y == Z)
32  return;
33 
34  if(X >= Y) {
35  if(X >= Z) {
36  new_X = X;
37  dm.x = 0;
38 
39  if(Z >= Y) {
40  new_Y = Z;
41  new_Z = Y;
42 
43  dm.y = 2;
44  dm.z = 1;
45  }
46  else {
47  new_Y = Y;
48  new_Z = Z;
49 
50  dm.y = 1;
51  dm.z = 2;
52  }
53  }
54  else {
55  new_X = Z;
56  new_Y = X;
57  new_Z = Y;
58 
59  dm.x = 1;
60  dm.y = 2;
61  dm.z = 0;
62  }
63  }
64  else {
65  if(Y >= Z) {
66  new_X = Y;
67  dm.y = 0;
68 
69  if(Z >= X) {
70  new_Y = Z;
71  new_Z = X;
72 
73  dm.x = 2;
74  dm.z = 1;
75  }
76  else {
77  new_Y = X;
78  new_Z = Z;
79 
80  dm.x = 1;
81  dm.z = 2;
82  }
83  }
84  else {
85  new_X = Z;
86  new_Y = Y;
87  new_Z = X;
88 
89  dm.x = 2;
90  dm.y = 1;
91  dm.z = 0;
92  }
93  }
94 }
95 #endif
96 
97 /* *********************************************************************** */
98 /* This class performs a recursive coordinate bisection partitioning */
99 /* together with some communication and computation refinements */
100 /* *********************************************************************** */
101 
102 #define MAXNEIGHBOUR 26
104 {
105  private:
106 
107  typedef struct { // a rectangular prism
108  float load; // is represented with
109  struct { int x,y,z; } origin; // origin and corner coordinates
110  struct { int x,y,z; } corner;
111  } Partition;
112 
113 
114  typedef struct { // the cost of a patch
115  float total; // is represented here
116  float local;
117  float edge;
118  float icompute[MAXNEIGHBOUR];
119  } PatchLoad;
120 
121  enum {XDIR=0,YDIR,ZDIR};
122 
123  // cost parameters
124  float c_local0; // fixed cost per patch
125  float c_local1; // cost per atom in the patch
126  float c_edge0; // fixed cost for having a neighbor patch
127  float c_edge1; // cost per atom of the neighboring patch
128  float c_icompute0; // fixed cost per calc. forces for a neighbor
129  float c_icompute1; // cost per atom of the neihgbor that I calc force.
130 
131 
132 
133  int numPatches;
134  int npartition;
135  int currentp;
136  Partition *partitions;
137 
138  PatchLoad *patchload;
139  PatchMap *patchMap;
140  Partition top_partition;
141 
142  void compute_patch_load(); // determine cost of each patch
143  void rec_divide(int, const Partition&); // recursive partitioning
144  void assignNodes(); // assign partitions to nodes
145  void assign_nodes_arr(int *); // assign partitions to array
146  void refine_edges();
147  void refine_boundaries();
148  void refine_surface();
149  int prev_better(float,float,float);
150 
151  public:
152 
153  RecBisection(int, PatchMap *);
154 
155  ~RecBisection();
156  int partition(int *); // perform partitioning.
157  // if parameter=NULL, store
158  // results in patchDistrib,
159  // otherwise, store in array
160 
161 #if USE_TOPOMAP
162  RecBisection(int, int , int, PatchMap *); //Pass in a 3d
163  //processor grid
164  void assignPatchesToProcGrid(int *dest_arr, int X, int Y, int Z,
165  DimensionMap dm);
166  int topogrid_rec_divide(Partition &proc_p, Partition &patch_p);
167  int partitionProcGrid(int X, int Y, int Z, int *dest_arr);
168 #endif
169 };
170 
171 #endif
172 
BlockLoad::TempStorage load
#define X
Definition: msm_defn.h:29
#define MAXNEIGHBOUR
Definition: RecBisection.h:102
#define Z
Definition: msm_defn.h:33
gridSize z
int partition(int *)
Definition: RecBisection.C:293
gridSize y
RecBisection(int, PatchMap *)
Definition: RecBisection.C:18
#define Y
Definition: msm_defn.h:31
gridSize x