-
Notifications
You must be signed in to change notification settings - Fork 1
/
ComputeMgr.C
1339 lines (1221 loc) · 41.2 KB
/
ComputeMgr.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
*** Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by
*** The Board of Trustees of the University of Illinois.
*** All rights reserved.
**/
#include "InfoStream.h"
#include "ProcessorPrivate.h"
//#define DEBUGM
#define MIN_DEBUG_LEVEL 1
#include "Debug.h"
#include "BOCgroup.h"
#include "ComputeMgr.decl.h"
#include "ComputeMgr.h"
#include "ProxyMgr.decl.h"
#include "ProxyMgr.h"
#include "Node.h"
#include "ComputeMap.h"
#include "PatchMap.h"
#include "PatchMap.inl"
#include "Compute.h"
#include "ComputeNonbondedUtil.h"
#include "ComputeNonbondedSelf.h"
#include "ComputeNonbondedPair.h"
#include "ComputeNonbondedCUDA.h"
#include "ComputeNonbondedMIC.h"
#include "ComputeAngles.h"
#include "ComputeDihedrals.h"
#include "ComputeImpropers.h"
#include "ComputeThole.h"
#include "ComputeAniso.h"
#include "ComputeCrossterms.h"
// JLai
#include "ComputeGromacsPair.h"
#include "ComputeBonds.h"
#include "ComputeNonbondedCUDAExcl.h"
#include "ComputeFullDirect.h"
#include "ComputeGlobal.h"
#include "ComputeGlobalMsgs.h"
#include "ComputeExt.h"
#include "ComputeGBISser.h"
#include "ComputeLCPO.h"
#include "ComputeFmmSerial.h"
#include "ComputeMsmSerial.h"
#include "ComputeMsmMsa.h"
#include "ComputeMsm.h"
#include "ComputeDPMTA.h"
#include "ComputeDPME.h"
#include "ComputeDPMEMsgs.h"
#include "ComputePme.h"
#include "OptPme.h"
#include "ComputeEwald.h"
#include "ComputeEField.h"
/* BEGIN gf */
#include "ComputeGridForce.h"
/* END gf */
#include "ComputeStir.h"
#include "ComputeSphericalBC.h"
#include "ComputeCylindricalBC.h"
#include "ComputeTclBC.h"
#include "ComputeRestraints.h"
#include "ComputeConsForce.h"
#include "ComputeConsForceMsgs.h"
#include "WorkDistrib.h"
#include "LdbCoordinator.h"
/* include all of the specific masters we need here */
#include "FreeEnergyEnums.h"
#include "FreeEnergyAssert.h"
#include "FreeEnergyGroup.h"
#include "FreeEnergyVector.h"
#include "FreeEnergyRestrain.h"
#include "FreeEnergyRMgr.h"
#include "FreeEnergyLambda.h"
#include "FreeEnergyLambdMgr.h"
#include "GlobalMasterTest.h"
#include "GlobalMasterIMD.h"
#include "GlobalMasterTcl.h"
#include "GlobalMasterSMD.h"
#include "GlobalMasterTMD.h"
#include "GlobalMasterSymmetry.h"
#include "GlobalMasterEasy.h"
#include "GlobalMasterMisc.h"
#include "GlobalMasterFreeEnergy.h"
#include "GlobalMasterColvars.h"
#include "ComputeNonbondedMICKernel.h"
ComputeMgr::ComputeMgr()
{
CkpvAccess(BOCclass_group).computeMgr = thisgroup;
computeGlobalObject = 0;
computeGlobalResultsMsgSeq = -1;
computeGlobalResultsMsgMasterSeq = -1;
computeDPMEObject = 0;
computeEwaldObject = 0;
computeNonbondedCUDAObject = 0;
computeNonbondedMICObject = 0;
computeNonbondedWorkArrays = new ComputeNonbondedWorkArrays;
skipSplitting = 0;
#if defined(NAMD_MIC)
// Create the micPEData flag array (1 bit per PE) and initially set each PE as "not driving
// a MIC card" (unset). PEs that are driving MIC card will identify themselves during startup.
int numPEs = CkNumPes();
int numInts = ((numPEs + (sizeof(int)*8-1)) & (~(sizeof(int)*8-1))) / (sizeof(int)*8); // Round up to sizeof(int) then divide by the size of an int
micPEData = new int[numInts];
if (micPEData == NULL) { NAMD_die("Unable to allocate memory for micPEData"); }
memset(micPEData, 0, sizeof(int) * numInts);
#else
micPEData = NULL;
#endif
}
ComputeMgr::~ComputeMgr(void)
{
delete computeNonbondedWorkArrays;
}
void ComputeMgr::updateComputes(int ep, CkGroupID chareID)
{
updateComputesReturnEP = ep;
updateComputesReturnChareID = chareID;
updateComputesCount = CkNumPes();
if (CkMyPe())
{
iout << iPE << iERRORF << "updateComputes signaled on wrong Pe!\n" << endi;
CkExit();
return;
}
CkStartQD(CkIndex_ComputeMgr::updateComputes2((CkQdMsg*)0),&thishandle);
}
void ComputeMgr::updateComputes2(CkQdMsg *msg)
{
delete msg;
CProxy_WorkDistrib wd(CkpvAccess(BOCclass_group).workDistrib);
WorkDistrib *workDistrib = wd.ckLocalBranch();
workDistrib->saveComputeMapChanges(CkIndex_ComputeMgr::updateComputes3(),thisgroup);
}
void ComputeMgr::updateComputes3()
{
if ( skipSplitting ) {
CProxy_ComputeMgr(thisgroup).updateLocalComputes();
} else {
CProxy_ComputeMgr(thisgroup).splitComputes();
skipSplitting = 1;
}
}
void ComputeMgr::splitComputes()
{
if ( ! CkMyRank() ) {
ComputeMap *computeMap = ComputeMap::Object();
const int nc = computeMap->numComputes();
for (int i=0; i<nc; i++) {
int nnp = computeMap->newNumPartitions(i);
if ( nnp > 0 ) {
if ( computeMap->numPartitions(i) != 1 ) {
CkPrintf("Warning: unable to partition compute %d\n", i);
computeMap->setNewNumPartitions(i,0);
continue;
}
//CkPrintf("splitting compute %d by %d\n",i,nnp);
computeMap->setNumPartitions(i,nnp);
if (computeMap->newNode(i) == -1) {
computeMap->setNewNode(i,computeMap->node(i));
}
for ( int j=1; j<nnp; ++j ) {
int newcid = computeMap->cloneCompute(i,j);
//CkPrintf("compute %d partition %d is %d\n",i,j,newcid);
}
}
}
computeMap->extendPtrs();
}
if (!CkMyPe())
{
CkStartQD(CkIndex_ComputeMgr::splitComputes2((CkQdMsg*)0), &thishandle);
}
}
void ComputeMgr::splitComputes2(CkQdMsg *msg)
{
delete msg;
CProxy_ComputeMgr(thisgroup).updateLocalComputes();
}
void ComputeMgr::updateLocalComputes()
{
ComputeMap *computeMap = ComputeMap::Object();
CProxy_ProxyMgr pm(CkpvAccess(BOCclass_group).proxyMgr);
ProxyMgr *proxyMgr = pm.ckLocalBranch();
LdbCoordinator *ldbCoordinator = LdbCoordinator::Object();
computeFlag.resize(0);
const int nc = computeMap->numComputes();
for (int i=0; i<nc; i++) {
if ( computeMap->node(i) == CkMyPe() &&
computeMap->newNumPartitions(i) > 1 ) {
Compute *c = computeMap->compute(i);
ldbCoordinator->Migrate(c->ldObjHandle,CkMyPe());
delete c;
computeMap->registerCompute(i,NULL);
if ( computeMap->newNode(i) == CkMyPe() ) computeFlag.add(i);
} else
if (computeMap->newNode(i) == CkMyPe() && computeMap->node(i) != CkMyPe())
{
computeFlag.add(i);
for (int n=0; n < computeMap->numPids(i); n++)
{
proxyMgr->createProxy(computeMap->pid(i,n));
}
}
else if (computeMap->node(i) == CkMyPe() &&
(computeMap->newNode(i) != -1 && computeMap->newNode(i) != CkMyPe() ))
{
// CkPrintf("delete compute %d on pe %d\n",i,CkMyPe());
delete computeMap->compute(i);
computeMap->registerCompute(i,NULL);
}
}
if (!CkMyPe())
{
CkStartQD(CkIndex_ComputeMgr::updateLocalComputes2((CkQdMsg*)0), &thishandle);
}
}
void
ComputeMgr::updateLocalComputes2(CkQdMsg *msg)
{
delete msg;
CProxy_ComputeMgr(thisgroup).updateLocalComputes3();
}
void
ComputeMgr::updateLocalComputes3()
{
ComputeMap *computeMap = ComputeMap::Object();
CProxy_ProxyMgr pm(CkpvAccess(BOCclass_group).proxyMgr);
ProxyMgr *proxyMgr = pm.ckLocalBranch();
ProxyMgr::nodecount = 0;
const int nc = computeMap->numComputes();
if ( ! CkMyRank() ) {
for (int i=0; i<nc; i++) {
computeMap->setNewNumPartitions(i,0);
if (computeMap->newNode(i) != -1) {
computeMap->setNode(i,computeMap->newNode(i));
computeMap->setNewNode(i,-1);
}
}
}
for(int i=0; i<computeFlag.size(); i++) createCompute(computeFlag[i], computeMap);
computeFlag.clear();
proxyMgr->removeUnusedProxies();
if (!CkMyPe())
{
CkStartQD(CkIndex_ComputeMgr::updateLocalComputes4((CkQdMsg*)0), &thishandle);
}
}
void
ComputeMgr::updateLocalComputes4(CkQdMsg *msg)
{
delete msg;
CProxy_ComputeMgr(thisgroup).updateLocalComputes5();
// store the latest compute map
SimParameters *simParams = Node::Object()->simParameters;
if (simParams->storeComputeMap) {
ComputeMap *computeMap = ComputeMap::Object();
computeMap->saveComputeMap(simParams->computeMapFilename);
}
}
#if 0
int firstphase = 1;
#endif
void
ComputeMgr::updateLocalComputes5()
{
if ( ! CkMyRank() ) {
ComputeMap::Object()->checkMap();
PatchMap::Object()->checkMap();
}
// we always use the centralized building of spanning tree
// distributed building of ST called in Node.C only
if (proxySendSpanning || proxyRecvSpanning)
ProxyMgr::Object()->buildProxySpanningTree2();
// this code needs to be turned on if we want to
// shift the creation of ST to the load balancer
#if 0
if (proxySendSpanning || proxyRecvSpanning)
{
if (firstphase)
ProxyMgr::Object()->buildProxySpanningTree2();
else
if (CkMyPe() == 0)
ProxyMgr::Object()->sendSpanningTrees();
firstphase = 0;
}
#endif
if (!CkMyPe())
CkStartQD(CkIndex_ComputeMgr::doneUpdateLocalComputes(), &thishandle);
}
void ComputeMgr::doneUpdateLocalComputes()
{
// if (!--updateComputesCount) {
DebugM(4, "doneUpdateLocalComputes on Pe("<<CkMyPe()<<")\n");
void *msg = CkAllocMsg(0,0,0);
CkSendMsgBranch(updateComputesReturnEP,msg,0,updateComputesReturnChareID);
// }
}
//
void
ComputeMgr::createCompute(ComputeID i, ComputeMap *map)
{
Compute *c;
PatchID pid2[2];
PatchIDList pids;
int trans2[2];
SimParameters *simParams = Node::Object()->simParameters;
PatchID pid8[8];
int trans8[8];
switch ( map->type(i) )
{
case computeNonbondedSelfType:
#ifdef NAMD_CUDA
register_cuda_compute_self(i,map->computeData[i].pids[0].pid);
#elif defined(NAMD_MIC)
if (map->directToDevice(i) == 0) {
c = new ComputeNonbondedSelf(i,map->computeData[i].pids[0].pid,
computeNonbondedWorkArrays,
map->partition(i),map->partition(i)+1,
map->numPartitions(i)); // unknown delete
map->registerCompute(i,c);
c->initialize();
} else {
register_mic_compute_self(i,map->computeData[i].pids[0].pid,map->partition(i),map->numPartitions(i));
}
#else
c = new ComputeNonbondedSelf(i,map->computeData[i].pids[0].pid,
computeNonbondedWorkArrays,
map->partition(i),map->partition(i)+1,
map->numPartitions(i)); // unknown delete
map->registerCompute(i,c);
c->initialize();
#endif
break;
case computeLCPOType:
for (int j = 0; j < 8; j++) {
pid8[j] = map->computeData[i].pids[j].pid;
trans8[j] = map->computeData[i].pids[j].trans;
}
c = new ComputeLCPO(i,pid8,trans8,
computeNonbondedWorkArrays,
map->partition(i),map->partition(i)+1,
map->numPartitions(i), 8);
map->registerCompute(i,c);
c->initialize();
break;
case computeNonbondedPairType:
pid2[0] = map->computeData[i].pids[0].pid;
trans2[0] = map->computeData[i].pids[0].trans;
pid2[1] = map->computeData[i].pids[1].pid;
trans2[1] = map->computeData[i].pids[1].trans;
#ifdef NAMD_CUDA
register_cuda_compute_pair(i,pid2,trans2);
#elif defined(NAMD_MIC)
if (map->directToDevice(i) == 0) {
c = new ComputeNonbondedPair(i,pid2,trans2,
computeNonbondedWorkArrays,
map->partition(i),map->partition(i)+1,
map->numPartitions(i)); // unknown delete
map->registerCompute(i,c);
c->initialize();
} else {
register_mic_compute_pair(i,pid2,trans2,map->partition(i),map->numPartitions(i));
}
#else
c = new ComputeNonbondedPair(i,pid2,trans2,
computeNonbondedWorkArrays,
map->partition(i),map->partition(i)+1,
map->numPartitions(i)); // unknown delete
map->registerCompute(i,c);
c->initialize();
#endif
break;
#ifdef NAMD_CUDA
case computeNonbondedCUDAType:
c = computeNonbondedCUDAObject = new ComputeNonbondedCUDA(i,this); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
#endif
#ifdef NAMD_MIC
case computeNonbondedMICType:
c = computeNonbondedMICObject = new ComputeNonbondedMIC(i,this); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
#endif
case computeExclsType:
PatchMap::Object()->basePatchIDList(CkMyPe(),pids);
c = new ComputeExcls(i,pids); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
case computeBondsType:
PatchMap::Object()->basePatchIDList(CkMyPe(),pids);
c = new ComputeBonds(i,pids); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
case computeAnglesType:
PatchMap::Object()->basePatchIDList(CkMyPe(),pids);
c = new ComputeAngles(i,pids); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
case computeDihedralsType:
PatchMap::Object()->basePatchIDList(CkMyPe(),pids);
c = new ComputeDihedrals(i,pids); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
case computeImpropersType:
PatchMap::Object()->basePatchIDList(CkMyPe(),pids);
c = new ComputeImpropers(i,pids); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
case computeTholeType:
PatchMap::Object()->basePatchIDList(CkMyPe(),pids);
c = new ComputeThole(i,pids); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
case computeAnisoType:
PatchMap::Object()->basePatchIDList(CkMyPe(),pids);
c = new ComputeAniso(i,pids); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
case computeCrosstermsType:
PatchMap::Object()->basePatchIDList(CkMyPe(),pids);
c = new ComputeCrossterms(i,pids); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
// JLai
case computeGromacsPairType:
PatchMap::Object()->basePatchIDList(CkMyPe(),pids);
c = new ComputeGromacsPair(i,pids); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
case computeSelfGromacsPairType:
c = new ComputeSelfGromacsPair(i,map->computeData[i].pids[0].pid); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
// End of JLai
case computeSelfExclsType:
c = new ComputeSelfExcls(i,map->computeData[i].pids[0].pid);
map->registerCompute(i,c);
c->initialize();
break;
case computeSelfBondsType:
c = new ComputeSelfBonds(i,map->computeData[i].pids[0].pid);
map->registerCompute(i,c);
c->initialize();
break;
case computeSelfAnglesType:
c = new ComputeSelfAngles(i,map->computeData[i].pids[0].pid);
map->registerCompute(i,c);
c->initialize();
break;
case computeSelfDihedralsType:
c = new ComputeSelfDihedrals(i,map->computeData[i].pids[0].pid);
map->registerCompute(i,c);
c->initialize();
break;
case computeSelfImpropersType:
c = new ComputeSelfImpropers(i,map->computeData[i].pids[0].pid);
map->registerCompute(i,c);
c->initialize();
break;
case computeSelfTholeType:
c = new ComputeSelfThole(i,map->computeData[i].pids[0].pid);
map->registerCompute(i,c);
c->initialize();
break;
case computeSelfAnisoType:
c = new ComputeSelfAniso(i,map->computeData[i].pids[0].pid);
map->registerCompute(i,c);
c->initialize();
break;
case computeSelfCrosstermsType:
c = new ComputeSelfCrossterms(i,map->computeData[i].pids[0].pid);
map->registerCompute(i,c);
c->initialize();
break;
#ifdef DPMTA
case computeDPMTAType:
c = new ComputeDPMTA(i); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
#endif
#ifdef DPME
case computeDPMEType:
c = computeDPMEObject = new ComputeDPME(i,this); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
#endif
case optPmeType:
c = new OptPmeCompute(i); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
case computePmeType:
c = new ComputePme(i,map->computeData[i].pids[0].pid); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
case computeEwaldType:
c = computeEwaldObject = new ComputeEwald(i,this); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
case computeFullDirectType:
c = new ComputeFullDirect(i); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
case computeGlobalType:
c = computeGlobalObject = new ComputeGlobal(i,this); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
case computeStirType:
c = new ComputeStir(i,map->computeData[i].pids[0].pid); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
case computeExtType:
c = new ComputeExt(i); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
case computeGBISserType: //gbis serial
c = new ComputeGBISser(i);
map->registerCompute(i,c);
c->initialize();
break;
case computeFmmType: // FMM serial
c = new ComputeFmmSerial(i);
map->registerCompute(i,c);
c->initialize();
break;
case computeMsmSerialType: // MSM serial
c = new ComputeMsmSerial(i);
map->registerCompute(i,c);
c->initialize();
break;
#ifdef CHARM_HAS_MSA
case computeMsmMsaType: // MSM parallel long-range part using MSA
c = new ComputeMsmMsa(i);
map->registerCompute(i,c);
c->initialize();
break;
#endif
case computeMsmType: // MSM parallel
c = new ComputeMsm(i);
map->registerCompute(i,c);
c->initialize();
break;
case computeEFieldType:
c = new ComputeEField(i,map->computeData[i].pids[0].pid); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
/* BEGIN gf */
case computeGridForceType:
c = new ComputeGridForce(i,map->computeData[i].pids[0].pid);
map->registerCompute(i,c);
c->initialize();
break;
/* END gf */
case computeSphericalBCType:
c = new ComputeSphericalBC(i,map->computeData[i].pids[0].pid); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
case computeCylindricalBCType:
c = new ComputeCylindricalBC(i,map->computeData[i].pids[0].pid); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
case computeTclBCType:
c = new ComputeTclBC(i); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
case computeRestraintsType:
c = new ComputeRestraints(i,map->computeData[i].pids[0].pid); // unknown delete
map->registerCompute(i,c);
c->initialize();
break;
case computeConsForceType:
c = new ComputeConsForce(i,map->computeData[i].pids[0].pid);
map->registerCompute(i,c);
c->initialize();
break;
case computeConsTorqueType:
c = new ComputeConsTorque(i,map->computeData[i].pids[0].pid);
map->registerCompute(i,c);
c->initialize();
break;
default:
NAMD_bug("Unknown compute type in ComputeMgr::createCompute().");
break;
}
}
void registerUserEventsForAllComputeObjs()
{
#ifdef TRACE_COMPUTE_OBJECTS
ComputeMap *map = ComputeMap::Object();
PatchMap *pmap = PatchMap::Object();
char user_des[50];
int p1, p2;
int adim, bdim, cdim;
int t1, t2;
int x1, y1, z1, x2, y2, z2;
int dx, dy, dz;
for (int i=0; i<map->numComputes(); i++)
{
memset(user_des, 0, 50);
switch ( map->type(i) )
{
case computeNonbondedSelfType:
sprintf(user_des, "computeNonBondedSelfType_%d_pid_%d", i, map->pid(i,0));
break;
case computeLCPOType:
sprintf(user_des, "computeLCPOType_%d_pid_%d", i, map->pid(i,0));
break;
case computeNonbondedPairType:
adim = pmap->gridsize_a();
bdim = pmap->gridsize_b();
cdim = pmap->gridsize_c();
p1 = map->pid(i, 0);
t1 = map->trans(i, 0);
x1 = pmap->index_a(p1) + adim * Lattice::offset_a(t1);
y1 = pmap->index_b(p1) + bdim * Lattice::offset_b(t1);
z1 = pmap->index_c(p1) + cdim * Lattice::offset_c(t1);
p2 = map->pid(i, 1);
t2 = map->trans(i, 1);
x2 = pmap->index_a(p2) + adim * Lattice::offset_a(t2);
y2 = pmap->index_b(p2) + bdim * Lattice::offset_b(t2);
z2 = pmap->index_c(p2) + cdim * Lattice::offset_c(t2);
dx = abs(x1-x2);
dy = abs(y1-y2);
dz = abs(z1-z2);
sprintf(user_des, "computeNonBondedPairType_%d(%d,%d,%d)", i, dx,dy,dz);
break;
case computeExclsType:
sprintf(user_des, "computeExclsType_%d", i);
break;
case computeBondsType:
sprintf(user_des, "computeBondsType_%d", i);
break;
case computeAnglesType:
sprintf(user_des, "computeAnglesType_%d", i);
break;
case computeDihedralsType:
sprintf(user_des, "computeDihedralsType_%d", i);
break;
case computeImpropersType:
sprintf(user_des, "computeImpropersType_%d", i);
break;
case computeTholeType:
sprintf(user_des, "computeTholeType_%d", i);
break;
case computeAnisoType:
sprintf(user_des, "computeAnisoType_%d", i);
break;
case computeCrosstermsType:
sprintf(user_des, "computeCrosstermsType_%d", i);
break;
case computeSelfExclsType:
sprintf(user_des, "computeSelfExclsType_%d", i);
break;
case computeSelfBondsType:
sprintf(user_des, "computeSelfBondsType_%d", i);
break;
case computeSelfAnglesType:
sprintf(user_des, "computeSelfAnglesType_%d", i);
break;
case computeSelfDihedralsType:
sprintf(user_des, "computeSelfDihedralsType_%d", i);
break;
case computeSelfImpropersType:
sprintf(user_des, "computeSelfImpropersType_%d", i);
break;
case computeSelfTholeType:
sprintf(user_des, "computeSelfTholeType_%d", i);
break;
case computeSelfAnisoType:
sprintf(user_des, "computeSelfAnisoType_%d", i);
break;
case computeSelfCrosstermsType:
sprintf(user_des, "computeSelfCrosstermsType_%d", i);
break;
#ifdef DPMTA
case computeDPMTAType:
sprintf(user_des, "computeDPMTAType_%d", i);
break;
#endif
#ifdef DPME
case computeDPMEType:
sprintf(user_des, "computeDPMEType_%d", i);
break;
#endif
case computePmeType:
sprintf(user_des, "computePMEType_%d", i);
break;
case computeEwaldType:
sprintf(user_des, "computeEwaldType_%d", i);
break;
case computeFullDirectType:
sprintf(user_des, "computeFullDirectType_%d", i);
break;
case computeGlobalType:
sprintf(user_des, "computeGlobalType_%d", i);
break;
case computeStirType:
sprintf(user_des, "computeStirType_%d", i);
break;
case computeExtType:
sprintf(user_des, "computeExtType_%d", i);
break;
case computeEFieldType:
sprintf(user_des, "computeEFieldType_%d", i);
break;
/* BEGIN gf */
case computeGridForceType:
sprintf(user_des, "computeGridForceType_%d", i);
break;
/* END gf */
case computeSphericalBCType:
sprintf(user_des, "computeSphericalBCType_%d", i);
break;
case computeCylindricalBCType:
sprintf(user_des, "computeCylindricalBCType_%d", i);
break;
case computeTclBCType:
sprintf(user_des, "computeTclBCType_%d", i);
break;
case computeRestraintsType:
sprintf(user_des, "computeRestraintsType_%d", i);
break;
case computeConsForceType:
sprintf(user_des, "computeConsForceType_%d", i);
break;
case computeConsTorqueType:
sprintf(user_des, "computeConsTorqueType_%d", i);
break;
default:
NAMD_bug("Unknown compute type in ComputeMgr::registerUserEventForAllComputeObjs().");
break;
}
int user_des_len = strlen(user_des);
char *user_des_cst = new char[user_des_len+1];
memcpy(user_des_cst, user_des, user_des_len);
user_des_cst[user_des_len] = 0;
//Since the argument in traceRegisterUserEvent is supposed
//to be a const string which will not be copied inside the
//function when a new user event is created, user_des_cst
//has to be allocated in heap.
int reEvenId = traceRegisterUserEvent(user_des_cst, TRACE_COMPOBJ_IDOFFSET+i);
//printf("Register user event (%s) with id (%d)\n", user_des, reEvenId);
}
#else
return;
#endif
}
void
ComputeMgr::createComputes(ComputeMap *map)
{
Node *node = Node::Object();
SimParameters *simParams = node->simParameters;
int myNode = node->myid();
if ( simParams->globalForcesOn && !myNode )
{
DebugM(4,"Mgr running on Node "<<CkMyPe()<<"\n");
/* create a master server to allow multiple masters */
masterServerObject = new GlobalMasterServer(this,
PatchMap::Object()->numNodesWithPatches());
/* create the individual global masters */
// masterServerObject->addClient(new GlobalMasterTest());
if (simParams->tclForcesOn)
masterServerObject->addClient(new GlobalMasterTcl());
if (simParams->IMDon && ! simParams->IMDignore)
masterServerObject->addClient(new GlobalMasterIMD());
if (simParams->SMDOn)
masterServerObject->addClient(
new GlobalMasterSMD(simParams->SMDk, simParams->SMDk2,
simParams->SMDVel,
simParams->SMDDir, simParams->SMDOutputFreq,
simParams->firstTimestep, simParams->SMDFile,
node->molecule->numAtoms)
);
if (simParams->symmetryOn &&
(simParams->firstTimestep < simParams->symmetryLastStep ||
simParams->symmetryLastStep == -1))
masterServerObject->addClient(new GlobalMasterSymmetry());
if (simParams->TMDOn)
masterServerObject->addClient(new GlobalMasterTMD());
if (simParams->miscForcesOn)
masterServerObject->addClient(new GlobalMasterMisc());
if ( simParams->freeEnergyOn )
masterServerObject->addClient(new GlobalMasterFreeEnergy());
if ( simParams->colvarsOn )
masterServerObject->addClient(new GlobalMasterColvars());
}
if ( !myNode && simParams->IMDon && simParams->IMDignore ) {
// GlobalMasterIMD constructor saves pointer to node->IMDOutput object
new GlobalMasterIMD();
}
#ifdef NAMD_CUDA
bool deviceIsMine = ( cuda_device_pe() == CkMyPe() );
#endif
#ifdef NAMD_MIC
bool deviceIsMine = ( mic_device_pe() == CkMyPe() );
#endif
for (int i=0; i < map->nComputes; i++)
{
if ( ! ( i % 100 ) )
{
}
#if defined(NAMD_CUDA) || defined(NAMD_MIC)
switch ( map->type(i) )
{
#ifdef NAMD_CUDA
case computeNonbondedSelfType:
case computeNonbondedPairType:
if ( ! deviceIsMine ) continue;
if ( ! cuda_device_shared_with_pe(map->computeData[i].node) ) continue;
break;
#endif
#ifdef NAMD_MIC
case computeNonbondedSelfType:
if (map->directToDevice(i) != 0) { // If should be directed to the device...
if ( ! deviceIsMine ) continue;
if ( ! mic_device_shared_with_pe(map->computeData[i].node) ) continue;
} else { // ... otherwise, direct to host...
if (map->computeData[i].node != myNode) { continue; }
}
break;
case computeNonbondedPairType:
if (map->directToDevice(i)) { // If should be directed to the device...
if ( ! deviceIsMine ) continue;
if ( ! mic_device_shared_with_pe(map->computeData[i].node) ) continue;
} else { // ... otherwise, direct to host...
if (map->computeData[i].node != myNode) { continue; }
}
break;
#endif
case computeNonbondedCUDAType:
case computeNonbondedMICType:
if ( ! deviceIsMine ) continue;
default:
if ( map->computeData[i].node != myNode ) continue;
}
#else
if ( map->computeData[i].node != myNode ) continue;
#endif
DebugM(1,"Compute " << i << '\n');
DebugM(1," node = " << map->computeData[i].node << '\n');
DebugM(1," type = " << map->computeData[i].type << '\n');
DebugM(1," numPids = " << map->computeData[i].numPids << '\n');
DebugM(1," numPidsAllocated = " << map->computeData[i].numPidsAllocated << '\n');
for (int j=0; j < map->computeData[i].numPids; j++)
{
// DebugM(1," pid " << map->computeData[i].pids[j] << '\n');
if (!((j+1) % 6))
DebugM(1,'\n');
}
DebugM(1,"\n---------------------------------------");
DebugM(1,"---------------------------------------\n");
createCompute(i, map);
}
#ifdef NAMD_CUDA
if ( computeNonbondedCUDAObject ) {
computeNonbondedCUDAObject->assignPatches();
}
#endif
#ifdef NAMD_MIC
if ( computeNonbondedMICObject ) {
computeNonbondedMICObject->assignPatches();
}
#endif
}
#if 0
void ComputeMgr:: sendComputeGlobalConfig(ComputeGlobalConfigMsg *msg)
{
(CProxy_ComputeMgr(CkpvAccess(BOCclass_group).computeMgr)).recvComputeGlobalConfig(msg);
}
void ComputeMgr:: recvComputeGlobalConfig(ComputeGlobalConfigMsg *msg)
{
if ( computeGlobalObject )
{
computeGlobalObject->recvConfig(msg);
}
else if ( ! (PatchMap::Object())->numHomePatches() ) delete msg;
else NAMD_die("ComputeMgr::computeGlobalObject is NULL!");
}
#endif
void ComputeMgr:: sendComputeGlobalData(ComputeGlobalDataMsg *msg)
{
CProxy_ComputeMgr cm(CkpvAccess(BOCclass_group).computeMgr);
cm[0].recvComputeGlobalData(msg);
}
void ComputeMgr:: recvComputeGlobalData(ComputeGlobalDataMsg *msg)
{
if (masterServerObject) // make sure it has been initialized
{
masterServerObject->recvData(msg);
}
else NAMD_die("ComputeMgr::masterServerObject is NULL!");
}
void ComputeMgr:: sendComputeGlobalResults(ComputeGlobalResultsMsg *msg)
{
msg->seq = ++computeGlobalResultsMsgMasterSeq;
thisProxy.recvComputeGlobalResults(msg);
}
void ComputeMgr:: enableComputeGlobalResults()
{
++computeGlobalResultsMsgSeq;
for ( int i=0; i<computeGlobalResultsMsgs.size(); ++i ) {
if ( computeGlobalResultsMsgs[i]->seq == computeGlobalResultsMsgSeq ) {