@@ -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