Skip to content

Commit f82931a

Browse files
committed
defect added
1 parent 90340d4 commit f82931a

File tree

7 files changed

+124
-11
lines changed

7 files changed

+124
-11
lines changed

src/lib/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ list(
7878
ALLOC_SRC_C
7979
alloc/alloc.c)
8080

81+
list(
82+
APPEND
83+
PTBC_SRC_C
84+
ptbc/defect.c
85+
)
86+
8187
list(
8288
APPEND
8389
SOLVER_SRC_C
@@ -401,6 +407,7 @@ list(
401407
${IO_SRC_C}
402408
${INIT_SRC_C}
403409
${APP_CONTEXT_SRC_C}
410+
${PTBC_SRC_C}
404411
${ALLOC_SRC_C}
405412
${SOLVER_SRC_C}
406413
${TEST_SRC_C}

src/lib/get_staples.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "start.h"
3030
#include "su3.h"
3131
#include "su3adj.h"
32+
#include <ptbc.h>
3233

3334
void get_staples(su3* const staple, const int x, const int mu, const su3** in_gauge_field) {
3435
int iy;
@@ -41,20 +42,25 @@ void get_staples(su3* const staple, const int x, const int mu, const su3** in_ga
4142
w1 = &in_gauge_field[x][k];
4243
w2 = &in_gauge_field[g_iup[x][k]][mu];
4344
w3 = &in_gauge_field[g_iup[x][mu]][k];
45+
double const ptbc_fac0 = get_ptbc_coeff(x, k) * get_ptbc_coeff(g_iup[x][k], mu) * get_ptbc_coeff(g_iup[x][mu], k);
4446

4547
/* st = w2 * w3^d */
4648
_su3_times_su3d(st, *w2, *w3);
4749
/* v = v + w1 * st */
48-
_su3_times_su3_acc(*staple, *w1, st);
50+
//_su3_times_su3_acc(*staple, *w1, st);
51+
_real_times_su3_times_su3_acc(*staple, *w1, st, ptbc_fac0);
4952

5053
iy = g_idn[x][k];
5154
w1 = &in_gauge_field[iy][k];
5255
w2 = &in_gauge_field[iy][mu];
5356
w3 = &in_gauge_field[g_iup[iy][mu]][k];
57+
double const ptbc_fac1 = get_ptbc_coeff(iy, k) * get_ptbc_coeff(iy, mu) * get_ptbc_coeff(g_iup[iy][mu], k);
58+
5459
/* st = w2 * w3 */
5560
_su3_times_su3(st, *w2, *w3);
5661
/* v = v + w1^d * st */
57-
_su3d_times_su3_acc(*staple, *w1, st);
62+
//_su3d_times_su3_acc(*staple, *w1, st);
63+
_real_times_su3_times_su3_acc(*staple, *w1, st, ptbc_fac1);
5864
}
5965
}
6066
}
@@ -71,20 +77,24 @@ void get_spacelike_staples(su3* const staple, const int x, const int mu,
7177
w1 = &in_gauge_field[x][k];
7278
w2 = &in_gauge_field[g_iup[x][k]][mu];
7379
w3 = &in_gauge_field[g_iup[x][mu]][k];
80+
double const ptbc_fac0 = get_ptbc_coeff(x, k) * get_ptbc_coeff(g_iup[x][k], mu) * get_ptbc_coeff(g_iup[x][mu], k);
7481

7582
/* st = w2 * w3^d */
7683
_su3_times_su3d(st, *w2, *w3);
7784
/* v = v + w1 * st */
78-
_su3_times_su3_acc(*staple, *w1, st);
85+
//_su3_times_su3_acc(*staple, *w1, st);
86+
_real_times_su3_times_su3_acc(*staple, *w1, st, ptbc_fac0);
7987

8088
iy = g_idn[x][k];
8189
w1 = &in_gauge_field[iy][k];
8290
w2 = &in_gauge_field[iy][mu];
8391
w3 = &in_gauge_field[g_iup[iy][mu]][k];
92+
double const ptbc_fac1 = get_ptbc_coeff(iy, k) * get_ptbc_coeff(iy, mu) * get_ptbc_coeff(g_iup[iy][mu], k);
8493
/* st = w2 * w3 */
8594
_su3_times_su3(st, *w2, *w3);
8695
/* v = v + w1^d * st */
87-
_su3d_times_su3_acc(*staple, *w1, st);
96+
//_su3d_times_su3_acc(*staple, *w1, st);
97+
_real_times_su3_times_su3_acc(*staple, *w1, st, ptbc_fac1);
8898
}
8999
}
90100
}
@@ -101,19 +111,23 @@ void get_timelike_staples(su3* const staple, const int x, const int mu,
101111
w1 = &in_gauge_field[x][k];
102112
w2 = &in_gauge_field[g_iup[x][k]][mu];
103113
w3 = &in_gauge_field[g_iup[x][mu]][k];
114+
double const ptbc_fac0 = get_ptbc_coeff(x, k) * get_ptbc_coeff(g_iup[x][k], mu) * get_ptbc_coeff(g_iup[x][mu], k);
104115

105116
/* st = w2 * w3^d */
106117
_su3_times_su3d(st, *w2, *w3);
107118
/* v = v + w1 * st */
108-
_su3_times_su3_acc(*staple, *w1, st);
119+
//_su3_times_su3_acc(*staple, *w1, st);
120+
_real_times_su3_times_su3_acc(*staple, *w1, st, ptbc_fac0);
109121

110122
iy = g_idn[x][k];
111123
w1 = &in_gauge_field[iy][k];
112124
w2 = &in_gauge_field[iy][mu];
113125
w3 = &in_gauge_field[g_iup[iy][mu]][k];
126+
double const ptbc_fac1 = get_ptbc_coeff(iy, k) * get_ptbc_coeff(iy, mu) * get_ptbc_coeff(g_iup[iy][mu], k);
114127
/* st = w2 * w3 */
115128
_su3_times_su3(st, *w2, *w3);
116129
/* v = v + w1^d * st */
117-
_su3d_times_su3_acc(*staple, *w1, st);
130+
//_su3d_times_su3_acc(*staple, *w1, st);
131+
_real_times_su3_times_su3_acc(*staple, *w1, st, ptbc_fac1);
118132
}
119133
}

