Skip to content

Commit fd7f785

Browse files
committed
update cmake
1 parent cb2c911 commit fd7f785

5 files changed

Lines changed: 301 additions & 1 deletion

File tree

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
@@ -380,6 +386,7 @@ list(
380386
${INIT_SRC_C}
381387
${APP_CONTEXT_SRC_C}
382388
${ALLOC_SRC_C}
389+
${PTBC_SRC_C}
383390
${SOLVER_SRC_C}
384391
${TEST_SRC_C}
385392
${MEAS_SRC_C}

src/lib/include/ptbc.h

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

src/lib/init/init_parallel.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ void init_parallel_and_read_input(int argc, char *argv[], const char input_filen
8585
exit(-1);
8686
}
8787

88+
app()->ptbc.initialize();
89+
8890
#ifdef TM_USE_OMP
8991
init_openmp();
9092
#endif

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/read_input.l

Lines changed: 224 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ EQL {SPC}*={SPC}*
5252
#include <stdlib.h>
5353
#include <stdio.h>
5454
#include <string.h>
55+
#include <stdarg.h>
5556
#define INIT_GLOBALS
5657
#include "global.h"
5758
#undef INIT_GLOBALS
@@ -61,12 +62,14 @@ EQL {SPC}*={SPC}*
6162
#include "solver/solver_types.h"
6263
#include "meas/measurements.h"
6364
#include "integrator.h"
65+
#include "include/app.h"
6466
#include "operator.h"
6567
#include "phmc.h"
6668
#include <io/params.h>
6769
#include "qphix_types.h"
6870
#include "quda_types.h"
6971
#include "misc_types.h"
72+
#include "alloc.h"
7073
7174
#include <ctype.h>
7275
@@ -87,6 +90,28 @@ static inline void rmQuotes(char *str){
8790
*strsave='\0';
8891
}
8992
93+
94+
static inline int strlist_count_tokens(char const * const input)
95+
{
96+
int n = 0;
97+
for (int i = 0; i < strlen(input); i++)
98+
if (input[i] == ',') n++;
99+
return n+1;
100+
}
101+
102+
static inline void fail(const bool test, const char* fmt, ...)
103+
{
104+
if (test) {
105+
va_list args;
106+
char msg[1024];
107+
va_start(args, fmt);
108+
vsnprintf(msg, 1024, fmt, args);
109+
va_end(args);
110+
yy_fatal_error(msg);
111+
}
112+
}
113+
114+
90115
/* tokenize the comma-delimited list 'input' of the form
91116
'list = token1, token2, ...'
92117
and return the first token, which is the name of the list
@@ -473,6 +498,60 @@ static inline double fltlist_next_token(int * const list_end){
473498
free(input_copy);
474499
}
475500

501+
static inline void parse_int_par_array(char const * const input, int * par_array, const int max_size) {
502+
char paramname[100];
503+
char error_message[ERR_MSG_LEN];
504+
int list_end = 0;
505+
int element = 0;
506+
507+
char * input_copy = (char*)NULL;
508+
strlist_tokenize(input, &input_copy, paramname, 100);
509+
int parval = (int) fltlist_next_token(&list_end);
510+
while( list_end != 1 ){
511+
if( element >= max_size ){
512+
snprintf(error_message, ERR_MSG_LEN, "Exceeded maximum number of elements (%d) parsing %s!\n", max_size, paramname);
513+
yy_fatal_error(error_message);
514+
}
515+
516+
par_array[element] = parval;
517+
if(myverbose){
518+
printf(" %s, element %d set to %d line %d\n", paramname,
519+
element, par_array[element], line_of_file);
520+
}
521+
522+
element++;
523+
parval = (int) fltlist_next_token(&list_end);
524+
}
525+
free(input_copy);
526+
}
527+
528+
static inline void parse_dbl_par_array(char const * const input, double * par_array, const int max_size) {
529+
char paramname[100];
530+
char error_message[ERR_MSG_LEN];
531+
int list_end = 0;
532+
int element = 0;
533+
534+
char * input_copy = (char*)NULL;
535+
strlist_tokenize(input, &input_copy, paramname, 100);
536+
double parval = fltlist_next_token(&list_end);
537+
while( list_end != 1 ){
538+
if( element >= max_size ){
539+
snprintf(error_message, ERR_MSG_LEN, "Exceeded maximum number of elements (%d) parsing %s!\n", max_size, paramname);
540+
yy_fatal_error(error_message);
541+
}
542+
543+
par_array[element] = parval;
544+
if(myverbose){
545+
printf(" %s, element %d set to %e line %d\n", paramname,
546+
element, par_array[element], line_of_file);
547+
}
548+
549+
element++;
550+
parval = fltlist_next_token(&list_end);
551+
}
552+
free(input_copy);
553+
}
554+
476555
%}
477556

478557
%option never-interactive
@@ -556,6 +635,11 @@ static inline double fltlist_next_token(int * const list_end){
556635
%x INITINTEGRATOR
557636
%x INTEGRATOR
558637

638+
%x INITPTBC
639+
%x PTBC
640+
%x PTBCDEFECT
641+
%x PTBCINSTANCE
642+
559643
%x DEFLATION
560644
%x INITDEFLATION
561645

@@ -712,6 +796,9 @@ static inline double fltlist_next_token(int * const list_end){
712796
^BeginInt BEGIN(INITINTEGRATOR);
713797
^BeginOperator{SPC}+ BEGIN(INITOPERATOR);
714798

799+
800+
^BeginPTBC BEGIN(INITPTBC);
801+
715802
^BeginExternalInverter{SPC}+ BEGIN(INITEXTERNALINVERTER);
716803

717804
^BeginTuneMGParams{SPC}+ BEGIN(TUNEMGPARAMS);
@@ -3071,6 +3158,142 @@ static inline double fltlist_next_token(int * const list_end){
30713158
}
30723159
}
30733160

3161+
<INITPTBC>{SPC}* {
3162+
appm()->ptbc.active = false;
3163+
appm()->ptbc.n_instances = 0;
3164+
appm()->ptbc.n_defects = 0;
3165+
appm()->ptbc.instance_id = 0;
3166+
if(myverbose) printf("Initialising PTBC line %d\n", line_of_file);
3167+
BEGIN(PTBC);
3168+
}
3169+
<PTBC>{
3170+
{SPC}*BeginPTBCDefect{SPC}+{DIGIT}+ {
3171+
sscanf(yytext, " %[a-zA-Z] %d", name, &b);
3172+
fail(b<0 || b>MAX_N_DEFECTS, "PTBC Defect id = %d out of bounds!", b);
3173+
appm()->ptbc.defects[b].active = true;
3174+
appm()->ptbc.n_defects++;
3175+
fail(appm()->ptbc.n_defects>=MAX_N_DEFECTS, "To many PTBC defects! Limit is %d", MAX_N_DEFECTS);
3176+
if(myverbose) printf(" Initialising PTBC defect (index = %d) in line %d\n", b, line_of_file);
3177+
BEGIN(PTBCDEFECT);
3178+
}
3179+
<PTBCDEFECT>{
3180+
{SPC}*Extents{EQL}{STRLIST} {
3181+
3182+
PTBCDefect* cd = appm()->ptbc.defects + b;
3183+
3184+
int n_parameters = strlist_count_tokens(yytext);
3185+
fail(n_parameters != 3, "Coefficients must provide exactly 3 numbers, not %d!\n", n_parameters);
3186+
sscanf(yytext, " %[a-zA-Z] = %d, %d, %d", name, cd->Ld, cd->Ld+1, cd->Ld+2);
3187+
if(myverbose) printf(" Ld = [%d, %d, %d] line %d\n", cd->Ld[0], cd->Ld[1], cd->Ld[2], line_of_file);
3188+
BEGIN(PTBCDEFECT);
3189+
}
3190+
{SPC}*Along{EQL}T {
3191+
appm()->ptbc.defects[b].along = DIRECTION_T;
3192+
if(myverbose) printf(" PTBC defect along T direction line %d\n", line_of_file);
3193+
BEGIN(PTBCDEFECT);
3194+
}
3195+
{SPC}*Along{EQL}X {
3196+
appm()->ptbc.defects[b].along = DIRECTION_X;
3197+
if(myverbose) printf(" PTBC defect along X direction line %d\n", line_of_file);
3198+
BEGIN(PTBCDEFECT);
3199+
}
3200+
{SPC}*Along{EQL}Y {
3201+
appm()->ptbc.defects[b].along = DIRECTION_Y;
3202+
if(myverbose) printf(" PTBC defect along Y direction line %d\n", line_of_file);
3203+
BEGIN(PTBCDEFECT);
3204+
}
3205+
{SPC}*Along{EQL}Z {
3206+
appm()->ptbc.defects[b].along = DIRECTION_Z;
3207+
if(myverbose) printf(" PTBC defect along Z direction line %d\n", line_of_file);
3208+
BEGIN(PTBCDEFECT);
3209+
}
3210+
{SPC}*EndPTBCDefect{SPC}* {
3211+
if(myverbose) printf(" PTBC defect parsed line %d\n", line_of_file);
3212+
BEGIN(PTBC);
3213+
}
3214+
}
3215+
{SPC}*BeginPTBCInstance{SPC}+{DIGIT}+ {
3216+
sscanf(yytext, " %[a-zA-Z] %d", name, &b);
3217+
fail(b<0 || b>MAX_N_INSTANCES, "PTBC Instance id = %d out of bounds!", b);
3218+
appm()->ptbc.instances[b].active = true;
3219+
appm()->ptbc.instances[b].n_coeffs = -1;
3220+
appm()->ptbc.n_instances++;
3221+
fail(appm()->ptbc.n_instances>=MAX_N_INSTANCES, "To many PTBC instances! Limit is %d", MAX_N_INSTANCES);
3222+
if(myverbose) printf(" Initialising PTBC instance (index = %d) in line %d\n", b, line_of_file);
3223+
BEGIN(PTBCINSTANCE);
3224+
}
3225+
<PTBCINSTANCE>{
3226+
{SPC}*Coefficients{EQL}{STRLIST} {
3227+
3228+
PTBCInstance* ci = appm()->ptbc.instances + b;
3229+
3230+
int n_parameters = strlist_count_tokens(yytext);
3231+
if (ci->coefficients == NULL)
3232+
ci->coefficients = safe_malloc(n_parameters*sizeof(double*));
3233+
3234+
parse_dbl_par_array(yytext, ci->coefficients, n_parameters);
3235+
3236+
for (int i = 0; i < n_parameters; ++i) {
3237+
fail(ci->coefficients[i]<0 || ci->coefficients[i] > 1,
3238+
"Coefficient %d with value %e is out of bounds", i, ci->coefficients[i]);
3239+
}
3240+
3241+
if (ci->n_coeffs == -1) ci->n_coeffs = n_parameters;
3242+
fail(ci->n_coeffs != n_parameters, "Number of PTBC coefficients must be equal to number of defects!\n");
3243+
3244+
for (int i = 0; i < n_parameters; ++i) {
3245+
if(myverbose) printf(" Coefficients[%d] = %f line %d\n", i, ci->coefficients[i], line_of_file);
3246+
}
3247+
3248+
BEGIN(PTBCINSTANCE);
3249+
}
3250+
{SPC}*Defects{EQL}{STRLIST} {
3251+
3252+
PTBCInstance* ci = appm()->ptbc.instances + b;
3253+
3254+
int n_parameters = strlist_count_tokens(yytext);
3255+
if (ci->defects == NULL) {
3256+
ci->defects = safe_malloc(n_parameters*sizeof(PTBCDefect*));
3257+
}
3258+
3259+
int* ids = safe_malloc(n_parameters*sizeof(int*));
3260+
parse_int_par_array(yytext, ids, n_parameters);
3261+
3262+
for (int i = 0; i < n_parameters; ++i) {
3263+
if(myverbose) printf(" Defects = %d line %d\n", ids[i], line_of_file);
3264+
fail(ids[i]<0 || ids[i]>MAX_N_DEFECTS, "PTBC Defect id = %d out of bounds!", ids[i]);
3265+
ci->defects[i] = &(appm()->ptbc.defects[ids[i]]);
3266+
}
3267+
3268+
if (ci->n_coeffs == -1) ci->n_coeffs = n_parameters;
3269+
3270+
fail(ci->n_coeffs != n_parameters,
3271+
"Number of PTBC defects must be equal to number of coefficients!\n");
3272+
3273+
free(ids);
3274+
BEGIN(PTBCINSTANCE);
3275+
}
3276+
{SPC}*EndPTBCInstance{SPC}* {
3277+
if(myverbose) printf(" PTBC instance parsed line %d\n", line_of_file);
3278+
BEGIN(PTBC);
3279+
}
3280+
}
3281+
EndPTBC{SPC}* {
3282+
fail(app()->ptbc.n_instances == 1, "Number of PTBC chains must be larger than 1!\n");
3283+
3284+
for (int i = 0; i < app()->ptbc.n_instances; ++i) {
3285+
fail(app()->ptbc.instances[i].active == false, "PTBC instance %d is not active!\n", i);
3286+
3287+
for (int j = 0; j < app()->ptbc.instances[i].n_coeffs; ++j) {
3288+
fail(app()->ptbc.instances[i].defects[j]->active == false, "PTBC instance %d does not refer to a valid defect!\n", i);
3289+
}
3290+
}
3291+
3292+
if(myverbose) printf("PTBC parsed line %d\n\n", line_of_file);
3293+
BEGIN(0);
3294+
}
3295+
}
3296+
30743297
<SOURCETYPE>{
30753298
Point {
30763299
SourceInfo.type = SRC_TYPE_POINT;
@@ -3729,7 +3952,7 @@ static inline double fltlist_next_token(int * const list_end){
37293952
BEGIN(comment_caller);
37303953
}
37313954

3732-
<INITMONOMIAL,DETMONOMIAL,CLDETMONOMIAL,CLDETRATMONOMIAL,CLDETRATRWMONOMIAL,NDPOLYMONOMIAL,NDRATMONOMIAL,NDRATCORMONOMIAL,NDCLRATMONOMIAL,NDCLRATCORMONOMIAL,CLPOLYMONOMIAL,GAUGEMONOMIAL,INTEGRATOR,INITINTEGRATOR,INITMEASUREMENT,PIONNORMMEAS,ONLINEMEAS,ORIENTEDPLAQUETTESMEAS,GRADIENTFLOWMEAS,INITOPERATOR,TMOP,DBTMOP,OVERLAPOP,WILSONOP,CLOVEROP,DBCLOVEROP,POLYMONOMIAL,PLOOP,RATMONOMIAL,RATCORMONOMIAL,CLRATMONOMIAL,CLRATCORMONOMIAL,INITDEFLATION,DEFLATION,INITMULTIGRID,MULTIGRID,INITEXTERNALINVERTER,QUDAINVERTER,QPHIXINVERTER,NDDETRATMONOMIAL,NDCLDETRATMONOMIAL,TUNEQUDAMGPARAMS>{SPC}*\n {
3955+
<INITMONOMIAL,DETMONOMIAL,CLDETMONOMIAL,CLDETRATMONOMIAL,CLDETRATRWMONOMIAL,NDPOLYMONOMIAL,NDRATMONOMIAL,NDRATCORMONOMIAL,NDCLRATMONOMIAL,NDCLRATCORMONOMIAL,CLPOLYMONOMIAL,GAUGEMONOMIAL,INTEGRATOR,INITINTEGRATOR,PTBC,INITPTBC,PTBCDEFECT,PTBCINSTANCE,INITMEASUREMENT,PIONNORMMEAS,ONLINEMEAS,ORIENTEDPLAQUETTESMEAS,GRADIENTFLOWMEAS,INITOPERATOR,TMOP,DBTMOP,OVERLAPOP,WILSONOP,CLOVEROP,DBCLOVEROP,POLYMONOMIAL,PLOOP,RATMONOMIAL,RATCORMONOMIAL,CLRATMONOMIAL,CLRATCORMONOMIAL,INITDEFLATION,DEFLATION,INITMULTIGRID,MULTIGRID,INITEXTERNALINVERTER,QUDAINVERTER,QPHIXINVERTER,NDDETRATMONOMIAL,NDCLDETRATMONOMIAL,TUNEQUDAMGPARAMS>{SPC}*\n {
37333956
line_of_file++;
37343957
}
37353958
<*>{SPC}*\n {

0 commit comments

Comments
 (0)