forked from etmc/tmLQCD
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqphix_interface.cpp
2193 lines (1981 loc) · 94.6 KB
/
qphix_interface.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
/***********************************************************************
*
* Copyright (C) 2015 Mario Schroeck
* 2016 Peter Labus
* 2017 Peter Labus, Martin Ueding, Bartosz Kostrzewa
*
* This file is part of tmLQCD.
*
* tmLQCD is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* tmLQCD is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with tmLQCD. If not, see <http://www.gnu.org/licenses/>.
*
***********************************************************************/
#include "qphix_interface.h"
#include "qphix_interface.hpp"
#include "qphix_interface_utils.hpp"
#include "qphix_types.h"
#include "qphix_veclen.h"
#ifdef TM_USE_MPI
#include <mpi.h>
#endif
extern "C" {
#ifdef HAVE_CONFIG_H
#include "tmlqcd_config.h"
#endif
#include "boundary.h"
#include "geometry_eo.h"
#include "gettime.h"
#include "global.h"
#include "struct_accessors.h"
#include "linalg/convert_eo_to_lexic.h"
#include "linalg/diff.h"
#include "linalg/square_norm.h"
#include "linalg/square_norm.h"
#include "misc_types.h"
// for the normalisation of the heavy doublet when running
// RHMC
#include "phmc.h"
#include "start.h"
#include "operator/clover_leaf.h"
#include "operator/clovertm_operators.h"
#include "operator_types.h"
#include "operator/Hopping_Matrix.h"
#include "solver/matrix_mult_typedef.h"
#include "solver/solver_types.h"
#include "solver/solver.h"
#include "solver/solver_field.h"
#include "solver/solver_params.h"
#include "xchange/xchange_gauge.h"
}
#ifdef TM_USE_OMP
#include <omp.h>
#endif
#include <qphix/blas_new_c.h>
#include <qphix/clover.h>
#include <qphix/invbicgstab.h>
#include <qphix/invcg.h>
#include <qphix/inv_richardson_multiprec.h>
#include <qphix/inv_dummy_hermtest.h>
#include <qphix/minvcg.h>
#include <qphix/ndtm_reuse_operator.h>
#include <qphix/ndtm_reuse_operator_clover.h>
#include <qphix/print_utils.h>
#include <qphix/qphix_config.h>
#include <qphix/twisted_mass.h>
#include <qphix/twisted_mass_clover.h>
#include <qphix/wilson.h>
#include <cfloat>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cmath>
using namespace tmlqcd;
tm_QPhiXParams_t qphix_input;
int By;
int Bz;
int NCores;
int Sy;
int Sz;
int PadXY;
int PadXYZ;
int MinCt;
int N_simt;
bool compress12;
QphixPrec_t qphix_precision;
QphixPrec_t qphix_inner_precision;
int subLattSize[4];
int lattSize[4];
int qmp_geom[4];
int qmp_tm_map[4];
// angles for boundary phases, values come from read_input
extern double X0, X1, X2, X3;
bool use_tbc[4];
double tbc_phases[4][2];
// we always use twisted boundary conditions, which means that we are always
// periodic in time and any possible anti-periodicity is implemented via
// the phase
double constexpr t_boundary = 1.0;
template <typename T>
struct rsdTarget {
static const double value;
};
template <>
const double rsdTarget<QPhiX::half>::value = 1.0e-3;
template <>
const double rsdTarget<float>::value = 1.0e-8;
void _initQphix(int argc, char **argv, tm_QPhiXParams_t params, int c12, QphixPrec_t precision_, QphixPrec_t inner_precision_) {
static bool qmp_topo_initialised = false;
// Global Lattice Size
lattSize[0] = LX * g_nproc_x;
lattSize[1] = LY * g_nproc_y;
lattSize[2] = LZ * g_nproc_z;
lattSize[3] = T * g_nproc_t;
// Local Lattice Size
subLattSize[0] = LX;
subLattSize[1] = LY;
subLattSize[2] = LZ;
subLattSize[3] = T;
// extract twisted boundary conditions
for (int dim = 0; dim < 4; dim++) {
bool dim_tbc = false;
double dim_phase[2] = {1.0, 0.0};
if (dim == 0) {
dim_tbc = (fabs(X1) > DBL_EPSILON);
dim_phase[0] = -((double*)(&phase_1))[0] / g_kappa;
dim_phase[1] = -((double*)(&phase_1))[1] / g_kappa;
} else if (dim == 1) {
dim_tbc = (fabs(X2) > DBL_EPSILON);
dim_phase[0] = -((double*)(&phase_2))[0] / g_kappa;
dim_phase[1] = -((double*)(&phase_2))[1] / g_kappa;
} else if (dim == 2) {
dim_tbc = (fabs(X3) > DBL_EPSILON);
dim_phase[0] = -((double*)(&phase_3))[0] / g_kappa;
dim_phase[1] = -((double*)(&phase_3))[1] / g_kappa;
} else if (dim == 3) {
dim_tbc = (fabs(X0) > DBL_EPSILON);
dim_phase[0] = -((double*)(&phase_0))[0] / g_kappa;
dim_phase[1] = -((double*)(&phase_0))[1] / g_kappa;
}
use_tbc[dim] = dim_tbc;
tbc_phases[dim][0] = dim_phase[0];
tbc_phases[dim][1] = dim_phase[1];
}
By = params.By;
Bz = params.Bz;
NCores = params.NCores;
Sy = params.Sy;
Sz = params.Sz;
PadXY = params.PadXY;
PadXYZ = params.PadXYZ;
MinCt = params.MinCt;
N_simt = Sy * Sz;
if (c12 == 8) {
QPhiX::masterPrintf(
"# INFO QphiX: 8-parameter gauge compression not supported, using two row compression "
"instead!\n");
c12 = 12;
}
compress12 = c12 == 12 ? true : false;
qphix_precision = precision_;
qphix_inner_precision = inner_precision_;
#ifdef QPHIX_QMP_COMMS
// Declare the logical topology
if (!qmp_topo_initialised) {
// the QMP topology is the one implied by the number of processes in each
// dimension as required by QPHIX ( x fastest to t slowest running )
qmp_geom[0] = g_nproc_x;
qmp_geom[1] = g_nproc_y;
qmp_geom[2] = g_nproc_z;
qmp_geom[3] = g_nproc_t;
// in order for the topologies to agree between tmLQCD and QPhiX, the dimensions need to be
// permuted
// since Z is fastest in tmLQCD and X is second-slowest
qmp_tm_map[0] = 2;
qmp_tm_map[1] = 1;
qmp_tm_map[2] = 0;
qmp_tm_map[3] = 3;
if (QMP_declare_logical_topology_map(qmp_geom, 4, qmp_tm_map, 4) != QMP_SUCCESS) {
QMP_error("Failed to declare QMP Logical Topology\n");
abort();
}
// longish test to check if the logical coordinates are correctly mapped
if (g_debug_level >= 5) {
for (int proc = 0; proc < g_nproc; proc++) {
if (proc == g_proc_id) {
const int coordinates[4] = {g_proc_coords[1], g_proc_coords[2], g_proc_coords[3],
g_proc_coords[0]};
int id = QMP_get_node_number_from(coordinates);
int *qmp_coords = QMP_get_logical_coordinates_from(id);
fflush(stdout);
printf("QMP id: %3d x:%3d y:%3d z:%3d t:%3d\n", id, qmp_coords[0], qmp_coords[1],
qmp_coords[2], qmp_coords[3]);
printf("MPI id: %3d x:%3d y:%3d z:%3d t:%3d\n\n", g_proc_id, g_proc_coords[1],
g_proc_coords[2], g_proc_coords[3], g_proc_coords[0]);
free(qmp_coords);
fflush(stdout);
MPI_Barrier(MPI_COMM_WORLD);
} else {
MPI_Barrier(MPI_COMM_WORLD);
}
}
}
qmp_topo_initialised = true;
}
#endif
#ifdef QPHIX_QPX_SOURCE
if (thread_bind) {
QPhiX::setThreadAffinity(NCores_user, Sy_user * Sz_user);
}
QPhiX::reportAffinity();
#endif
}
void _initQphix(int argc, char **argv, tm_QPhiXParams_t params, int c12, QphixPrec_t precision_){
_initQphix(argc, argv, params, c12, precision_, precision_);
}
// Finalize the QPhiX library
void _endQphix() {}
template <typename FT, int VECLEN, int SOALEN, bool compress12>
void reorder_clover_to_QPhiX(
QPhiX::Geometry<FT, VECLEN, SOALEN, compress12> &geom,
typename QPhiX::Geometry<FT, VECLEN, SOALEN, compress12>::CloverBlock *qphix_clover, int cb,
bool inverse, bool fl_offdiag = false) {
const double startTime = gettime();
/* the spin-colour clover term in sw_term and the corresponding inverse
* in sw_inv are stored in the tmLQCD gamma basis.
* When we translate spinors to QPhiX, we apply a transformation V to the tmLQCD
* spinor and then apply the same transformation to the output spinor
* ( we have V^dagger = V and V*V = 1 )
* Thus, in order to translate the clover field, we need to copy
* (1+T)' = V*(1+T)*V, where T is the spin-colour clover-term
* This way, the clover term will be in the correct gamma basis.
*
* The tmLQCD clover term is stored in half-spinor blocks of colour matrices
* for which we need to work out what (1+T)'=V*(1+T)*V implies.
* Below, each sAB represents one 3x3 colour matrix
*
* +s33 -s32 0 0
* T' = V*T*V = -s23 +s22 0 0
* 0 0 +s11 -s10
* 0 0 -s01 +s00
*
* Such that the half-spinor blocks are inverted and within these, the ordering is
* reversed. Note that the off-diagonal 3x3 colour blocks are hermitian conjugate to
* each other and this is preserved by the transformation.
*
* The QPhiX (Wilson) clover term is stored as 12 reals on the diagonal
* in two 6-element vectors, one for each half-spinor spin pair
* and two sets of off-diagonal complex components.
*
* In addition, colour matrices are transposed in QPhiX.
*
* The tmLQCD clover term is stored as:
*
* s00 s01
* s11
* T = s22 s23
* s33
*
* with indexing
*
* sw[0][0] sw[1][0]
* sw[2][0]
* sw[0][1] sw[1][1]
* sw[2][1]
*
* The inverse has four su3 blocks instead and is indexed
* sw_inv[0][0] sw_inv[1][0]
* sw_inv[3][0] sw_inv[2][0]
* sw_inv[0][1] sw_inv[1][1]
* sw_inv[3][1] sw_inv[2][1]
*
* where blocks sw_inv[3][0] and sw_inv[3][1] are relevant only when mu > 0
*
* There is a special case for the non-degenerate twisted clover operator. The flavour-off-diagonal
* components of the inverse clover term do not have an imaginary part on the spin-colour diagonal.
* They can thus be stored as CloverBlock, which is done in the QPhiX implementation
* of the ND tmclover operator.
*
* As a hack, this inverse is prepared by sw_invert_epsbar and placed in to the last
* VOLUME/2 sites of sw_inv. Reading from there is triggered by the boolean
* fl_offdiag.
*/
// rescale to get clover term (or its inverse) in the physical normalisation
// rather than the kappa normalisation
const double scale = inverse ? 2.0 * g_kappa : 1.0 / (2.0 * g_kappa);
su3 ***tm_clover = inverse ? sw_inv : sw;
// Number of elements in spin, color & complex
const int Ns = 4;
const int Nc = 3;
const int Nz = 2;
// Geometric parameters for QPhiX data layout
const auto ngy = geom.nGY();
const auto nVecs = geom.nVecs();
const auto Pxy = geom.getPxy();
const auto Pxyz = geom.getPxyz();
// packer for Wilson clover (real diagonal + complex upper-triangular)
/* for the index in the off_diagN arrays, we map to an index in the su3 struct
* keeping in mind complex conjugation
* The off-diagonal in QPhiX is stored as follows:
*
* 0 1 3 6 10
* 2 4 7 11
* 5 8 12
* 9 13
* 14
*
* which we are going to map to su3 in blocks
*
* 0* 1*
* 2*
*
* 3 4 5
* 6 7 8
* 10 11 12
*
* 9* 13*
* 14*
*
* where the asterisk indicates complex conjugation. As a linear array then,
* these mappings are:
*
*/
const int od_su3_offsets[15] = {Nz,
2 * Nz, // 0 1
Nc * Nz + 2 * Nz, // 2
0,
Nz,
2 * Nz, // 3 4 5
Nc * Nz,
Nc * Nz + Nz,
Nc * Nz + 2 * Nz, // 6 7 8
Nz, // 9
2 * Nc * Nz,
2 * Nc * Nz + Nz,
2 * Nc * Nz + 2 * Nz, // 10 11 12
2 * Nz,
Nc * Nz + 2 * Nz}; // 13 14
#pragma omp parallel for collapse(4)
for (int64_t t = 0; t < T; t++) {
for (int64_t z = 0; z < LZ; z++) {
for (int64_t y = 0; y < LY; y++) {
for (int64_t v = 0; v < nVecs; v++) {
int64_t block = (t * Pxyz + z * Pxy) / ngy + (y / ngy) * nVecs + v;
for (int64_t x_soa = 0; x_soa < SOALEN; x_soa++) {
int64_t xx = (y % ngy) * SOALEN + x_soa;
int64_t q_cb_x_coord = x_soa + v * SOALEN;
int64_t tm_x_coord = q_cb_x_coord * 2 + (((t + y + z) & 1) ^ cb);
// the inverse of the clover term is in even-odd ordering
// while the clover term itself is lexicographically ordered
// for the special case of the nd tmclover operator, the inverse of the flavour off-diagonal
// components is stored in the last VOLUME/2 elements of sw_inv
int64_t tm_idx =
(inverse ? g_lexic2eosub[g_ipt[t][tm_x_coord][y][z]] : g_ipt[t][tm_x_coord][y][z]) +
( (inverse && fl_offdiag) ? VOLUME/2 : 0 );
int b_idx;
// we begin with the diagonal elements in CloverBlock
for (int d = 0; d < 6; d++) {
// choose the block in sw which corresponds to the block in T'
b_idx = d < 3 ? 2 : 0;
// get the right colour components
qphix_clover[block].diag1[d][xx] =
QPhiX::rep<FT, double>(
*(reinterpret_cast<double const *const>(&tm_clover[tm_idx][b_idx][1].c00) +
(Nc * Nz + Nz) * (d % 3)) *
scale
);
qphix_clover[block].diag2[d][xx] =
QPhiX::rep<FT, double>(
*(reinterpret_cast<double const *const>(&tm_clover[tm_idx][b_idx][0].c00) +
(Nc * Nz + Nz) * (d % 3)) *
scale
);
}
b_idx = 2; // s33 and s11
for (int od : {0, 1, 2}) {
for (int reim : {0, 1}) {
qphix_clover[block].off_diag1[od][reim][xx] =
QPhiX::rep<FT, double>(
(reim == 1 ? -1.0 : 1.0) *
*(reinterpret_cast<double const *const>(&tm_clover[tm_idx][b_idx][1].c00) +
od_su3_offsets[od] + reim) *
scale
);
qphix_clover[block].off_diag2[od][reim][xx] =
QPhiX::rep<FT, double>(
(reim == 1 ? -1.0 : 1.0) *
*(reinterpret_cast<double const *const>(&tm_clover[tm_idx][b_idx][0].c00) +
od_su3_offsets[od] + reim) *
scale
);
}
}
b_idx = 1; // s32 and s10
for (int od : {3, 4, 5, 6, 7, 8, 10, 11, 12}) {
for (int reim : {0, 1}) {
qphix_clover[block].off_diag1[od][reim][xx] =
QPhiX::rep<FT, double>(
*(reinterpret_cast<double const *const>(&tm_clover[tm_idx][b_idx][1].c00) +
od_su3_offsets[od] + reim) *
(-scale)
);
qphix_clover[block].off_diag2[od][reim][xx] =
QPhiX::rep<FT, double>(
*(reinterpret_cast<double const *const>(&tm_clover[tm_idx][b_idx][0].c00) +
od_su3_offsets[od] + reim) *
(-scale)
);
}
}
b_idx = 0; // s22 and s00
for (int od : {9, 13, 14}) {
for (int reim : {0, 1}) {
qphix_clover[block].off_diag1[od][reim][xx] =
QPhiX::rep<FT, double>(
(reim == 1 ? -1.0 : 1.0) *
*(reinterpret_cast<double const *const>(&tm_clover[tm_idx][b_idx][1].c00) +
od_su3_offsets[od] + reim) *
scale
);
qphix_clover[block].off_diag2[od][reim][xx] =
QPhiX::rep<FT, double>(
(reim == 1 ? -1.0 : 1.0) *
*(reinterpret_cast<double const *const>(&tm_clover[tm_idx][b_idx][0].c00) +
od_su3_offsets[od] + reim) *
scale
);
}
}
} // x_soa
} // for(v)
} // for(y)
} // for(z)
} // for(t)
const double diffTime = gettime() - startTime;
if (g_debug_level > 1) {
QPhiX::masterPrintf(
"# QPHIX-interface: time spent in reorder_clover_to_QPhiX (CloverBlock): %f secs\n",
diffTime);
}
}
template <typename FT, int VECLEN, int SOALEN, bool compress12>
void reorder_clover_to_QPhiX(
QPhiX::Geometry<FT, VECLEN, SOALEN, compress12> &geom,
typename QPhiX::Geometry<FT, VECLEN, SOALEN, compress12>::FullCloverBlock *qphix_clover[2],
int cb, bool inverse) {
const double startTime = gettime();
/* the spin-colour clover term in sw_term and the corresponding inverse
* in sw_inv are stored in the tmLQCD gamma basis.
* When we translate spinors to QPhiX, we apply a transformation V to the tmLQCD
* spinor and then apply the same transformation to the output spinor
* ( we have V^dagger = V and V*V = 1 )
* Thus, in order to translate the clover field, we need to copy
* (1+T)' = V*(1+T)*V, where T is the spin-colour clover-term
* This way, the clover term will be in the correct gamma basis.
*
* The tmLQCD clover term is stored in half-spinor blocks of colour matrices
* for which we need to work out what (1+T)'=V*(1+T)*V implies.
* Below, each sAB represents one 3x3 colour matrix
*
* +s33 -s32 0 0
* T' = V*T*V = -s23 +s22 0 0
* 0 0 +s11 -s10
* 0 0 -s01 +s00
*
* Such that the half-spinor blocks are inverted and within these, the ordering is
* reversed. Note that the off-diagonal 3x3 colour blocks are hermitian conjugate to
* each other and this is preserved by the transformation.
*
* The QPhiX (tmclover) clover term and its inverse are stored as a pair of full
* 6x6 complex matrices which are multiplied with the spinor in exactly the same way
* as in tmLQCD.
*
* The tmLQCD clover term is stored as:
*
* s00 s01
* s11
* T = s22 s23
* s33
*
* with indexing
*
* sw[0][0] sw[1][0]
* sw[2][0]
* sw[0][1] sw[1][1]
* sw[2][1]
*
* The inverse has four su3 blocks instead and is indexed
* sw_inv[0][0] sw_inv[1][0]
* sw_inv[3][0] sw_inv[2][0]
* sw_inv[0][1] sw_inv[1][1]
* sw_inv[3][1] sw_inv[2][1]
*
* where blocks sw_inv[3][0] and sw_inv[3][1] are relevant only when mu > 0 *
*/
// rescale to get clover term (or its inverse) in the physical normalisation
// rather than the kappa normalisation
const double scale = inverse ? 2.0 * g_kappa : 1.0 / (2.0 * g_kappa);
su3 ***tm_clover = inverse ? sw_inv : sw;
// Number of elements in spin, color & complex
const int Ns = 4;
const int Nc = 3;
const int Nz = 2;
const double amu = g_mu / (2.0 * g_kappa);
// Geometric parameters for QPhiX data layout
const auto ngy = geom.nGY();
const auto nVecs = geom.nVecs();
const auto Pxy = geom.getPxy();
const auto Pxyz = geom.getPxyz();
#pragma omp parallel for collapse(4)
for (int64_t t = 0; t < T; t++) {
for (int64_t z = 0; z < LZ; z++) {
for (int64_t y = 0; y < LY; y++) {
for (int64_t v = 0; v < nVecs; v++) {
int64_t block = (t * Pxyz + z * Pxy) / ngy + (y / ngy) * nVecs + v;
for (int64_t x_soa = 0; x_soa < SOALEN; x_soa++) {
int64_t xx = (y % ngy) * SOALEN + x_soa;
int64_t q_cb_x_coord = x_soa + v * SOALEN;
int64_t tm_x_coord = q_cb_x_coord * 2 + (((t + y + z) & 1) ^ cb);
// the inverse of the clover term is in even-odd ordering
// while the clover term itself is lexicographically ordered
int64_t tm_idx =
inverse ? g_lexic2eosub[g_ipt[t][tm_x_coord][y][z]] : g_ipt[t][tm_x_coord][y][z];
for (int fl : {0, 1}) {
if (inverse && fl == 1) {
// the inverse clover term for the second flavour is stored at an offset
tm_idx += VOLUME / 2;
}
for (int q_hs : {0, 1}) {
auto &hs_block =
((q_hs == 0) ? qphix_clover[fl][block].block1 : qphix_clover[fl][block].block2);
for (int q_sc1 = 0; q_sc1 < 6; q_sc1++) {
for (int q_sc2 = 0; q_sc2 < 6; q_sc2++) {
const int q_s1 = q_sc1 / 3;
const int q_s2 = q_sc2 / 3;
const int q_c1 = q_sc1 % 3;
const int q_c2 = q_sc2 % 3;
// invert in spin as required by V*T*V
const int t_hs = 1 - q_hs;
// the indices inside the half-spinor are also inverted
// (which transposes them, of course)
const int t_s1 = 1 - q_s1;
const int t_s2 = 1 - q_s2;
// carry out the mapping from T' to T, keeping in mind that for the inverse
// there are four blocks also on the tmLQCD side, otherwise there are just three
const int t_b_idx = t_s1 + t_s2 + ((inverse && t_s1 == 1 && t_s2 == 0) ? 2 : 0);
for (int reim : {0, 1}) {
hs_block[q_sc1][q_sc2][reim][xx] =
QPhiX::rep<FT,double>(
scale *
// off-diagonal (odd-numbered) blocks change sign
(t_b_idx & 1 ? (-1.0) : 1.0) *
// if not doing the inverse and in the bottom-left block, need to
// complex conjugate
((!inverse && (t_s1 == 1 && t_s2 == 0) && reim == 1) ? -1.0 : 1.0) *
*(reinterpret_cast<double const *const>(
&(tm_clover[tm_idx][t_b_idx][t_hs].c00)) +
// if not doing the inverse and in the bottom-left block, transpose
// in colour
// because we're actually reading out of the top-right block
Nz * ((!inverse && (t_s1 == 1 && t_s2 == 0)) ? Nc * q_c2 + q_c1
: Nc * q_c1 + q_c2) +
reim) +
// in the QPhiX gamma basis, the twisted quark mass enters with the
// opposite
// sign for consistency
((!inverse && q_sc1 == q_sc2 && q_hs == 0 && reim == 1)
? -amu * (1 - 2 * fl)
: 0) +
((!inverse && q_sc1 == q_sc2 && q_hs == 1 && reim == 1)
? amu * (1 - 2 * fl)
: 0)
);
}
} // q_sc2
} // q_sc1
} // q_hs
} // fl
} // x_soa
} // for(v)
} // for(y)
} // for(z)
} // for(t)
const double diffTime = gettime() - startTime;
if (g_debug_level > 1) {
QPhiX::masterPrintf(
"# QPHIX-interface: time spent in reorder_clover_to_QPhiX (FullCloverBlock): %f secs\n",
diffTime);
}
}
template <typename FT, int VECLEN, int SOALEN, bool compress12>
void reorder_gauge_to_QPhiX(
QPhiX::Geometry<FT, VECLEN, SOALEN, compress12> &geom,
typename QPhiX::Geometry<FT, VECLEN, SOALEN, compress12>::SU3MatrixBlock *qphix_gauge_cb0,
typename QPhiX::Geometry<FT, VECLEN, SOALEN, compress12>::SU3MatrixBlock *qphix_gauge_cb1) {
const double startTime = gettime();
// Number of elements in spin, color & complex
// Here c1 is QPhiX's outer color, and c2 the inner one
const int Ns = 4;
const int Nc1 = compress12 ? 2 : 3;
const int Nc2 = 3;
const int Nz = 2;
// Geometric parameters for QPhiX data layout
const auto ngy = geom.nGY();
const auto nVecs = geom.nVecs();
const auto Pxy = geom.getPxy();
const auto Pxyz = geom.getPxyz();
// This is needed to translate between the different
// orderings of the direction index "\mu" in tmlQCD
// and QPhiX, respectively
// in qphix, the Dirac operator is applied in the order
// -+x -> -+y -> -+z -> -+t
// while tmlqcd does
// -+t -> -+x -> -+y -> -+z
// same as the lattice ordering
// The mappingn between the application dimensions is thus:
// tmlqcd_dim(t(0) -> x(1) -> y(2) -> z(3)) = qphix_dim( t(3) -> x(0) -> y(1) -> z(2) )
const int change_dim[4] = {1, 2, 3, 0};
// Get the base pointer for the (global) tmlQCD gauge field
xchange_gauge(g_gauge_field);
const double *in = reinterpret_cast<double *>(&g_gauge_field[0][0].c00);
#pragma omp parallel for collapse(4)
for (int64_t t = 0; t < T; t++)
for (int64_t z = 0; z < LZ; z++)
for (int64_t y = 0; y < LY; y++)
for (int64_t v = 0; v < nVecs; v++) {
int64_t block = (t * Pxyz + z * Pxy) / ngy + (y / ngy) * nVecs + v;
for (int dim = 0; dim < 4; dim++) // dimension == QPhiX \mu
for (int c1 = 0; c1 < Nc1; c1++) // QPhiX convention color 1 (runs up to 2 or 3)
for (int c2 = 0; c2 < Nc2; c2++) // QPhiX convention color 2 (always runs up to 3)
for (int x_soa = 0; x_soa < SOALEN; x_soa++) {
int64_t xx = (y % ngy) * SOALEN + x_soa;
int64_t q_cb_x_coord = x_soa + v * SOALEN;
int64_t tm_x_coord_cb0 = q_cb_x_coord * 2 + (((t + y + z) & 1) ^ 0);
int64_t tm_x_coord_cb1 = q_cb_x_coord * 2 + (((t + y + z) & 1) ^ 1);
int64_t tm_idx_cb0;
int64_t tm_idx_cb1;
// backward / forward
for (int dir = 0; dir < 2; dir++) {
if (dir == 0) {
tm_idx_cb0 = g_idn[g_ipt[t][tm_x_coord_cb0][y][z]][change_dim[dim]];
tm_idx_cb1 = g_idn[g_ipt[t][tm_x_coord_cb1][y][z]][change_dim[dim]];
} else {
tm_idx_cb0 = g_ipt[t][tm_x_coord_cb0][y][z];
tm_idx_cb1 = g_ipt[t][tm_x_coord_cb1][y][z];
}
for (int reim = 0; reim < Nz; reim++) {
// Note:
// -----
// 1. \mu in QPhiX runs from 0..7 for all eight neighbouring
// links.
// Here, the ordering of the direction (backward/forward)
// is the same
// for tmlQCD and QPhiX, but we have to change the
// ordering of the dimensions.
int q_mu = 2 * dim + dir;
qphix_gauge_cb0[block][q_mu][c1][c2][reim][xx] = QPhiX::rep<FT, double>(
su3_get_elem(&(g_gauge_field[tm_idx_cb0][change_dim[dim]]), c2, c1, reim ) );
qphix_gauge_cb1[block][q_mu][c1][c2][reim][xx] = QPhiX::rep<FT, double>(
su3_get_elem(&(g_gauge_field[tm_idx_cb1][change_dim[dim]]), c2, c1, reim ) );
}
}
} // for(dim,c1,c2,x_soa)
} // outer loop (t,z,y,v)
const double diffTime = gettime() - startTime;
if (g_debug_level > 1) {
QPhiX::masterPrintf("# QPHIX-interface: time spent in reorder_gauge_to_QPhiX: %f secs\n",
diffTime);
}
}
// Reorder tmLQCD eo-spinor to a FourSpinorBlock QPhiX spinor on the given checkerboard
template <typename FT, int VECLEN, int SOALEN, bool compress12>
void reorder_eo_spinor_to_QPhiX(
QPhiX::Geometry<FT, VECLEN, SOALEN, compress12> &geom, spinor const *const tm_eo_spinor,
typename QPhiX::Geometry<FT, VECLEN, SOALEN, compress12>::FourSpinorBlock *qphix_spinor,
const int cb) {
const double startTime = gettime();
const int Ns = 4;
const int Nc = 3;
const int Nz = 2;
const auto nVecs = geom.nVecs();
const auto Pxy = geom.getPxy();
const auto Pxyz = geom.getPxyz();
const auto Nxh = geom.Nxh();
// This is needed to translate between the different
// gamma bases tmlQCD and QPhiX are using
// (note, this is a 4x4 matrix with 4 non-zero elements)
const int change_sign[4] = {1, -1, -1, 1};
const int change_spin[4] = {3, 2, 1, 0};
#pragma omp parallel for collapse(4)
for (int64_t t = 0; t < T; t++) {
for (int64_t z = 0; z < LZ; z++) {
for (int64_t y = 0; y < LY; y++) {
for (int64_t v = 0; v < nVecs; v++) {
for (int col = 0; col < Nc; col++) {
for (int q_spin = 0; q_spin < Ns; q_spin++) {
for (int x_soa = 0; x_soa < SOALEN; x_soa++) {
int64_t q_ind = t * Pxyz + z * Pxy + y * nVecs + v;
int64_t q_cb_x_coord = v * SOALEN + x_soa;
// when t+y+z is odd and we're on an odd (1) checkerboard OR
// when t+y+z is even and we're on an even (0) checkerboard
// the full x coordinate is 2*x_cb
// otherwise, it is 2*x_cb+1
int64_t tm_x_coord = q_cb_x_coord * 2 + (((t + y + z) & 1) ^ cb);
// exchange x and z dimensions
int64_t tm_eo_ind = g_lexic2eosub[g_ipt[t][tm_x_coord][y][z]];
for (int reim = 0; reim < 2; reim++) {
qphix_spinor[q_ind][col][q_spin][reim][x_soa] =
QPhiX::rep<FT, double>(
change_sign[q_spin] * spinor_get_elem( &(tm_eo_spinor[tm_eo_ind]),
change_spin[q_spin],
col,
reim
)
);
}
}
}
}
}
}
}
}
const double diffTime = gettime() - startTime;
if (g_debug_level > 1) {
QPhiX::masterPrintf("# QPHIX-interface: time spent in reorder_eo_spinor_to_QPhiX: %f secs\n",
diffTime);
}
}
template <typename FT, int VECLEN, int SOALEN, bool compress12>
void reorder_eo_spinor_from_QPhiX(
QPhiX::Geometry<FT, VECLEN, SOALEN, compress12> &geom, spinor* tm_eo_spinor,
typename QPhiX::Geometry<FT, VECLEN, SOALEN, compress12>::FourSpinorBlock *qphix_spinor,
const int cb, double normFac = 1.0) {
const double startTime = gettime();
const int Ns = 4;
const int Nc = 3;
const int Nz = 2;
const auto nVecs = geom.nVecs();
const auto Pxy = geom.getPxy();
const auto Pxyz = geom.getPxyz();
const auto Nxh = geom.Nxh();
// This is needed to translate between the different
// gamma bases tmlQCD and QPhiX are using
// (note, this is a 4x4 matrix with 4 non-zero elements)
const int change_sign[4] = {1, -1, -1, 1};
const int change_spin[4] = {3, 2, 1, 0};
#pragma omp parallel for collapse(4)
for (int64_t t = 0; t < T; t++) {
for (int64_t z = 0; z < LZ; z++) {
for (int64_t y = 0; y < LY; y++) {
for (int64_t v = 0; v < nVecs; v++) {
for (int col = 0; col < Nc; col++) {
for (int q_spin = 0; q_spin < Ns; q_spin++) {
for (int x_soa = 0; x_soa < SOALEN; x_soa++) {
int64_t q_ind = t * Pxyz + z * Pxy + y * nVecs + v;
int64_t q_cb_x_coord = v * SOALEN + x_soa;
// when t+y+z is odd and we're on an odd checkerboard (1) OR
// when t+y+z is even and we're on an even (0) checkerboard
// the full x coordinate is 2*x_cb
// otherwise, it is 2*x_cb+1
int64_t tm_x_coord = q_cb_x_coord * 2 + (((t + y + z) & 1) ^ cb);
// exchange x and z dimensions
int64_t tm_eo_ind = g_lexic2eosub[g_ipt[t][tm_x_coord][y][z]];
spinor_set_elem( &(tm_eo_spinor[tm_eo_ind]),
change_spin[q_spin],
col,
change_sign[q_spin] * normFac * QPhiX::rep<double, FT>(
qphix_spinor[q_ind][col][q_spin][0][x_soa]
),
change_sign[q_spin] * normFac * QPhiX::rep<double, FT>(
qphix_spinor[q_ind][col][q_spin][1][x_soa]
)
);
}
}
}
}
}
}
}
const double diffTime = gettime() - startTime;
if (g_debug_level > 1) {
QPhiX::masterPrintf("# QPHIX-interface: time spent in reorder_eo_spinor_from_QPhiX: %f secs\n",
diffTime);
}
}
// Reorder a full tmLQCD spinor to a cb0 and cb1 QPhiX spinor
template <typename FT, int VECLEN, int SOALEN, bool compress12>
void reorder_spinor_to_QPhiX(QPhiX::Geometry<FT, VECLEN, SOALEN, compress12> &geom,
double const *tm_spinor, FT *qphix_spinor_cb0, FT *qphix_spinor_cb1) {
const double startTime = gettime();
// Number of elements in spin, color & complex
const int Ns = 4;
const int Nc = 3;
const int Nz = 2;
// Geometric parameters for QPhiX data layout
const auto nVecs = geom.nVecs();
const auto Pxy = geom.getPxy();
const auto Pxyz = geom.getPxyz();
// This is needed to translate between the different
// gamma bases tmlQCD and QPhiX are using
const int change_sign[4] = {1, -1, -1, 1};
const int change_spin[4] = {3, 2, 1, 0};
// This will loop over the entire lattice and calculate
// the array and internal indices for both tmlQCD & QPhiX
#pragma omp parallel for collapse(4)
for (uint64_t t = 0; t < T; t++)
for (uint64_t x = 0; x < LX; x++)
for (uint64_t y = 0; y < LY; y++)
for (uint64_t z = 0; z < LZ; z++) {
// These are the QPhiX SIMD vector in checkerboarded x direction
// (up to LX/2) and the internal position inside the SIMD vector
const uint64_t SIMD_vector = (x / 2) / SOALEN;
const uint64_t x_internal = (x / 2) % SOALEN;
// Calculate the array index in tmlQCD & QPhiX,
// given a global lattice index (t,x,y,z)
const uint64_t qphix_idx = t * Pxyz + z * Pxy + y * nVecs + SIMD_vector;
const uint64_t tm_idx = g_ipt[t][x][y][z];
// Calculate base point for every spinor field element (tmlQCD) or
// for every SIMD vector of spinors, a.k.a FourSpinorBlock (QPhiX),
// which will depend on the checkerboard (cb)
const double *in = tm_spinor + Ns * Nc * Nz * tm_idx;
FT *out;
if ((t + x + y + z) & 1)
out = qphix_spinor_cb1 + SOALEN * Nz * Nc * Ns * qphix_idx; // odd -> cb1
else
out = qphix_spinor_cb0 + SOALEN * Nz * Nc * Ns * qphix_idx; // even -> cb0
// Copy the internal elements, performing a gamma basis transformation
for (int spin = 0; spin < Ns; spin++) // QPhiX spin index
for (int color = 0; color < Nc; color++)
for (int z = 0; z < Nz; z++) // RE or IM
{
const uint64_t qId =
x_internal + z * SOALEN + spin * SOALEN * Nz + color * SOALEN * Nz * Ns;
const uint64_t tId = z + color * Nz + change_spin[spin] * Nz * Nc;
out[qId] = QPhiX::rep<FT, double>( change_sign[spin] * in[tId] );
}
} // volume
const double diffTime = gettime() - startTime;
if (g_debug_level > 1) {
QPhiX::masterPrintf("# QPHIX-interface: time spent in reorder_spinor_to_QPhiX: %f secs\n",
diffTime);
}
}
// Reorder a cb0 and cb1 QPhiX spinor to a full tmLQCD spinor
template <typename FT, int VECLEN, int SOALEN, bool compress12>
void reorder_spinor_from_QPhiX(QPhiX::Geometry<FT, VECLEN, SOALEN, compress12> &geom,
double *tm_spinor, FT const *qphix_spinor_cb0,
FT const *qphix_spinor_cb1, double normFac = 1.0) {
const double startTime = gettime();
// Number of elements in spin, color & complex
const int Ns = 4;
const int Nc = 3;
const int Nz = 2;
// Geometric parameters for QPhiX data layout
const auto nVecs = geom.nVecs();
const auto Pxy = geom.getPxy();
const auto Pxyz = geom.getPxyz();
// This is needed to translate between the different
// gamma bases tmlQCD and QPhiX are using
const int change_sign[4] = {1, -1, -1, 1};
const int change_spin[4] = {3, 2, 1, 0};
// This will loop over the entire lattice and calculate
// the array and internal indices for both tmlQCD & QPhiX
#pragma omp parallel for collapse(4)
for (uint64_t t = 0; t < T; t++)
for (uint64_t x = 0; x < LX; x++)
for (uint64_t y = 0; y < LY; y++)
for (uint64_t z = 0; z < LZ; z++) {
// These are the QPhiX SIMD vector in checkerboarded x direction
// (up to LX/2) and the internal position inside the SIMD vector
const uint64_t SIMD_vector = (x / 2) / SOALEN;
const uint64_t x_internal = (x / 2) % SOALEN;
// Calculate the array index in tmlQCD & QPhiX,
// given a global lattice index (t,x,y,z)
const uint64_t qphix_idx = t * Pxyz + z * Pxy + y * nVecs + SIMD_vector;
const uint64_t tm_idx = g_ipt[t][x][y][z];
// Calculate base point for every spinor field element (tmlQCD) or
// for every SIMD vector of spinors, a.k.a FourSpinorBlock (QPhiX),
// which will depend on the checkerboard (cb)
const FT *in;
if ((t + x + y + z) & 1)
in = qphix_spinor_cb1 + SOALEN * Nz * Nc * Ns * qphix_idx; // cb1
else
in = qphix_spinor_cb0 + SOALEN * Nz * Nc * Ns * qphix_idx; // cb0
double *out = tm_spinor + Ns * Nc * Nz * tm_idx;
// Copy the internal elements, performing a gamma basis transformation
for (int spin = 0; spin < Ns; spin++) // tmlQCD spin index