src/lib/include/ptbc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <mpi.h>
2+
3+
4+
bool is_defect(PTBCDefect *def, int const ix, int const mu);
5+
double get_ptbc_coeff(int const ix, int const mu);

src/lib/measure_gauge_action.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "measure_gauge_action.h"
4040
#include "su3.h"
4141
#include "su3adj.h"
42+
#include <ptbc.h>
4243

4344
double measure_plaquette(const su3 *const *const gf) {
4445
static double res;
@@ -74,7 +75,10 @@ double measure_plaquette(const su3 *const *const gf) {
7475
w = &gf[ix2][mu1];
7576
_su3_times_su3(pr2, *v, *w);
7677
_trace_su3_times_su3d(ac, pr1, pr2);
77-
tr = ac + kc;
78+
79+
// compute local parallel tempering factor: fac_1 * fac_2 * fac_3 * fac_4
80+
double const ptbc_fac = get_ptbc_coeff(ix, mu1) * get_ptbc_coeff(ix1, mu2) * get_ptbc_coeff(ix, mu2) * get_ptbc_coeff(ix2, mu1);
81+
tr = ac * ptbc_fac + kc;
7882
ts = tr + ks;
7983
tt = ts - ks;
8084
ks = ts;
@@ -136,7 +140,10 @@ double measure_gauge_action(const su3 *const *const gf, const double lambda) {
136140
w = &gf[ix2][0];
137141
_su3_times_su3(pr2, *v, *w);
138142
_trace_su3_times_su3d(ac, pr1, pr2);
139-
ac *= (1 + lambda);
143+
144+
// parallel tempering factor = fac_1 * fac_2 * fac_3 * fac_4 computed in 2 parts
145+
double const ptbc_fac = get_ptbc_coeff(ix, 0) * get_ptbc_coeff(ix1, mu2) * get_ptbc_coeff(ix, mu2) * get_ptbc_coeff(ix2, 0);
146+
ac *= (1 + lambda) * ptbc_fac;
140147
tr = ac + kc;
141148
ts = tr + ks;
142149
tt = ts - ks;
@@ -145,17 +152,21 @@ double measure_gauge_action(const su3 *const *const gf, const double lambda) {
145152
}
146153
// magnetic part
147154
for (int mu1 = 1; mu1 < 3; mu1++) {
155+
double const ptbc_fac1 = get_ptbc_coeff(ix, mu1);
156+
148157
ix1 = g_iup[ix][mu1];
149-
for (int mu2 = mu1 + 1; mu2 < 4; mu2++) {
158+
for (int mu2 = mu1 + 1; mu2 < 4; mu2++) {
150159
ix2 = g_iup[ix][mu2];
160+
double const ptbc_fac2 = get_ptbc_coeff(ix1, mu2) * get_ptbc_coeff(ix, mu2) * get_ptbc_coeff(ix2, mu1);
161+
151162
v = &gf[ix][mu1];
152163
w = &gf[ix1][mu2];
153164
_su3_times_su3(pr1, *v, *w);
154165
v = &gf[ix][mu2];
155166
w = &gf[ix2][mu1];
156167
_su3_times_su3(pr2, *v, *w);
157168
_trace_su3_times_su3d(ac, pr1, pr2);
158-
ac *= (1 - lambda);
169+
ac *= (1 - lambda) * ptbc_fac1 * ptbc_fac2;
159170
tr = ac + kc;
160171
ts = tr + ks;
161172
tt = ts - ks;

src/lib/measure_rectangles.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "measure_rectangles.h"
4646
#include "su3.h"
4747
#include "su3adj.h"
48+
#include <ptbc.h>
4849

4950
double measure_rectangles(const su3 **const gf) {
5051
static double res;
@@ -81,6 +82,7 @@ double measure_rectangles(const su3 **const gf) {
8182
*/
8283
j = g_iup[i][mu];
8384
k = g_iup[j][nu];
85+
double const ptbc_fac0 = get_ptbc_coeff(i, mu) * get_ptbc_coeff(j, nu) * get_ptbc_coeff(k, nu);
8486
v = &gf[i][mu];
8587
w = &gf[j][nu];
8688
_su3_times_su3(tmp, *v, *w);
@@ -95,6 +97,7 @@ double measure_rectangles(const su3 **const gf) {
9597
*/
9698
j = g_iup[i][nu];
9799
k = g_iup[j][nu];
100+
double const ptbc_fac1 = get_ptbc_coeff(i, nu) * get_ptbc_coeff(j, nu) * get_ptbc_coeff(k, mu);
98101
v = &gf[i][nu];
99102
w = &gf[j][nu];
100103
_su3_times_su3(tmp, *v, *w);
@@ -105,7 +108,7 @@ double measure_rectangles(const su3 **const gf) {
105108
_trace_su3_times_su3d(ac, pr1, pr2);
106109
/* printf("i mu nu: %d %d %d, ac = %e\n", i, mu, nu, ac); */
107110
/* Kahan summation */
108-
tr = ac + kc;
111+
tr = ac * ptbc_fac0 * ptbc_fac1 + kc;
109112
ts = tr + ks;
110113
tt = ts - ks;
111114
ks = ts;

src/lib/ptbc/defect.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <stdbool.h>
2+
#include <sys/types.h>
3+
#include <sys/stat.h>
4+
#include <unistd.h>
5+
#include <stdlib.h>
6+
#include <stdio.h>
7+
#include <stdarg.h>
8+
#include <mpi.h>
9+
#include <ptbc.h>
10+
#include "global.h"
11+
12+
13+
// check if a link lie in defect region
14+
// 1. last slice of along 2. 3d cube with 0 origin
15+
bool is_defect(PTBCDefect *def, int const ix, int const mu) {
16+
if (ix >= VOLUME) return false;
17+
18+
int const global_dim[4] = {T*g_nproc_t, LX*g_nproc_t, LY*g_nproc_x, LZ*g_nproc_z};
19+
20+
// check start point is at second last slice and link stays on the slice
21+
if (g_coord[ix][def->along] == global_dim[def->along] - 2 && mu != def->along){
22+
// xf = end point of link
23+
int xf[4] = {g_coord[ix][0], g_coord[ix][1], g_coord[ix][2], g_coord[ix][3]};
24+
xf[mu] = xf[mu] + 1;
25+
int dim3[3];
26+
int count = 0;
27+
for (int d=0; d<4; d++) {
28+
if (d != def->along) {
29+
dim3[count] = d;
30+
count++;
31+
}
32+
}
33+
34+
for (int d=0; d<3; d++) {
35+
if (g_coord[ix][dim3[d]] >= def->Ld[d] || xf[dim3[d]] >= def->Ld[d]) {
36+
return false;
37+
}
38+
}
39+
if (g_proc_id==0) printf("defect coordinate %d %d %d %d mu = %d\n", g_coord[ix][0], g_coord[ix][1], g_coord[ix][2], g_coord[ix][3], mu);
40+
return true;
41+
}
42+
else {
43+
return false;
44+
}
45+
}
46+
47+
// get multiplying factor of parallel tempering locally (assumne no overlapping defects!)
48+
double get_ptbc_coeff(int const ix, int const mu) {
49+
int const inst = app()->ptbc.instance_id;
50+
const PTBCInstance *instance = &(app()->ptbc.instances[inst]);
51+
52+
// loop over defects
53+
for (int i=0; i<instance->n_coeffs; i++) {
54+
PTBCDefect *def = instance->defects[i];
55+
// apply coeff if within defect
56+
if (is_defect(def, ix, mu)) {
57+
return instance->coefficients[i];
58+
}
59+
}
60+
61+
return 1.;
62+
}

src/lib/su3.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,17 @@ typedef struct {
479479
(u).c21 = (v).c20 * (w).c01 + (v).c21 * (w).c11 + (v).c22 * (w).c21; \
480480
(u).c22 = (v).c20 * (w).c02 + (v).c21 * (w).c12 + (v).c22 * (w).c22;
481481

482+
#define _real_times_su3_times_su3_acc(u, v, w, r) \
483+
(u).c00 += (r) * ((v).c00 * (w).c00 + (v).c01 * (w).c10 + (v).c02 * (w).c20); \
484+
(u).c01 += (r) * ((v).c00 * (w).c01 + (v).c01 * (w).c11 + (v).c02 * (w).c21); \
485+
(u).c02 += (r) * ((v).c00 * (w).c02 + (v).c01 * (w).c12 + (v).c02 * (w).c22); \
486+
(u).c10 += (r) * ((v).c10 * (w).c00 + (v).c11 * (w).c10 + (v).c12 * (w).c20); \
487+
(u).c11 += (r) * ((v).c10 * (w).c01 + (v).c11 * (w).c11 + (v).c12 * (w).c21); \
488+
(u).c12 += (r) * ((v).c10 * (w).c02 + (v).c11 * (w).c12 + (v).c12 * (w).c22); \
489+
(u).c20 += (r) * ((v).c20 * (w).c00 + (v).c21 * (w).c10 + (v).c22 * (w).c20); \
490+
(u).c21 += (r) * ((v).c20 * (w).c01 + (v).c21 * (w).c11 + (v).c22 * (w).c21); \
491+
(u).c22 += (r) * ((v).c20 * (w).c02 + (v).c21 * (w).c12 + (v).c22 * (w).c22);
492+
482493
#define _su3_times_su3_acc(u, v, w) \
483494
(u).c00 += (v).c00 * (w).c00 + (v).c01 * (w).c10 + (v).c02 * (w).c20; \
484495
(u).c01 += (v).c00 * (w).c01 + (v).c01 * (w).c11 + (v).c02 * (w).c21; \

0 commit comments

Comments
 (0)