NAMD
WorkDistrib.h
Go to the documentation of this file.
1 
7 #ifndef _WORKDISTRIB_H
8 #define _WORKDISTRIB_H
9 
10 #include "charm++.h"
11 
12 #include "main.h"
13 
14 #include "NamdTypes.h"
15 #include "BOCgroup.h"
16 #include "ComputeMap.h"
17 #include "WorkDistrib.decl.h"
18 
19 class Node;
20 class Compute;
21 class Molecule;
22 
23 // For Compute objects to enqueue themselves when ready to compute
24 class LocalWorkMsg : public CMessage_LocalWorkMsg
25 {
26 public:
28 };
29 
30 class FinishWorkMsg : public CMessage_FinishWorkMsg
31 {
32 public:
34  int data;
35 };
36 
37 enum { maxPatchDepends = 126 };
38 
39 class PatchMapMsg;
41 
42 class WorkDistrib : public CBase_WorkDistrib
43 {
44 public:
45  WorkDistrib();
46  ~WorkDistrib(void);
47 
48  // static void messageMovePatchDone();
49  // void movePatchDone();
50 
51  static void messageEnqueueWork(Compute *);
52  static void messageFinishCUDA(Compute *);
53  static void messageFinishMIC(Compute *);
54  void enqueueWork(LocalWorkMsg *msg);
55  void enqueueExcls(LocalWorkMsg *msg);
56  void enqueueBonds(LocalWorkMsg *msg);
57  void enqueueAngles(LocalWorkMsg *msg);
58  void enqueueDihedrals(LocalWorkMsg *msg);
59  void enqueueImpropers(LocalWorkMsg *msg);
60  void enqueueThole(LocalWorkMsg *msg); // Drude model
61  void enqueueAniso(LocalWorkMsg *msg); // Drude model
63  // JLai
65  // End of JLai
66  void enqueuePme(LocalWorkMsg *msg);
67  void enqueueSelfA1(LocalWorkMsg *msg);
68  void enqueueSelfA2(LocalWorkMsg *msg);
69  void enqueueSelfA3(LocalWorkMsg *msg);
70  void enqueueSelfB1(LocalWorkMsg *msg);
71  void enqueueSelfB2(LocalWorkMsg *msg);
72  void enqueueSelfB3(LocalWorkMsg *msg);
73  void enqueueWorkA1(LocalWorkMsg *msg);
74  void enqueueWorkA2(LocalWorkMsg *msg);
75  void enqueueWorkA3(LocalWorkMsg *msg);
76  void enqueueWorkB1(LocalWorkMsg *msg);
77  void enqueueWorkB2(LocalWorkMsg *msg);
78  void enqueueWorkB3(LocalWorkMsg *msg);
79  void enqueueWorkC(LocalWorkMsg *msg);
80  void enqueueCUDA(LocalWorkMsg *msg);
81  void enqueueCUDAP2(LocalWorkMsg *msg);
82  void enqueueCUDAP3(LocalWorkMsg *msg);
83  void finishCUDAPatch(FinishWorkMsg *msg);
84  void finishCUDA(LocalWorkMsg *msg);
85  void finishCUDAP2(LocalWorkMsg *msg);
86  void finishCUDAP3(LocalWorkMsg *msg);
87  void enqueueMIC(LocalWorkMsg *msg);
88  void finishMIC(LocalWorkMsg *msg);
89  void enqueueLCPO(LocalWorkMsg *msg);
90 
91  void mapComputes(void);
92  void sendPatchMap(void);
93  void sendComputeMap(void);
94  void saveComputeMapChanges(int,CkGroupID);
96  void doneSaveComputeMap(CkReductionMsg *);
97 
98  FullAtomList *createAtomLists(const char *basename=0);
99  void createHomePatches(void);
100  void distributeHomePatches(void);
101 
102  void reinitAtoms(const char *basename=0);
103  void patchMapInit(void);
104  void assignNodeToPatch(void);
105 
106  void savePatchMap(PatchMapMsg *msg);
107  inline void setPatchMapArrived(bool s) {patchMapArrived=s;}
108 
109 #ifdef MEM_OPT_VERSION
110  void fillAtomListForOnePatch(int pid, FullAtomList &alist);
111  void random_velocities_parallel(BigReal Temp,InputAtomList &inAtoms);
112 #endif
113 
114  static int peOrderingInit; // used during startup
115  static int *peDiffuseOrdering; // pes in diffuse order
116  static int *peDiffuseOrderingIndex; // index of pe in diffuse order
117  static int *peCompactOrdering; // pes in compact order
118  static int *peCompactOrderingIndex; // index of pe in compact order
119 
121  inline bool operator() (int a, int b) const {
122  const int *index = WorkDistrib::peDiffuseOrderingIndex;
123  return ( index[a] < index[b] );
124  }
125  };
127  inline bool operator() (int a, int b) const {
128  const int *index = WorkDistrib::peCompactOrderingIndex;
129  return ( index[a] < index[b] );
130  }
131  };
132 
133  static void sortPmePes(int *pmepes, int xdim, int ydim);
134 
135  static void peOrderingReady();
136 
137  // MIC-Specific
138  static void send_initHostDeviceLDB();
139  /* entry */ void initHostDeviceLDB();
140  static void send_contributeHostDeviceLDB(int peSetLen, int * peSet);
141  /* entry */ void contributeHostDeviceLDB(int peSetLen, int * peSet);
142  static void send_setDeviceLDBParams(int dt, int hs, int sp1, int pp1, int pp2);
143  /* entry */ void setDeviceLDBParams(int dt, int hs, int sp1, int pp1, int pp2);
144 
145  static void buildNodeAwarePeOrdering(void);
146 
147 private:
148  void mapComputeNonbonded(void);
149  void mapComputeLCPO(void);
150  void mapComputeNode(ComputeType);
151  void mapComputeHomePatches(ComputeType);
152  void mapComputeHomeTuples(ComputeType);
153  void mapComputePatch(ComputeType);
154  void assignPatchesToLowestLoadNode(void);
155  void assignPatchesRecursiveBisection(void);
156  void assignPatchesRoundRobin(void);
157  void assignPatchesSpaceFillingCurve(void);
158  void assignPatchesBitReversal(void);
159  int assignPatchesTopoGridRecBisection();
160 
161  void sortNodesAndAssign(int *assignedNode, int baseNodes = 0);
162  void velocities_from_PDB(const char *filename,
163  Vector *v, int totalAtoms);
164  void velocities_from_binfile(const char *fname, Vector *vels, int n);
165  void random_velocities(BigReal Temp, Molecule *structure,
166  Vector *v, int totalAtoms);
167  void remove_com_motion(Vector *vel, Molecule *structure, int n);
168 
169  bool patchMapArrived;
170  bool computeMapArrived;
171 
172  int saveComputeMapReturnEP;
173  CkGroupID saveComputeMapReturnChareID;
174 };
175 
176 #endif /* WORKDISTRIB_H */
177 
void setDeviceLDBParams(int dt, int hs, int sp1, int pp1, int pp2)
Definition: WorkDistrib.C:3410
void enqueueMIC(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3126
static void sortPmePes(int *pmepes, int xdim, int ydim)
Definition: WorkDistrib.C:300
static void messageFinishMIC(Compute *)
Definition: WorkDistrib.C:2929
void setPatchMapArrived(bool s)
Definition: WorkDistrib.h:107
void enqueueAngles(LocalWorkMsg *msg)
Definition: WorkDistrib.C:2968
static void messageFinishCUDA(Compute *)
Definition: WorkDistrib.C:2896
Definition: Node.h:78
static int * peCompactOrdering
Definition: WorkDistrib.h:117
void finishCUDAP3(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3122
void enqueueCrossterms(LocalWorkMsg *msg)
Definition: WorkDistrib.C:2998
void enqueuePme(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3013
void enqueueWorkA3(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3066
ComputeType
Definition: ComputeMap.h:20
void enqueueWork(LocalWorkMsg *msg)
Definition: WorkDistrib.C:2950
void enqueueGromacsPair(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3005
void enqueueSelfA1(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3024
void finishCUDAP2(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3119
Definition: Vector.h:64
static void send_contributeHostDeviceLDB(int peSetLen, int *peSet)
Definition: WorkDistrib.C:3390
void enqueueExcls(LocalWorkMsg *msg)
Definition: WorkDistrib.C:2956
void enqueueBonds(LocalWorkMsg *msg)
Definition: WorkDistrib.C:2962
void enqueueAniso(LocalWorkMsg *msg)
Definition: WorkDistrib.C:2992
void enqueueSelfB1(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3040
void enqueueWorkB1(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3072
static void messageEnqueueWork(Compute *)
Definition: WorkDistrib.C:2727
static void peOrderingReady()
Definition: WorkDistrib.C:166
void enqueueSelfA3(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3034
bool operator()(int a, int b) const
Definition: WorkDistrib.h:127
void patchMapInit(void)
Definition: WorkDistrib.C:1105
void recvComputeMapChanges(ComputeMapChangeMsg *)
Definition: WorkDistrib.C:370
Compute * compute
Definition: WorkDistrib.h:33
void enqueueCUDA(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3096
void sendComputeMap(void)
Definition: WorkDistrib.C:1078
void enqueueWorkB2(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3077
void enqueueCUDAP2(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3102
void enqueueSelfB3(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3050
void enqueueWorkC(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3090
void reinitAtoms(const char *basename=0)
Definition: WorkDistrib.C:952
void enqueueThole(LocalWorkMsg *msg)
Definition: WorkDistrib.C:2986
void enqueueWorkA2(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3061
void createHomePatches(void)
Definition: WorkDistrib.C:889
Compute * compute
Definition: WorkDistrib.h:27
void enqueueImpropers(LocalWorkMsg *msg)
Definition: WorkDistrib.C:2980
void enqueueLCPO(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3019
bool operator()(int a, int b) const
Definition: WorkDistrib.h:121
void finishCUDA(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3113
~WorkDistrib(void)
Definition: WorkDistrib.C:117
void enqueueCUDAP3(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3105
static int * peDiffuseOrderingIndex
Definition: WorkDistrib.h:116
void enqueueWorkA1(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3056
static int * peDiffuseOrdering
Definition: WorkDistrib.h:115
static int peOrderingInit
Definition: WorkDistrib.h:114
void sendPatchMap(void)
Definition: WorkDistrib.C:978
void saveComputeMapChanges(int, CkGroupID)
Definition: WorkDistrib.C:352
void finishCUDAPatch(FinishWorkMsg *msg)
Definition: WorkDistrib.C:3109
void savePatchMap(PatchMapMsg *msg)
Definition: WorkDistrib.C:1014
static int * peCompactOrderingIndex
Definition: WorkDistrib.h:118
static void buildNodeAwarePeOrdering(void)
Definition: WorkDistrib.C:176
static void send_setDeviceLDBParams(int dt, int hs, int sp1, int pp1, int pp2)
Definition: WorkDistrib.C:3403
void mapComputes(void)
Definition: WorkDistrib.C:2269
void enqueueSelfA2(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3029
void distributeHomePatches(void)
Definition: WorkDistrib.C:930
void enqueueSelfB2(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3045
void initHostDeviceLDB()
Definition: WorkDistrib.C:3384
static void send_initHostDeviceLDB()
Definition: WorkDistrib.C:3377
FullAtomList * createAtomLists(const char *basename=0)
Definition: WorkDistrib.C:618
void enqueueDihedrals(LocalWorkMsg *msg)
Definition: WorkDistrib.C:2974
void finishMIC(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3129
void contributeHostDeviceLDB(int peSetLen, int *peSet)
Definition: WorkDistrib.C:3397
void doneSaveComputeMap(CkReductionMsg *)
Definition: WorkDistrib.C:423
void enqueueWorkB3(LocalWorkMsg *msg)
Definition: WorkDistrib.C:3082
double BigReal
Definition: common.h:114
void assignNodeToPatch(void)
Definition: WorkDistrib.C:1319