-
Notifications
You must be signed in to change notification settings - Fork 141
/
MultiDiracDeterminant.2.cpp
1207 lines (1069 loc) · 51.9 KB
/
MultiDiracDeterminant.2.cpp
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
//////////////////////////////////////////////////////////////////////////////////////
// This file is distributed under the University of Illinois/NCSA Open Source License.
// See LICENSE file in top directory for details.
//
// Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
//
// File developed by: Bryan Clark, bclark@Princeton.edu, Princeton University
// Miguel Morales, moralessilva2@llnl.gov, Lawrence Livermore National Laboratory
// Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
// Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
// Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
//
// File created by: Bryan Clark, bclark@Princeton.edu, Princeton University
//////////////////////////////////////////////////////////////////////////////////////
/**@file
* @brief Implement build functions: Function bodies are too big to be in a header file
*/
#include "QMCWaveFunctions/Fermion/MultiDiracDeterminant.h"
#include "Numerics/MatrixOperators.h"
#include "OMPTarget/ompBLAS.hpp"
#include "OMPTarget/ompReductionComplex.hpp"
#include "OhmmsPETE/ompReductionTinyVector.hpp"
namespace qmcplusplus
{
/** shared function used by buildTableMatrix_calculateRatios */
void MultiDiracDeterminant::buildTableMatrix_calculateRatios_impl(
int ref,
ValueType det0,
ValueType* restrict ratios,
const OffloadMatrix<ValueType>& psiinv,
const OffloadMatrix<ValueType>& psi,
OffloadMatrix<ValueType>& table_matrix,
const OffloadVector<int>& data,
const VectorSoaContainer<int, 2, OffloadPinnedAllocator<int>>& pairs,
const OffloadVector<RealType>& sign)
{
{
ScopedTimer local(buildTable_timer);
const size_t num = psi.extent(1);
const size_t npairs = pairs.size();
//MatrixOperators::product_ABt(psiinv,psi,table_matrix);
const int* first = pairs.data(0);
const int* second = pairs.data(1);
for (size_t i = 0; i < npairs; ++i)
{
const int I = first[i];
const int J = second[i];
table_matrix(I, J) = simd::dot(psiinv[I], psi[J], num);
}
}
{
ScopedTimer local(table2ratios_timer);
const int* it2 = data.data();
const size_t nitems = sign.size();
const size_t nb_cols = table_matrix.cols();
// explore Inclusive Scan for OpenMP
for (size_t count = 0; count < nitems; ++count)
{
const size_t n = *it2;
if (count != ref)
ratios[count] = sign[count] * det0 *
(n > MaxSmallDet ? det_calculator_.evaluate(table_matrix, it2 + 1, n)
: calcSmallDeterminant(n, table_matrix.data(), it2 + 1, nb_cols));
it2 += 3 * n + 1;
}
ratios[ref] = det0;
}
}
void MultiDiracDeterminant::mw_buildTableMatrix_calculateRatios_impl(
MultiDiracDetMultiWalkerResource& mw_res,
int ref,
const OffloadVector<ValueType>& det0_list,
const RefVector<OffloadMatrix<ValueType>>& psiinv_list,
const RefVector<OffloadMatrix<ValueType>>& psi_list,
const OffloadVector<int>& data,
const VectorSoaContainer<int, 2, OffloadPinnedAllocator<int>>& pairs,
const OffloadVector<RealType>& sign,
const RefVector<OffloadMatrix<ValueType>>& table_matrix_list,
const RefVector<OffloadVector<ValueType>>& ratios_list)
{
const size_t nw = ratios_list.size();
auto& psiinv_deviceptr_list = mw_res.psiinv_deviceptr_list;
auto& psi_deviceptr_list = mw_res.psi_deviceptr_list;
auto& table_matrix_deviceptr_list = mw_res.table_matrix_deviceptr_list;
auto& ratios_deviceptr_list = mw_res.ratios_deviceptr_list;
const size_t nb_cols_table_matrix(table_matrix_list[0].get().cols());
{
ScopedTimer local(buildTable_timer);
const size_t npairs = pairs.size();
const size_t num = psi_list[0].get().extent(1);
const size_t nitems = sign.size();
const int* first = pairs.data(0);
const int* second = pairs.data(1);
psiinv_deviceptr_list.resize(nw);
psi_deviceptr_list.resize(nw);
table_matrix_deviceptr_list.resize(nw);
ratios_deviceptr_list.resize(nw);
for (size_t iw = 0; iw < nw; iw++)
{
psiinv_deviceptr_list[iw] = psiinv_list[iw].get().device_data();
psi_deviceptr_list[iw] = psi_list[iw].get().device_data();
table_matrix_deviceptr_list[iw] = table_matrix_list[iw].get().device_data();
ratios_deviceptr_list[iw] = ratios_list[iw].get().device_data();
}
const size_t nb_cols_psi(psi_list[0].get().cols());
const size_t nb_cols_psiinv(psiinv_list[0].get().cols());
auto* ratios_list_ptr = ratios_deviceptr_list.data();
auto* table_matrix_list_ptr = table_matrix_deviceptr_list.data();
const auto* psiinv_list_ptr = psiinv_deviceptr_list.data();
const auto* psi_list_ptr = psi_deviceptr_list.data();
{
ScopedTimer local_timer(offload_timer);
PRAGMA_OFFLOAD("omp target teams distribute parallel for collapse(2) \
map(always, to: psiinv_list_ptr[:nw], psi_list_ptr[:nw]) \
map(always, to: ratios_list_ptr[:nw], table_matrix_list_ptr[:nw]) \
map(to:first[:npairs], second[:npairs])")
for (size_t iw = 0; iw < nw; iw++)
for (size_t i = 0; i < npairs; ++i)
{
const int I = first[i];
const int J = second[i];
ValueType table_matrix_local = 0.0;
for (size_t ind = 0; ind < num; ind++)
table_matrix_local +=
psiinv_list_ptr[iw][I * nb_cols_psiinv + ind] * psi_list_ptr[iw][J * nb_cols_psi + ind];
table_matrix_list_ptr[iw][I * nb_cols_table_matrix + J] = table_matrix_local;
}
}
}
{
ScopedTimer local(table2ratios_timer);
const int max_ext_level = ndets_per_excitation_level_->size() - 1;
// Compute workload changes drastically as the excitation level increases.
// this may need different parallelization strategy.
size_t det_offset = 1;
size_t data_offset = 1;
auto update_offsets = [&](size_t ext_level) {
det_offset += (*ndets_per_excitation_level_)[ext_level];
data_offset += (*ndets_per_excitation_level_)[ext_level] * (3 * ext_level + 1);
};
mw_updateRatios_det0(det0_list, ratios_deviceptr_list);
if (max_ext_level >= 1)
{
mw_updateRatios<1>(det_offset, data_offset, data, sign, table_matrix_deviceptr_list, nb_cols_table_matrix,
ratios_deviceptr_list);
update_offsets(1);
}
if (max_ext_level >= 2)
{
mw_updateRatios<2>(det_offset, data_offset, data, sign, table_matrix_deviceptr_list, nb_cols_table_matrix,
ratios_deviceptr_list);
update_offsets(2);
}
if (max_ext_level >= 3)
{
mw_updateRatios<3>(det_offset, data_offset, data, sign, table_matrix_deviceptr_list, nb_cols_table_matrix,
ratios_deviceptr_list);
update_offsets(3);
}
if (max_ext_level >= 4)
{
mw_updateRatios<4>(det_offset, data_offset, data, sign, table_matrix_deviceptr_list, nb_cols_table_matrix,
ratios_deviceptr_list);
update_offsets(4);
}
if (max_ext_level >= 5)
{
mw_updateRatios<5>(det_offset, data_offset, data, sign, table_matrix_deviceptr_list, nb_cols_table_matrix,
ratios_deviceptr_list);
update_offsets(5);
}
if (max_ext_level >= 6)
{
for (size_t iw = 0; iw < nw; iw++)
table_matrix_list[iw].get().updateFrom();
for (size_t ext_level = 6; ext_level <= max_ext_level; ext_level++)
{
mw_updateRatios_generic(ext_level, det_offset, data_offset, det_calculator_, data, sign, table_matrix_list,
ratios_list);
update_offsets(ext_level);
}
// FIXME need to transfer the part of det ratios ext_level >= 6 to the device.
}
}
}
void MultiDiracDeterminant::buildTableMatrix_calculateRatios(
int ref,
const OffloadMatrix<ValueType>& psiinv,
const OffloadMatrix<ValueType>& psi,
const OffloadVector<int>& data,
const VectorSoaContainer<int, 2, OffloadPinnedAllocator<int>>& pairs,
const OffloadVector<RealType>& sign,
OffloadMatrix<ValueType>& table_matrix,
OffloadVector<ValueType>& ratios)
{
ScopedTimer local_timer(calculateRatios_timer);
buildTableMatrix_calculateRatios_impl(ref, ValueType(1), ratios.data(), psiinv, psi, table_matrix, data, pairs, sign);
}
void MultiDiracDeterminant::mw_buildTableMatrix_calculateRatios(
MultiDiracDetMultiWalkerResource& mw_res,
int ref,
const OffloadVector<ValueType>& det0_list,
const RefVector<OffloadMatrix<ValueType>>& psiinv_list,
const RefVector<OffloadMatrix<ValueType>>& psi_list,
const OffloadVector<int>& data,
const VectorSoaContainer<int, 2, OffloadPinnedAllocator<int>>& pairs,
const OffloadVector<RealType>& sign,
const RefVector<OffloadMatrix<ValueType>>& table_matrix_list,
const RefVector<OffloadVector<ValueType>>& ratios_list)
{
ScopedTimer local_timer(calculateRatios_timer);
mw_buildTableMatrix_calculateRatios_impl(mw_res, ref, det0_list, psiinv_list, psi_list, data, pairs, sign,
table_matrix_list, ratios_list);
{
ScopedTimer local_timer(transferD2H_timer);
for (size_t iw = 0; iw < ratios_list.size(); iw++)
ratios_list[iw].get().updateFrom();
}
}
void MultiDiracDeterminant::buildTableMatrix_calculateGradRatios(
int ref,
const OffloadMatrix<ValueType>& psiinv,
const OffloadMatrix<ValueType>& psi,
const OffloadVector<int>& data,
const VectorSoaContainer<int, 2, OffloadPinnedAllocator<int>>& pairs,
const OffloadVector<RealType>& sign,
const ValueType& det0_grad,
OffloadMatrix<ValueType>& table_matrix,
int dx,
int iat,
Matrix<GradType>& grads)
{
ScopedTimer local_timer(calculateGradRatios_timer);
buildTableMatrix_calculateRatios_impl(ref, det0_grad, WorkSpace.data(), psiinv, psi, table_matrix, data, pairs, sign);
for (size_t count = 0; count < getNumDets(); ++count)
grads(count, iat)[dx] = WorkSpace[count];
}
void MultiDiracDeterminant::mw_buildTableMatrix_calculateGradRatios(
MultiDiracDetMultiWalkerResource& mw_res,
int ref,
int iat,
int dx,
int getNumDets,
const OffloadVector<ValueType>& det0_grad_list,
const RefVector<OffloadMatrix<ValueType>>& psiinv_list,
const RefVector<OffloadMatrix<ValueType>>& psi_list,
const OffloadVector<int>& data,
const VectorSoaContainer<int, 2, OffloadPinnedAllocator<int>>& pairs,
const OffloadVector<RealType>& sign,
const RefVector<OffloadVector<ValueType>>& WorkSpace_list,
const RefVector<OffloadMatrix<ValueType>>& table_matrix_list,
UnpinnedOffloadMatrix<ValueType>& mw_grads)
{
ScopedTimer local_timer(calculateGradRatios_timer);
mw_buildTableMatrix_calculateRatios_impl(mw_res, ref, det0_grad_list, psiinv_list, psi_list, data, pairs, sign,
table_matrix_list, WorkSpace_list);
const size_t nw = WorkSpace_list.size();
OffloadVector<ValueType*> WorkSpace_deviceptr_list(nw);
for (size_t iw = 0; iw < nw; iw++)
WorkSpace_deviceptr_list[iw] = WorkSpace_list[iw].get().device_data();
auto* WorkSpace_list_ptr = WorkSpace_deviceptr_list.data();
auto* mw_grads_ptr = mw_grads.data();
const size_t Grads_cols = mw_grads.cols();
PRAGMA_OFFLOAD("omp target teams distribute parallel for collapse(2) map(from:mw_grads_ptr[:mw_grads.size()]) \
map(always, to:WorkSpace_list_ptr[:nw])")
for (size_t iw = 0; iw < nw; iw++)
for (size_t count = 0; count < getNumDets; ++count)
mw_grads_ptr[(3 * iw + dx) * Grads_cols + count] = WorkSpace_list_ptr[iw][count];
}
void MultiDiracDeterminant::buildTableMatrix_calculateRatiosValueMatrixOneParticle(
int ref,
const OffloadMatrix<ValueType>& psiinv,
const OffloadMatrix<ValueType>& psi,
const OffloadVector<int>& data,
const VectorSoaContainer<int, 2, OffloadPinnedAllocator<int>>& pairs,
const OffloadVector<RealType>& sign,
OffloadMatrix<ValueType>& table_matrix,
int iat,
Matrix<ValueType>& ratios)
{
const ValueType det0 = ratios(ref, iat);
buildTableMatrix_calculateRatios_impl(ref, det0, WorkSpace.data(), psiinv, psi, table_matrix, data, pairs, sign);
//splatt
for (size_t count = 0; count < getNumDets(); ++count)
ratios(count, iat) = WorkSpace[count];
#if 0
ValueType det0 = ratios(ref,iat);
int num=psi.extent(1);
std::vector<std::pair<int,int> >::iterator it(pairs.begin()), last(pairs.end());
while(it != last)
{
table_matrix((*it).first,(*it).second) = simd::dot(psiinv[(*it).first],psi[(*it).second],num);
it++;
}
std::vector<int>::iterator it2 = data.begin();
int count= 0; // number of determinants processed
while(it2 != data.end())
{
int n = *it2; // number of excitations
if(count == ref)
{
it2+=3*n+1; // number of integers used to encode the current excitation
count++;
continue;
}
ratios(count,iat) = sign[count]*det0*CustomizedMatrixDet(n,table_matrix,it2+1);
count++;
it2+=3*n+1;
}
#endif
}
void MultiDiracDeterminant::mw_evaluateDetsForPtclMove(const RefVectorWithLeader<MultiDiracDeterminant>& det_list,
const RefVectorWithLeader<ParticleSet>& P_list,
int iat)
{
const int nw = det_list.size();
MultiDiracDeterminant& det_leader = det_list.getLeader();
RefVectorWithLeader<SPOSet> phi_list(*det_leader.getPhi());
ScopedTimer local_timer(det_leader.evaluateDetsForPtclMove_timer);
RefVector<OffloadVector<ValueType>> psiV_list, new_ratios_to_ref_list;
RefVector<OffloadMatrix<ValueType>> TpsiM_list, psiM_list, table_matrix_list;
RefVector<OffloadMatrix<ValueType>> psiMinv_temp_list, psiMinv_list;
phi_list.reserve(nw);
psiV_list.reserve(nw);
psiMinv_list.reserve(nw);
psiMinv_temp_list.reserve(nw);
table_matrix_list.reserve(nw);
TpsiM_list.reserve(nw);
psiM_list.reserve(nw);
new_ratios_to_ref_list.reserve(nw);
for (size_t iw = 0; iw < nw; iw++)
{
MultiDiracDeterminant& det = (det_list[iw]);
det.UpdateMode = ORB_PBYP_PARTIAL;
phi_list.push_back(*det.Phi);
psiV_list.push_back(det.psiV);
psiMinv_list.push_back(det.psiMinv);
psiM_list.push_back(det.psiM);
psiMinv_temp_list.push_back(det.psiMinv_temp);
new_ratios_to_ref_list.push_back(det.new_ratios_to_ref_);
table_matrix_list.push_back(det.table_matrix);
TpsiM_list.push_back(det.TpsiM);
}
det_leader.UpdateMode = ORB_PBYP_RATIO;
const int WorkingIndex = iat - det_leader.FirstIndex;
{
ScopedTimer local_timer(det_leader.evalOrbValue_timer);
for (size_t iw = 0; iw < nw; iw++)
{
MultiDiracDeterminant& det = (det_list[iw]);
Vector<ValueType> psiV_list_host_view(psiV_list[iw].get().data(), psiV_list[iw].get().size());
det.getPhi()->evaluateValue(P_list[iw], iat, psiV_list_host_view);
///Transfer of data from host to Device
{
ScopedTimer local_timer(det.transferH2D_timer);
psiV_list[iw].get().updateTo();
}
}
}
size_t success = 0;
int dummy_handle = 0;
const auto psiMinv_rows = psiMinv_list[0].get().rows();
const auto psiMinv_cols = psiMinv_list[0].get().cols();
const auto TpsiM_cols = TpsiM_list[0].get().cols();
const auto psiM_cols = psiM_list[0].get().cols();
const auto TpsiM_rows = TpsiM_list[0].get().rows();
const auto NumPtcls = det_leader.NumPtcls;
const auto NumOrbitals = det_leader.NumOrbitals;
const auto& confgList = *det_leader.ciConfigList;
auto& mw_res = det_leader.mw_res_handle_.getResource();
auto* psiV_list_devptr = mw_res.psiV_deviceptr_list.device_data();
auto* psiV_temp_list_ptr = mw_res.psiV_temp_deviceptr_list.data();
auto* psiMinv_list_devptr = mw_res.psiMinv_deviceptr_list.device_data();
auto* psiMinv_temp_list_devptr = mw_res.psiMinv_temp_deviceptr_list.device_data();
auto* TpsiM_list_devptr = mw_res.TpsiM_deviceptr_list.device_data();
auto* psiM_list_ptr = mw_res.psiM_deviceptr_list.data();
auto& curRatio_list = mw_res.curRatio_list;
curRatio_list.resize(nw);
auto* curRatio_list_ptr = curRatio_list.data();
auto& inv_curRatio_list = mw_res.inv_curRatio_list;
inv_curRatio_list.resize(nw);
auto* inv_curRatio_list_ptr = inv_curRatio_list.data();
auto* confgListOccup_ptr = det_leader.refdet_occup->data();
{
success = ompBLAS::copy_batched(dummy_handle, psiMinv_rows * psiMinv_cols, psiMinv_list_devptr, 1,
psiMinv_temp_list_devptr, 1, nw);
if (success != 0)
throw std::runtime_error("In MultiDiracDeterminant ompBLAS::copy_batched_offset failed.");
success = ompBLAS::copy_batched_offset(dummy_handle, det_leader.NumOrbitals, psiV_list_devptr, 0, 1,
TpsiM_list_devptr, WorkingIndex, TpsiM_cols, nw);
if (success != 0)
throw std::runtime_error("In MultiDiracDeterminant ompBLAS::copy_batched_offset failed.");
PRAGMA_OFFLOAD("omp target teams distribute map(always, from:curRatio_list_ptr[:nw]) \
is_device_ptr(psiV_list_devptr, psiMinv_temp_list_devptr)")
for (size_t iw = 0; iw < nw; iw++)
{
ValueType c_ratio = 0.0;
PRAGMA_OFFLOAD("omp parallel for reduction(+ : c_ratio)")
for (size_t jc = 0; jc < NumPtcls; jc++)
{
const size_t J = confgListOccup_ptr[jc];
psiV_temp_list_ptr[iw][jc] = psiV_list_devptr[iw][J];
size_t ic = jc * psiMinv_cols;
c_ratio += (psiMinv_temp_list_devptr[iw] + WorkingIndex)[ic] * psiV_temp_list_ptr[iw][jc];
}
curRatio_list_ptr[iw] = c_ratio;
inv_curRatio_list_ptr[iw] = ValueType(1) / c_ratio;
}
det_leader.mw_InverseUpdateByColumn(det_leader.mw_res_handle_, WorkingIndex, inv_curRatio_list,
mw_res.psiV_temp_deviceptr_list, mw_res.psiMinv_temp_deviceptr_list,
psiMinv_rows);
///This is needed by acceptMove. Eventually acceptMove will need to become mw_acceptMove.
{
ScopedTimer local_timer(det_leader.transferD2H_timer);
for (size_t iw = 0; iw < nw; iw++)
psiMinv_temp_list[iw].get().updateFrom();
}
auto& det0_list = mw_res.cone_vec;
det_leader.mw_buildTableMatrix_calculateRatios(det_leader.mw_res_handle_, det_leader.ReferenceDeterminant,
det0_list, psiMinv_temp_list, TpsiM_list, *det_leader.detData,
*det_leader.uniquePairs, *det_leader.DetSigns, table_matrix_list,
new_ratios_to_ref_list);
// restore the modified column of TpsiM.
PRAGMA_OFFLOAD("omp target teams distribute parallel for collapse(2) is_device_ptr(TpsiM_list_devptr) \
map(always, to:psiM_list_ptr[:nw])")
for (size_t iw = 0; iw < nw; iw++)
for (size_t i = 0; i < NumOrbitals; i++)
TpsiM_list_devptr[iw][i * TpsiM_cols + WorkingIndex] = psiM_list_ptr[iw][i + psiM_cols * WorkingIndex];
}
for (size_t iw = 0; iw < nw; iw++)
{
MultiDiracDeterminant& det = (det_list[iw]);
det.curRatio = curRatio_list_ptr[iw];
}
}
void MultiDiracDeterminant::evaluateDetsForPtclMove(const ParticleSet& P, int iat, int refPtcl)
{
ScopedTimer local_timer(evaluateDetsForPtclMove_timer);
UpdateMode = ORB_PBYP_RATIO;
{
ScopedTimer orb_timer(evalOrbValue_timer);
Vector<ValueType> psiV_host_view(psiV.data(), psiV.size());
Phi->evaluateValue(P, iat, psiV_host_view);
}
const int WorkingIndex = (refPtcl < 0 ? iat : refPtcl) - FirstIndex;
assert(WorkingIndex >= 0 && WorkingIndex < LastIndex - FirstIndex);
const auto& confgList = *ciConfigList;
//std::vector<int>::iterator it(confgList[ReferenceDeterminant].occup.begin());
auto it(confgList[ReferenceDeterminant].occup.begin());
// mmorales: the only reason this is here is because
// NonlocalECP do not necessarily call rejectMove after
// calling ratio(), and even if the move is rejected
// this matrix needs to be restored
// If we always restore after ratio, then this is not needed
// For efficiency reasons, I don't do this for ratioGrad or ratio(P,dG,dL)
{
ScopedTimer inverse(updateInverse_timer);
psiMinv_temp = psiMinv;
for (size_t i = 0; i < NumPtcls; i++)
psiV_temp[i] = psiV[*(it++)];
auto ratio_old_ref_det = DetRatioByColumn(psiMinv_temp, psiV_temp, WorkingIndex);
curRatio = ratio_old_ref_det;
InverseUpdateByColumn(psiMinv_temp, psiV_temp, workV1, workV2, WorkingIndex, ratio_old_ref_det);
for (size_t i = 0; i < NumOrbitals; i++)
TpsiM(i, WorkingIndex) = psiV[i];
}
buildTableMatrix_calculateRatios(ReferenceDeterminant, psiMinv_temp, TpsiM, *detData, *uniquePairs, *DetSigns,
table_matrix, new_ratios_to_ref_);
// check comment above
for (size_t i = 0; i < NumOrbitals; i++)
TpsiM(i, WorkingIndex) = psiM(WorkingIndex, i);
}
void MultiDiracDeterminant::evaluateDetsAndGradsForPtclMove(const ParticleSet& P, int iat)
{
ScopedTimer local_timer(evaluateDetsAndGradsForPtclMove_timer);
UpdateMode = ORB_PBYP_PARTIAL;
{
ScopedTimer local_timer(evalOrbVGL_timer);
// Using Host Views for Phi-evaluateVGL since not ported to GPU
Vector<ValueType> psiV_host_view(psiV.data(), psiV.size());
Vector<GradType> dpsiV_host_view(dpsiV.data(), dpsiV.size());
Vector<ValueType> d2psiV_host_view(d2psiV.data(), d2psiV.size());
Phi->evaluateVGL(P, iat, psiV_host_view, dpsiV_host_view, d2psiV_host_view);
}
const int WorkingIndex = iat - FirstIndex;
const auto& confgList = *ciConfigList;
assert(WorkingIndex >= 0 && WorkingIndex < LastIndex - FirstIndex);
GradType ratioGradRef;
{
ScopedTimer inverse(updateInverse_timer);
//mmorales: check comment above
psiMinv_temp = psiMinv;
//std::vector<int>::iterator it(confgList[ReferenceDeterminant].occup.begin());
auto it(confgList[ReferenceDeterminant].occup.begin());
for (size_t i = 0; i < NumPtcls; i++)
{
psiV_temp[i] = psiV[*it];
ratioGradRef += psiMinv_temp(i, WorkingIndex) * dpsiV[*it];
it++;
}
curRatio = DetRatioByColumn(psiMinv_temp, psiV_temp, WorkingIndex);
InverseUpdateByColumn(psiMinv_temp, psiV_temp, workV1, workV2, WorkingIndex, curRatio);
for (size_t i = 0; i < NumOrbitals; i++)
TpsiM(i, WorkingIndex) = psiV[i];
}
buildTableMatrix_calculateRatios(ReferenceDeterminant, psiMinv_temp, TpsiM, *detData, *uniquePairs, *DetSigns,
table_matrix, new_ratios_to_ref_);
for (size_t idim = 0; idim < OHMMS_DIM; idim++)
{
{
ScopedTimer inverse(updateInverse_timer);
//dpsiMinv = psiMinv_temp;
dpsiMinv = psiMinv;
auto it(confgList[ReferenceDeterminant].occup.begin());
for (size_t i = 0; i < NumPtcls; i++)
psiV_temp[i] = dpsiV[*(it++)][idim];
InverseUpdateByColumn(dpsiMinv, psiV_temp, workV1, workV2, WorkingIndex, ratioGradRef[idim]);
for (size_t i = 0; i < NumOrbitals; i++)
TpsiM(i, WorkingIndex) = dpsiV[i][idim];
}
buildTableMatrix_calculateGradRatios(ReferenceDeterminant, dpsiMinv, TpsiM, *detData, *uniquePairs, *DetSigns,
ratioGradRef[idim] / curRatio, table_matrix, idim, WorkingIndex, new_grads);
}
// check comment above
for (int i = 0; i < NumOrbitals; i++)
TpsiM(i, WorkingIndex) = psiM(WorkingIndex, i);
}
void MultiDiracDeterminant::evaluateDetsAndGradsForPtclMoveWithSpin(const ParticleSet& P, int iat)
{
assert(P.isSpinor() == is_spinor_);
ScopedTimer local_timer(evaluateDetsAndGradsForPtclMove_timer);
UpdateMode = ORB_PBYP_PARTIAL;
{
ScopedTimer orb_timer(evalOrbVGL_timer);
// Creating Host view to call Phi->evaluateVGL
Vector<ValueType> psiV_host_view(psiV.data(), psiV.size());
Vector<GradType> dpsiV_host_view(dpsiV.data(), dpsiV.size());
Vector<ValueType> d2psiV_host_view(d2psiV.data(), d2psiV.size());
Phi->evaluateVGL_spin(P, iat, psiV_host_view, dpsiV_host_view, d2psiV_host_view, dspin_psiV);
}
const int WorkingIndex = iat - FirstIndex;
assert(WorkingIndex >= 0 && WorkingIndex < LastIndex - FirstIndex);
const auto& confgList = *ciConfigList;
GradType ratioGradRef;
ValueType ratioSpinGradRef = 0.0;
{
ScopedTimer inverse(updateInverse_timer);
//mmorales: check comment above
psiMinv_temp = psiMinv;
//std::vector<int>::iterator it(confgList[ReferenceDeterminant].occup.begin());
auto it(confgList[ReferenceDeterminant].occup.begin());
for (size_t i = 0; i < NumPtcls; i++)
{
psiV_temp[i] = psiV[*it];
ratioGradRef += psiMinv_temp(i, WorkingIndex) * dpsiV[*it];
ratioSpinGradRef += psiMinv_temp(i, WorkingIndex) * dspin_psiV[*it];
it++;
}
curRatio = DetRatioByColumn(psiMinv_temp, psiV_temp, WorkingIndex);
new_spingrads(ReferenceDeterminant, WorkingIndex) = ratioSpinGradRef / curRatio;
InverseUpdateByColumn(psiMinv_temp, psiV_temp, workV1, workV2, WorkingIndex, curRatio);
for (size_t i = 0; i < NumOrbitals; i++)
TpsiM(i, WorkingIndex) = psiV[i];
}
buildTableMatrix_calculateRatios(ReferenceDeterminant, psiMinv_temp, TpsiM, *detData, *uniquePairs, *DetSigns,
table_matrix, new_ratios_to_ref_);
for (size_t idim = 0; idim < OHMMS_DIM; idim++)
{
{
ScopedTimer inverse(updateInverse_timer);
//dpsiMinv = psiMinv_temp;
dpsiMinv = psiMinv;
auto it(confgList[ReferenceDeterminant].occup.begin());
for (size_t i = 0; i < NumPtcls; i++)
psiV_temp[i] = dpsiV[*(it++)][idim];
InverseUpdateByColumn(dpsiMinv, psiV_temp, workV1, workV2, WorkingIndex, ratioGradRef[idim]);
for (size_t i = 0; i < NumOrbitals; i++)
TpsiM(i, WorkingIndex) = dpsiV[i][idim];
}
buildTableMatrix_calculateGradRatios(ReferenceDeterminant, dpsiMinv, TpsiM, *detData, *uniquePairs, *DetSigns,
ratioGradRef[idim] / curRatio, table_matrix, idim, WorkingIndex, new_grads);
}
//Now compute the spin gradient, same procedure as normal gradient components above
{
ScopedTimer inverse(updateInverse_timer);
dpsiMinv = psiMinv;
auto it(confgList[ReferenceDeterminant].occup.begin());
for (size_t i = 0; i < NumPtcls; i++)
psiV_temp[i] = dspin_psiV[*(it++)];
InverseUpdateByColumn(dpsiMinv, psiV_temp, workV1, workV2, WorkingIndex, ratioSpinGradRef);
for (size_t i = 0; i < NumOrbitals; i++)
TpsiM(i, WorkingIndex) = dspin_psiV[i];
}
buildTableMatrix_calculateRatiosValueMatrixOneParticle(ReferenceDeterminant, dpsiMinv, TpsiM, *detData, *uniquePairs,
*DetSigns, table_matrix, WorkingIndex, new_spingrads);
// check comment above
for (int i = 0; i < NumOrbitals; i++)
TpsiM(i, WorkingIndex) = psiM(WorkingIndex, i);
}
void MultiDiracDeterminant::mw_evaluateDetsAndGradsForPtclMove(
const RefVectorWithLeader<MultiDiracDeterminant>& det_list,
const RefVectorWithLeader<ParticleSet>& P_list,
int iat,
UnpinnedOffloadMatrix<ValueType>& mw_grads)
{
const int nw = det_list.size();
MultiDiracDeterminant& det_leader = det_list.getLeader();
RefVectorWithLeader<SPOSet> phi_list(*det_leader.getPhi());
ScopedTimer local_timer(det_leader.evaluateDetsAndGradsForPtclMove_timer);
int success = 0;
int dummy_handle = 0;
const size_t NumOrbitals(det_leader.NumOrbitals);
const size_t NumPtcls(det_leader.NumPtcls);
RefVector<OffloadVector<ValueType>> psiV_list, psiV_temp_list, new_ratios_to_ref_list, WorkSpace_list;
RefVector<OffloadVector<ValueType>> d2psiV_list;
RefVector<OffloadMatrix<ValueType>> psiMinv_temp_list, psiMinv_list, dpsiMinv_list;
RefVector<OffloadMatrix<ValueType>> table_matrix_list, psiM_list, TpsiM_list;
RefVector<OffloadVector<GradType>> dpsiV_list;
phi_list.reserve(nw);
psiV_list.reserve(nw);
dpsiV_list.reserve(nw);
d2psiV_list.reserve(nw);
psiV_temp_list.reserve(nw);
psiMinv_temp_list.reserve(nw);
psiMinv_list.reserve(nw);
psiM_list.reserve(nw);
TpsiM_list.reserve(nw);
new_ratios_to_ref_list.reserve(nw);
table_matrix_list.reserve(nw);
dpsiMinv_list.reserve(nw);
WorkSpace_list.reserve(nw);
auto& mw_res = det_leader.mw_res_handle_.getResource();
auto& ratioGradRef_list = mw_res.ratioGradRef_list;
auto& det0_grad_list = mw_res.det0_grad_list;
ratioGradRef_list.resize(nw);
det0_grad_list.resize(nw);
det_leader.UpdateMode = ORB_PBYP_PARTIAL;
const int WorkingIndex = iat - det_leader.FirstIndex;
for (size_t iw = 0; iw < nw; iw++)
{
MultiDiracDeterminant& det = (det_list[iw]);
det.UpdateMode = ORB_PBYP_PARTIAL;
phi_list.push_back(*det.Phi);
psiV_list.push_back(det.psiV);
dpsiV_list.push_back(det.dpsiV);
d2psiV_list.push_back(det.d2psiV);
psiV_temp_list.push_back(det.psiV_temp);
psiMinv_list.push_back(det.psiMinv);
psiM_list.push_back(det.psiM);
psiMinv_temp_list.push_back(det.psiMinv_temp);
new_ratios_to_ref_list.push_back(det.new_ratios_to_ref_);
TpsiM_list.push_back(det.TpsiM);
table_matrix_list.push_back(det.table_matrix);
dpsiMinv_list.push_back(det.dpsiMinv);
WorkSpace_list.push_back(det.WorkSpace);
}
{
ScopedTimer local_timer(det_leader.evalOrbVGL_timer);
for (size_t iw = 0; iw < nw; iw++)
{
MultiDiracDeterminant& det = (det_list[iw]);
Vector<ValueType> psiV_list_host_view(psiV_list[iw].get().data(), psiV_list[iw].get().size());
Vector<GradType> dpsiV_list_host_view(dpsiV_list[iw].get().data(), dpsiV_list[iw].get().size());
Vector<ValueType> d2psiV_list_host_view(d2psiV_list[iw].get().data(), d2psiV_list[iw].get().size());
det.Phi->evaluateVGL(P_list[iw], iat, psiV_list_host_view, dpsiV_list_host_view, d2psiV_list_host_view);
{
ScopedTimer local_timer(det_leader.transferH2D_timer);
psiV_list[iw].get().updateTo();
dpsiV_list[iw].get().updateTo();
}
}
}
const auto psiMinv_rows = psiMinv_list[0].get().rows();
const auto psiMinv_cols = psiMinv_list[0].get().cols();
const auto TpsiM_num_cols = TpsiM_list[0].get().cols();
const auto psiM_num_cols = psiM_list[0].get().cols();
const auto& confgList = *det_leader.ciConfigList;
auto* psiV_list_devptr = mw_res.psiV_deviceptr_list.device_data();
auto* psiV_temp_list_ptr = mw_res.psiV_temp_deviceptr_list.data();
auto* TpsiM_list_devptr = mw_res.TpsiM_deviceptr_list.device_data();
auto* psiM_list_ptr = mw_res.psiM_deviceptr_list.data();
auto* psiMinv_list_devptr = mw_res.psiMinv_deviceptr_list.device_data();
auto* dpsiMinv_list_devptr = mw_res.dpsiMinv_deviceptr_list.device_data();
auto* psiMinv_temp_list_devptr = mw_res.psiMinv_temp_deviceptr_list.device_data();
auto& curRatio_list = mw_res.curRatio_list;
curRatio_list.resize(nw);
auto* curRatio_list_ptr = curRatio_list.data();
auto& inv_curRatio_list = mw_res.inv_curRatio_list;
inv_curRatio_list.resize(nw);
auto* inv_curRatio_list_ptr = inv_curRatio_list.data();
auto* det0_grad_list_ptr = det0_grad_list.data();
auto* confgListOccup_ptr = det_leader.refdet_occup->data();
auto* dpsiV_list_ptr = mw_res.dpsiV_deviceptr_list.data();
auto* ratioGradRef_list_ptr = ratioGradRef_list.data();
{
success = ompBLAS::copy_batched(dummy_handle, psiMinv_rows * psiMinv_cols, psiMinv_list_devptr, 1,
psiMinv_temp_list_devptr, 1, nw);
if (success != 0)
throw std::runtime_error("In MultiDiracDeterminant ompBLAS::copy_batched_offset failed.");
PRAGMA_OFFLOAD("omp target teams distribute is_device_ptr(psiV_list_devptr, psiMinv_temp_list_devptr) \
map(always, from:curRatio_list_ptr[:nw])")
for (size_t iw = 0; iw < nw; iw++)
{
GradType ratioGradRef_local(0);
PRAGMA_OFFLOAD("omp parallel for reduction(+ : ratioGradRef_local)")
for (size_t i = 0; i < NumPtcls; i++)
{
const size_t J = confgListOccup_ptr[i];
psiV_temp_list_ptr[iw][i] = psiV_list_devptr[iw][J];
ratioGradRef_local += psiMinv_temp_list_devptr[iw][i * psiMinv_cols + WorkingIndex] * dpsiV_list_ptr[iw][J];
}
ratioGradRef_list_ptr[iw] = ratioGradRef_local;
ValueType c_ratio = 0.0;
PRAGMA_OFFLOAD("omp parallel for reduction(+ : c_ratio)")
for (size_t jc = 0; jc < psiMinv_cols; jc += 1)
{
const size_t ic = jc * psiMinv_cols;
c_ratio += (psiMinv_temp_list_devptr[iw] + WorkingIndex)[ic] * psiV_temp_list_ptr[iw][jc];
}
curRatio_list_ptr[iw] = c_ratio;
inv_curRatio_list_ptr[iw] = ValueType(1) / c_ratio;
}
success = ompBLAS::copy_batched_offset(dummy_handle, det_leader.NumOrbitals, psiV_list_devptr, 0, 1,
TpsiM_list_devptr, WorkingIndex, TpsiM_num_cols, nw);
if (success != 0)
throw std::runtime_error("In MultiDiracDeterminant ompBLAS::copy_batched_offset failed.");
det_leader.mw_InverseUpdateByColumn(det_leader.mw_res_handle_, WorkingIndex, inv_curRatio_list,
mw_res.psiV_temp_deviceptr_list, mw_res.psiMinv_temp_deviceptr_list,
psiMinv_rows);
///This is needed by Host in acceptMove. Eventually acceptMove will need to become mw_acceptMove.
{
ScopedTimer local_timer(det_leader.transferD2H_timer);
for (size_t iw = 0; iw < nw; iw++)
psiMinv_temp_list[iw].get().updateFrom();
}
auto& det0_list = mw_res.cone_vec;
det_leader.mw_buildTableMatrix_calculateRatios(det_leader.mw_res_handle_, det_leader.ReferenceDeterminant,
det0_list, psiMinv_temp_list, TpsiM_list, *det_leader.detData,
*det_leader.uniquePairs, *det_leader.DetSigns, table_matrix_list,
new_ratios_to_ref_list);
for (size_t idim = 0; idim < OHMMS_DIM; idim++)
{
success = ompBLAS::copy_batched(dummy_handle, psiMinv_rows * psiMinv_cols, psiMinv_list_devptr, 1,
dpsiMinv_list_devptr, 1, nw);
if (success != 0)
throw std::runtime_error("In MultiDiracDeterminant ompBLAS::copy_batched_offset failed.");
PRAGMA_OFFLOAD("omp target teams distribute map(to: ratioGradRef_list_ptr[:nw])")
for (size_t iw = 0; iw < nw; iw++)
{
inv_curRatio_list_ptr[iw] = ValueType(1) / ratioGradRef_list_ptr[iw][idim];
for (size_t i = 0; i < NumPtcls; i++)
{
const size_t J = confgListOccup_ptr[i];
psiV_temp_list_ptr[iw][i] = dpsiV_list_ptr[iw][J][idim];
}
}
det_leader.mw_InverseUpdateByColumn(det_leader.mw_res_handle_, WorkingIndex, inv_curRatio_list,
mw_res.psiV_temp_deviceptr_list, mw_res.dpsiMinv_deviceptr_list,
psiMinv_rows);
PRAGMA_OFFLOAD("omp target teams distribute map(to:dpsiV_list_ptr[:nw], curRatio_list_ptr[:nw]) \
map(always,from:det0_grad_list_ptr[:nw]) \
is_device_ptr(TpsiM_list_devptr)")
for (size_t iw = 0; iw < nw; iw++)
{
det0_grad_list_ptr[iw] = ratioGradRef_list_ptr[iw][idim] / curRatio_list_ptr[iw];
for (size_t i = 0; i < NumOrbitals; i++)
TpsiM_list_devptr[iw][i * TpsiM_num_cols + WorkingIndex] = dpsiV_list_ptr[iw][i][idim];
}
det_leader.mw_buildTableMatrix_calculateGradRatios(det_leader.mw_res_handle_, det_leader.ReferenceDeterminant,
WorkingIndex, idim, det_leader.getNumDets(), det0_grad_list,
dpsiMinv_list, TpsiM_list, *det_leader.detData,
*det_leader.uniquePairs, *det_leader.DetSigns, WorkSpace_list,
table_matrix_list, mw_grads);
}
// restore the modified column of TpsiM.
PRAGMA_OFFLOAD("omp target teams distribute parallel for collapse(2) is_device_ptr(TpsiM_list_devptr) \
map(always, to:psiM_list_ptr[:nw])")
for (size_t iw = 0; iw < nw; iw++)
for (size_t i = 0; i < NumOrbitals; i++)
TpsiM_list_devptr[iw][i * TpsiM_num_cols + WorkingIndex] = psiM_list_ptr[iw][i + psiM_num_cols * WorkingIndex];
}
for (size_t iw = 0; iw < nw; iw++)
{
MultiDiracDeterminant& det = (det_list[iw]);
det.curRatio = curRatio_list[iw];
}
}
void MultiDiracDeterminant::evaluateGrads(ParticleSet& P, int iat)
{
const int WorkingIndex = iat - FirstIndex;
assert(WorkingIndex >= 0 && WorkingIndex < LastIndex - FirstIndex);
const auto& confgList = *ciConfigList;
for (size_t idim = 0; idim < OHMMS_DIM; idim++)
{
//dpsiMinv = psiMinv_temp;
dpsiMinv = psiMinv;
auto it = confgList[ReferenceDeterminant].occup.begin();
ValueType ratioG = 0.0;
for (size_t i = 0; i < NumPtcls; i++)
{
psiV_temp[i] = dpsiM(WorkingIndex, *it)[idim];
ratioG += psiMinv(i, WorkingIndex) * dpsiM(WorkingIndex, *it)[idim];
it++;
}
InverseUpdateByColumn(dpsiMinv, psiV_temp, workV1, workV2, WorkingIndex, ratioG);
for (size_t i = 0; i < NumOrbitals; i++)
TpsiM(i, WorkingIndex) = dpsiM(WorkingIndex, i)[idim];
buildTableMatrix_calculateGradRatios(ReferenceDeterminant, dpsiMinv, TpsiM, *detData, *uniquePairs, *DetSigns,
ratioG, table_matrix, idim, WorkingIndex, grads);
}
// check comment above
for (size_t i = 0; i < NumOrbitals; i++)
TpsiM(i, WorkingIndex) = psiM(WorkingIndex, i);
}
void MultiDiracDeterminant::evaluateGradsWithSpin(ParticleSet& P, int iat)
{
assert(P.isSpinor() == is_spinor_);
const int WorkingIndex = iat - FirstIndex;
assert(WorkingIndex >= 0 && WorkingIndex < LastIndex - FirstIndex);
const auto& confgList = *ciConfigList;
for (size_t idim = 0; idim < OHMMS_DIM; idim++)
{
//dpsiMinv = psiMinv_temp;
dpsiMinv = psiMinv;
auto it = confgList[ReferenceDeterminant].occup.begin();
ValueType ratioG = 0.0;
for (size_t i = 0; i < NumPtcls; i++)
{
psiV_temp[i] = dpsiM(WorkingIndex, *it)[idim];
ratioG += psiMinv(i, WorkingIndex) * dpsiM(WorkingIndex, *it)[idim];
it++;
}
InverseUpdateByColumn(dpsiMinv, psiV_temp, workV1, workV2, WorkingIndex, ratioG);
for (size_t i = 0; i < NumOrbitals; i++)
TpsiM(i, WorkingIndex) = dpsiM(WorkingIndex, i)[idim];
buildTableMatrix_calculateGradRatios(ReferenceDeterminant, dpsiMinv, TpsiM, *detData, *uniquePairs, *DetSigns,
ratioG, table_matrix, idim, WorkingIndex, grads);
}
//Now compute the spin gradient, same procedure as normal gradient components above
dpsiMinv = psiMinv;
auto it = confgList[ReferenceDeterminant].occup.begin();
ValueType ratioSG = 0.0;
for (size_t i = 0; i < NumPtcls; i++)
{
psiV_temp[i] = dspin_psiM(WorkingIndex, *it);
ratioSG += psiMinv(i, WorkingIndex) * dspin_psiM(WorkingIndex, *it);
it++;
}
spingrads(ReferenceDeterminant, WorkingIndex) = ratioSG;
InverseUpdateByColumn(dpsiMinv, psiV_temp, workV1, workV2, WorkingIndex, ratioSG);
for (size_t i = 0; i < NumOrbitals; i++)
TpsiM(i, WorkingIndex) = dspin_psiM(WorkingIndex, i);
buildTableMatrix_calculateRatiosValueMatrixOneParticle(ReferenceDeterminant, dpsiMinv, TpsiM, *detData, *uniquePairs,
*DetSigns, table_matrix, WorkingIndex, spingrads);
// check comment above
for (size_t i = 0; i < NumOrbitals; i++)
TpsiM(i, WorkingIndex) = psiM(WorkingIndex, i);
}
void MultiDiracDeterminant::mw_evaluateGrads(const RefVectorWithLeader<MultiDiracDeterminant>& det_list,
const RefVectorWithLeader<ParticleSet>& P_list,
int iat,
UnpinnedOffloadMatrix<ValueType>& mw_grads)
{
const int nw = det_list.size();
MultiDiracDeterminant& det_leader = det_list.getLeader();
const int WorkingIndex = iat - det_leader.FirstIndex;
int success = 0;
int dummy_handle = 0;
const size_t NumOrbitals(det_leader.NumOrbitals);
const size_t NumPtcls(det_leader.NumPtcls);
ScopedTimer local_timer(det_leader.evaluateGrads_timer);
RefVector<OffloadMatrix<ValueType>> dpsiMinv_list, psiMinv_list;
RefVector<OffloadMatrix<GradType>> dpsiM_list;
RefVector<OffloadVector<ValueType>> psiV_temp_list, WorkSpace_list;
RefVector<OffloadMatrix<ValueType>> table_matrix_list, TpsiM_list, psiM_list;
//RefVector<OffloadMatrix<GradType>> grads_list;
psiMinv_list.reserve(nw);
dpsiMinv_list.reserve(nw);
dpsiM_list.reserve(nw);
psiV_temp_list.reserve(nw);
//grads_list.reserve(nw);
table_matrix_list.reserve(nw);
TpsiM_list.reserve(nw);
psiM_list.reserve(nw);
WorkSpace_list.reserve(nw);
for (size_t iw = 0; iw < nw; iw++)
{
MultiDiracDeterminant& det = (det_list[iw]);
psiMinv_list.push_back(det.psiMinv);
dpsiMinv_list.push_back(det.dpsiMinv);
psiV_temp_list.push_back(det.psiV_temp);
dpsiM_list.push_back(det.dpsiM);
//grads_list.push_back(det.grads);