Skip to content

Commit 94b4494

Browse files
committed
Making exposu3 thread safe
1 parent da53162 commit 94b4494

9 files changed

+43
-33
lines changed

expo.c

+24-27
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "su3adj.h"
5454
#include "expo.h"
5555
#include "float.h"
56+
#include "global.h"
5657

5758
static double imag_det(const su3adj* p) {
5859
double d,tos3,o3,os3;
@@ -76,6 +77,25 @@ static void mul_su3alg(su3adj* p,double d) {
7677
(*p).d8*=d;
7778
}
7879

80+
void init_exposu3() {
81+
int k;
82+
double fctr = 1.0;
83+
g_exposu3_no_c = 0;
84+
85+
while (fctr>DBL_EPSILON) {
86+
g_exposu3_no_c++;
87+
fctr/=(double)(g_exposu3_no_c);
88+
}
89+
g_exposu3_no_c += 7;
90+
g_exposu3_no_c += (g_exposu3_no_c%2);
91+
92+
g_exposu3_c=malloc((g_exposu3_no_c+1)*sizeof(*g_exposu3_c));
93+
94+
g_exposu3_c[0]=1.0;
95+
for (k=0; k < g_exposu3_no_c; k++)
96+
g_exposu3_c[k+1]=g_exposu3_c[k]/(double)(k+1);
97+
}
98+
7999
void exposu3(su3* const vr, const su3adj* const p) {
80100
int n,m,mm;
81101
su3 ALIGN v,v2,vt;
@@ -84,29 +104,6 @@ void exposu3(su3* const vr, const su3adj* const p) {
84104
_Complex double t;
85105
_Complex double ALIGN p0,p1,p2;
86106
_Complex double ALIGN q0,q1,q2;
87-
static int init_flag=0, no_c;
88-
static double *c;
89-
90-
if (init_flag==0) {
91-
int k;
92-
double fctr = 1.0;
93-
no_c = 0;
94-
95-
while (fctr>DBL_EPSILON) {
96-
no_c++;
97-
fctr/=(double)(no_c);
98-
}
99-
no_c += 7;
100-
no_c += (no_c%2);
101-
102-
c=malloc((no_c+1)*sizeof(*c));
103-
104-
c[0]=1.0;
105-
for (k=0; k < no_c; k++)
106-
c[k+1]=c[k]/(double)(k+1);
107-
108-
init_flag=1;
109-
}
110107

111108
_make_su3(v,*p);
112109
_su3_times_su3(v2,v,v);
@@ -139,19 +136,19 @@ void exposu3(su3* const vr, const su3adj* const p) {
139136
/* printf(" d= %.16f and t=%.16f + 1i %.16f \n",d,creal(t),cimag(t));*/
140137

141138
if(fabs(d)>(1.000001*(1.000002-fabs(t))))
142-
printf("The norm of X is larger than 1 and N = %d \n", no_c);
139+
printf("The norm of X is larger than 1 and N = %d \n", g_exposu3_no_c);
143140

144141

145-
p0=c[no_c];
142+
p0=g_exposu3_c[g_exposu3_no_c];
146143
p1=0.0;
147144
p2=0.0;
148145

149-
for (n=(no_c-1);n>=0;n--) {
146+
for (n=(g_exposu3_no_c-1);n>=0;n--) {
150147
q0=p0;
151148
q1=p1;
152149
q2=p2;
153150

154-
p0=c[n]-I*d*q2;
151+
p0=g_exposu3_c[n]-I*d*q2;
155152
p1=q0-t*q2;
156153
p2=q1;
157154
}

expo.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
#ifndef _EXPO_H
2020
#define _EXPO_H
2121

22-
extern void exposu3(su3* const vr, const su3adj* const p);
23-
extern void exposu3_check(su3* const vr, const su3adj* const p, int im);
24-
extern void restoresu3(su3* const vr, const su3* const u);
25-
extern void restoresu3_in_place(su3* const u);
26-
extern void exposu3_in_place(su3* const u);
22+
void init_exposu3();
23+
void exposu3(su3* const vr, const su3adj* const p);
24+
void exposu3_check(su3* const vr, const su3adj* const p, int im);
25+
void restoresu3(su3* const vr, const su3* const u);
26+
void restoresu3_in_place(su3* const u);
27+
void exposu3_in_place(su3* const u);
2728

2829
#endif

global.h

+4
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ EXTERN int g_mpi_z_rank;
212212
EXTERN int g_mpi_ST_rank;
213213
EXTERN int g_nb_list[8];
214214

215+
/* Variables for exposu3 */
216+
EXTERN int g_exposu3_no_c;
217+
EXTERN double * g_exposu3_c;
218+
215219
/* OpenMP Kahan accumulation arrays */
216220
EXTERN _Complex double *g_omp_acc_cp;
217221
EXTERN double* g_omp_acc_re;

smearing/hex_stout_exclude_none.c

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
void stout_exclude_none(su3_tuple *buff_out, double const coeff, su3_tuple **staples, su3_tuple *buff_in)
44
{
55
static su3 tmp;
6+
if (g_exposu3_no_c == 0) init_exposu3();
67

78
#define _MULTIPLY_AND_EXPONENTIATE(x, principal) \
89
{ \

smearing/hex_stout_exclude_one.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include "hex.ih"
2+
#include "global.h"
23

34
void stout_exclude_one(su3_tuple **buff_out, double const coeff, su3_tuple **staples, su3_tuple *buff_in)
45
{
56
static su3 tmp;
6-
7+
if (g_exposu3_no_c == 0) init_exposu3();
8+
79
#define _MULTIPLY_AND_EXPONENTIATE(x, principal, component) \
810
{ \
911
_su3_times_su3d(tmp, staples[component / 4][x][component % 4], buff_in[x][principal]); \

smearing/hex_stout_exclude_two.c

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
void stout_exclude_two(su3_tuple **buff_out, double const coeff, su3_tuple **staples, su3_tuple *buff_in)
44
{
55
static su3 tmp;
6+
if (g_exposu3_no_c == 0) init_exposu3();
67

78
#define _MULTIPLY_AND_EXPONENTIATE(x, principal, component) \
89
{ \

smearing/stout_stout_smear.c

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ int stout_smear(su3_tuple *m_field_out, struct stout_parameters const *params, s
1414
buffer = (su3_tuple*)(((unsigned long int)(buffer) + ALIGN_BASE) & ~ALIGN_BASE);
1515
#endif
1616

17+
if (g_exposu3_no_c == 0) init_exposu3();
1718
if (buffer == (su3_tuple*)NULL)
1819
return -1;
1920
initialized = 1;

update_gauge.c

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ void update_gauge(const double step, hamiltonian_field_t * const hf) {
7373
#undef static
7474
#endif
7575

76+
if (g_exposu3_no_c == 0) init_exposu3();
77+
7678
#ifdef TM_USE_OMP
7779
#pragma omp for
7880
#endif

update_momenta_fg.c

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ void update_momenta_fg(int * mnllist, double step, const int no,
107107
xchange_deri(hf->derivative);
108108
#endif
109109

110+
if (g_exposu3_no_c == 0) init_exposu3();
110111

111112
/* #ifdef TM_USE_OMP
112113
#pragma omp parallel for

0 commit comments

Comments
 (0)