void random_gauge_field(const int repro) { int ix,mu; #ifdef MPI int rlxd_state[105]; int j=0; if(g_proc_id !=0 && repro == 1) { MPI_Recv(&rlxd_state[0], 105, MPI_INT, g_proc_id-1, 102, MPI_COMM_WORLD, &status); rlxd_reset(rlxd_state); } #endif for (ix = 0; ix < VOLUME; ix++) { for (mu = 0; mu < 4; mu++) { g_gauge_field[ix][mu] = random_su3(); } } #ifdef MPI if(repro == 1) { j = (g_proc_id + 1) % g_nproc; rlxd_get(rlxd_state); MPI_Send(&rlxd_state[0], 105, MPI_INT, j, 102, MPI_COMM_WORLD); if(g_proc_id == 0) { MPI_Recv(&rlxd_state[0], 105, MPI_INT, g_nproc-1, 102, MPI_COMM_WORLD, &status); rlxd_reset(rlxd_state); } } #endif g_update_gauge_copy = 1; g_update_gauge_energy = 1; g_update_rectangle_energy = 1; return; }
/* Function provides a spinor field of length V with Gaussian distribution */ void random_spinor_field_lexic(spinor * const k) { int x, y, z, t, X, Y, Z, tt, id=0; #ifdef MPI int rlxd_state[105]; #endif int coords[4]; spinor *s; double v[24]; #ifdef MPI if(g_proc_id == 0) { rlxd_get(rlxd_state); } MPI_Bcast(rlxd_state, 105, MPI_INT, 0, MPI_COMM_WORLD); if(g_proc_id != 0) { rlxd_reset(rlxd_state); } #endif for(t = 0; t < g_nproc_t*T; t++) { tt = t - g_proc_coords[0]*T; coords[0] = t / T; for(x = 0; x < g_nproc_x*LX; x++) { X = x - g_proc_coords[1]*LX; coords[1] = x / LX; for(y = 0; y < g_nproc_y*LY; y++) { Y = y - g_proc_coords[2]*LY; coords[2] = y / LY; for(z = 0; z < g_nproc_z*LZ; z++) { Z = z - g_proc_coords[3]*LZ; coords[3] = z / LZ; #ifdef MPI MPI_Cart_rank(g_cart_grid, coords, &id); #endif if(g_cart_id == id) { gauss_vector(v, 24); s = k + g_ipt[tt][X][Y][Z]; memcpy(s, v, 24*sizeof(double)); } else { ranlxd(v,24); } } } } } return; }
/* codes */ void gaussian_volume_source(spinor * const P, spinor * const Q, const int sample, const int nstore, const int f) { int x, y, z, t, i, reset = 0, seed; int rlxd_state[105]; spinor * p; /* save the ranlxd_state if neccessary */ if(ranlxd_init == 1) { rlxd_get(rlxd_state); reset = 1; } /* Compute the seed */ seed =(int) abs(1 + sample + f*10*97 + nstore*100*53 + g_cart_id*13); rlxd_init(1, seed); for(t = 0; t < T; t++) { for(x = 0; x < LX; x++) { for(y =0; y < LY; y++) { for(z = 0; z < LZ; z++) { i = g_lexic2eosub[ g_ipt[t][x][y][z] ]; if((t+x+y+z+g_proc_coords[3]*LZ+g_proc_coords[2]*LY + g_proc_coords[0]*T+g_proc_coords[1]*LX)%2 == 0) { p = (P + i); } else { p = (Q + i); } rnormal((double*)p, 24); } } } } /* reset the ranlxd if neccessary */ if(reset) { rlxd_reset(rlxd_state); } return; }
int main(int argc,char *argv[]) { FILE *parameterfile=NULL,*rlxdfile=NULL, *countfile=NULL; char * filename = NULL; char datafilename[50]; char parameterfilename[50]; char gauge_filename[50]; char * nstore_filename = ".nstore_counter"; char * input_filename = NULL; int rlxd_state[105]; int j,ix,mu; int k; struct timeval t1; int g_nev, max_iter_ev; double stop_prec_ev; /* Energy corresponding to the Gauge part */ double eneg = 0., plaquette_energy = 0., rectangle_energy = 0.; /* Acceptance rate */ int Rate=0; /* Do we want to perform reversibility checks */ /* See also return_check_flag in read_input.h */ int return_check = 0; /* For getopt */ int c; /* For the Polyakov loop: */ int dir = 2; _Complex double pl, pl4; verbose = 0; g_use_clover_flag = 0; g_nr_of_psf = 1; #ifndef XLC signal(SIGUSR1,&catch_del_sig); signal(SIGUSR2,&catch_del_sig); signal(SIGTERM,&catch_del_sig); signal(SIGXCPU,&catch_del_sig); #endif while ((c = getopt(argc, argv, "h?f:o:")) != -1) { switch (c) { case 'f': input_filename = calloc(200, sizeof(char)); strcpy(input_filename,optarg); break; case 'o': filename = calloc(200, sizeof(char)); strcpy(filename,optarg); break; case 'h': case '?': default: usage(); break; } } if(input_filename == NULL){ input_filename = "hmc.input"; } if(filename == NULL){ filename = "output"; } /* Read the input file */ read_input(input_filename); mpi_init(argc, argv); if(Nsave == 0){ Nsave = 1; } if(nstore == -1) { countfile = fopen(nstore_filename, "r"); if(countfile != NULL) { fscanf(countfile, "%d\n", &nstore); fclose(countfile); } else { nstore = 0; } } if(g_rgi_C1 == 0.) { g_dbw2rand = 0; } #ifndef TM_USE_MPI g_dbw2rand = 0; #endif /* Reorder the mu parameter and the number of iterations */ if(g_mu3 > 0.) { g_mu = g_mu1; g_mu1 = g_mu3; g_mu3 = g_mu; j = int_n[1]; int_n[1] = int_n[3]; int_n[3] = j; j = g_csg_N[0]; g_csg_N[0] = g_csg_N[4]; g_csg_N[4] = j; g_csg_N[6] = j; if(fabs(g_mu3) > 0) { g_csg_N[6] = 0; } g_nr_of_psf = 3; } else if(g_mu2 > 0.) { g_mu = g_mu1; g_mu1 = g_mu2; g_mu2 = g_mu; int_n[3] = int_n[1]; int_n[1] = int_n[2]; int_n[2] = int_n[3]; /* For chronological inverter */ g_csg_N[4] = g_csg_N[0]; g_csg_N[0] = g_csg_N[2]; g_csg_N[2] = g_csg_N[4]; if(fabs(g_mu2) > 0) { g_csg_N[4] = 0; } g_csg_N[6] = 0; g_nr_of_psf = 2; } else { g_csg_N[2] = g_csg_N[0]; if(fabs(g_mu2) > 0) { g_csg_N[2] = 0; } g_csg_N[4] = 0; g_csg_N[6] = 0; } for(j = 0; j < g_nr_of_psf+1; j++) { if(int_n[j] == 0) int_n[j] = 1; } if(g_nr_of_psf == 3) { g_eps_sq_force = g_eps_sq_force1; g_eps_sq_force1 = g_eps_sq_force3; g_eps_sq_force3 = g_eps_sq_force; g_eps_sq_acc = g_eps_sq_acc1; g_eps_sq_acc1 = g_eps_sq_acc3; g_eps_sq_acc3 = g_eps_sq_acc; } if(g_nr_of_psf == 2) { g_eps_sq_force = g_eps_sq_force1; g_eps_sq_force1 = g_eps_sq_force2; g_eps_sq_force2 = g_eps_sq_force; g_eps_sq_acc = g_eps_sq_acc1; g_eps_sq_acc1 = g_eps_sq_acc2; g_eps_sq_acc2 = g_eps_sq_acc; } g_mu = g_mu1; g_eps_sq_acc = g_eps_sq_acc1; g_eps_sq_force = g_eps_sq_force1; #ifdef _GAUGE_COPY j = init_gauge_field(VOLUMEPLUSRAND + g_dbw2rand, 1); #else j = init_gauge_field(VOLUMEPLUSRAND + g_dbw2rand, 0); #endif if ( j!= 0) { fprintf(stderr, "Not enough memory for gauge_fields! Aborting...\n"); exit(0); } j = init_geometry_indices(VOLUMEPLUSRAND + g_dbw2rand); if ( j!= 0) { fprintf(stderr, "Not enough memory for geometry_indices! Aborting...\n"); exit(0); } j = init_spinor_field(VOLUMEPLUSRAND/2, NO_OF_SPINORFIELDS); if ( j!= 0) { fprintf(stderr, "Not enough memory for spinor fields! Aborting...\n"); exit(0); } j = init_bispinor_field(VOLUME/2, NO_OF_SPINORFIELDS); j = init_csg_field(VOLUMEPLUSRAND/2, g_csg_N); if ( j!= 0) { fprintf(stderr, "Not enough memory for csg fields! Aborting...\n"); exit(0); } j = init_moment_field(VOLUME, VOLUMEPLUSRAND); if ( j!= 0) { fprintf(stderr, "Not enough memory for moment fields! Aborting...\n"); exit(0); } zero_spinor_field(g_spinor_field[DUM_DERI+4],VOLUME/2); zero_spinor_field(g_spinor_field[DUM_DERI+5],VOLUME/2); zero_spinor_field(g_spinor_field[DUM_DERI+6],VOLUME/2); if(g_proc_id == 0){ /* fscanf(fp6,"%s",filename); */ /*construct the filenames for the observables and the parameters*/ strcpy(datafilename,filename); strcat(datafilename,".data"); strcpy(parameterfilename,filename); strcat(parameterfilename,".para"); parameterfile=fopen(parameterfilename, "w"); printf("# This is the hmc code for twisted Mass Wilson QCD\n\nVersion %s\n", Version); #ifdef SSE printf("# The code was compiled with SSE instructions\n"); #endif #ifdef SSE2 printf("# The code was compiled with SSE2 instructions\n"); #endif #ifdef SSE3 printf("# The code was compiled with SSE3 instructions\n"); #endif #ifdef P4 printf("# The code was compiled for Pentium4\n"); #endif #ifdef OPTERON printf("# The code was compiled for AMD Opteron\n"); #endif #ifdef _NEW_GEOMETRY printf("# The code was compiled with -D_NEW_GEOMETRY\n"); #endif #ifdef _GAUGE_COPY printf("# The code was compiled with -D_GAUGE_COPY\n"); #endif printf("# The lattice size is %d x %d x %d x %d\n", (int)(T*g_nproc_t), (int)(LX*g_nproc_x), (int)(LY), (int)(LZ)); printf("# The local lattice size is %d x %d x %d x %d\n", (int)(T), (int)(LX), (int)(LY),(int) LZ); printf("# beta = %f , kappa= %f\n", g_beta, g_kappa); printf("# mus = %f, %f, %f\n", g_mu1, g_mu2, g_mu3); printf("# int_n_gauge = %d, int_n_ferm1 = %d, int_n_ferm2 = %d, int_n_ferm3 = %d\n", int_n[0], int_n[1], int_n[2], int_n[3]); printf("# g_rgi_C0 = %f, g_rgi_C1 = %f\n", g_rgi_C0, g_rgi_C1); printf("# Number of pseudo-fermion fields: %d\n", g_nr_of_psf); printf("# g_eps_sq_force = %e, g_eps_sq_acc = %e\n", g_eps_sq_force, g_eps_sq_acc); printf("# Integration scheme: "); if(integtyp == 1) printf("leap-frog (single time scale)\n"); if(integtyp == 2) printf("Sexton-Weingarten (single time scale)\n"); if(integtyp == 3) printf("leap-frog (multiple time scales)\n"); if(integtyp == 4) printf("Sexton-Weingarten (multiple time scales)\n"); if(integtyp == 5) printf("higher order and leap-frog (multiple time scales)\n"); printf("# Using %s precision for the inversions!\n", g_relative_precision_flag ? "relative" : "absolute"); printf("# Using in chronological inverter for spinor_field 1,2,3 a history of %d, %d, %d, respectively\n", g_csg_N[0], g_csg_N[2], g_csg_N[4]); fprintf(parameterfile, "The lattice size is %d x %d x %d x %d\n", (int)(g_nproc_t*T), (int)(g_nproc_x*LX), (int)(LY), (int)(LZ)); fprintf(parameterfile, "The local lattice size is %d x %d x %d x %d\n", (int)(T), (int)(LX), (int)(LY), (int)(LZ)); fprintf(parameterfile, "g_beta = %f , g_kappa= %f, c_sw = %f \n",g_beta,g_kappa,g_c_sw); fprintf(parameterfile, "boundary of fermion fields (t,x,y,z): %f %f %f %f \n",X0,X1,X2,X3); fprintf(parameterfile, "EPS_SQ0=%e, EPS_SQ1=%e EPS_SQ2=%e, EPS_SQ3=%e \n" ,EPS_SQ0,EPS_SQ1,EPS_SQ2,EPS_SQ3); fprintf(parameterfile, "g_eps_sq_force = %e, g_eps_sq_acc = %e\n", g_eps_sq_force, g_eps_sq_acc); fprintf(parameterfile, "dtau=%f, Nsteps=%d, Nmeas=%d, Nsave=%d, integtyp=%d, nsmall=%d \n", dtau,Nsteps,Nmeas,Nsave,integtyp,nsmall); fprintf(parameterfile, "mu = %f, mu2=%f, mu3=%f\n ", g_mu, g_mu2, g_mu3); fprintf(parameterfile, "int_n_gauge = %d, int_n_ferm1 = %d, int_n_ferm2 = %d, int_n_ferm3 = %d\n ", int_n[0], int_n[1], int_n[2], int_n[3]); fprintf(parameterfile, "g_rgi_C0 = %f, g_rgi_C1 = %f\n", g_rgi_C0, g_rgi_C1); fprintf(parameterfile, "# Number of pseudo-fermion fields: %d\n", g_nr_of_psf); fprintf(parameterfile, "# Integration scheme: "); if(integtyp == 1) fprintf(parameterfile, "leap-frog (single time scale)\n"); if(integtyp == 2) fprintf(parameterfile, "Sexton-Weingarten (single time scale)\n"); if(integtyp == 3) fprintf(parameterfile, "leap-frog (multiple time scales)\n"); if(integtyp == 4) fprintf(parameterfile, "Sexton-Weingarten (multiple time scales)\n"); if(integtyp == 5) fprintf(parameterfile, "higher order and leap-frog (multiple time scales)\n"); fprintf(parameterfile, "Using %s precision for the inversions!\n", g_relative_precision_flag ? "relative" : "absolute"); fprintf(parameterfile, "Using in chronological inverter for spinor_field 1,2,3 a history of %d, %d, %d, respectively\n", g_csg_N[0], g_csg_N[2], g_csg_N[4]); fflush(stdout); fflush(parameterfile); } /* define the geometry */ geometry(); /* define the boundary conditions for the fermion fields */ boundary(); check_geometry(); if(g_proc_id == 0) { #if defined GEOMETRIC if(g_proc_id==0) fprintf(parameterfile,"The geometric series is used as solver \n\n"); #else if(g_proc_id==0) fprintf(parameterfile,"The BICG_stab is used as solver \n\n"); #endif fflush(parameterfile); } /* Continue */ if(startoption == 3){ rlxdfile = fopen(rlxd_input_filename,"r"); if(rlxdfile != NULL) { if(g_proc_id == 0) { fread(rlxd_state,sizeof(rlxd_state),1,rlxdfile); } } else { if(g_proc_id == 0) { printf("%s does not exist, switching to restart...\n", rlxd_input_filename); } startoption = 2; } fclose(rlxdfile); if(startoption != 2) { if(g_proc_id == 0) { rlxd_reset(rlxd_state); printf("Reading Gauge field from file %s\n", gauge_input_filename); fflush(stdout); } read_gauge_field_time_p(gauge_input_filename,g_gauge_field); } } if(startoption != 3){ /* Initialize random number generator */ if(g_proc_id == 0) { rlxd_init(1, random_seed); /* hot */ if(startoption == 1) { random_gauge_field(); } rlxd_get(rlxd_state); #ifdef TM_USE_MPI MPI_Send(&rlxd_state[0], 105, MPI_INT, 1, 99, MPI_COMM_WORLD); MPI_Recv(&rlxd_state[0], 105, MPI_INT, g_nproc-1, 99, MPI_COMM_WORLD, &status); rlxd_reset(rlxd_state); #endif } #ifdef TM_USE_MPI else { MPI_Recv(&rlxd_state[0], 105, MPI_INT, g_proc_id-1, 99, MPI_COMM_WORLD, &status); rlxd_reset(rlxd_state); /* hot */ if(startoption == 1) { random_gauge_field(); } k=g_proc_id+1; if(k==g_nproc){ k=0; } rlxd_get(rlxd_state); MPI_Send(&rlxd_state[0], 105, MPI_INT, k, 99, MPI_COMM_WORLD); } #endif /* Cold */ if(startoption == 0) { unit_g_gauge_field(); } /* Restart */ else if(startoption == 2) { if (g_proc_id == 0){ printf("Reading Gauge field from file %s\n", gauge_input_filename); fflush(stdout); } read_gauge_field_time_p(gauge_input_filename,g_gauge_field); } } /*For parallelization: exchange the gaugefield */ #ifdef TM_USE_MPI xchange_gauge(g_gauge_field); #endif #ifdef _GAUGE_COPY update_backward_gauge(); #endif /*compute the energy of the gauge field*/ plaquette_energy=measure_gauge_action(); if(g_rgi_C1 > 0. || g_rgi_C1 < 0.) { rectangle_energy = measure_rectangles(); if(g_proc_id==0){ fprintf(parameterfile,"#First rectangle value: %14.12f \n",rectangle_energy/(12.*VOLUME*g_nproc)); } } eneg = g_rgi_C0 * plaquette_energy + g_rgi_C1 * rectangle_energy; /* Measure and print the Polyakov loop: */ polyakov_loop(&pl, dir); if(g_proc_id==0){ fprintf(parameterfile,"#First plaquette value: %14.12f \n", plaquette_energy/(6.*VOLUME*g_nproc)); fprintf(parameterfile,"#First Polyakov loop value in %d-direction |L(%d)|= %14.12f \n", dir, dir, cabs(pl)); } dir=3; polyakov_loop(&pl, dir); if(g_proc_id==0){ fprintf(parameterfile,"#First Polyakov loop value in %d-direction |L(%d)|= %14.12f \n", dir, dir, cabs(pl)); fclose(parameterfile); } /* set ddummy to zero */ for(ix = 0; ix < VOLUME+RAND; ix++){ for(mu=0; mu<4; mu++){ ddummy[ix][mu].d1=0.; ddummy[ix][mu].d2=0.; ddummy[ix][mu].d3=0.; ddummy[ix][mu].d4=0.; ddummy[ix][mu].d5=0.; ddummy[ix][mu].d6=0.; ddummy[ix][mu].d7=0.; ddummy[ix][mu].d8=0.; } } if(g_proc_id == 0) { gettimeofday(&t1,NULL); countfile = fopen("history_hmc_tm", "a"); fprintf(countfile, "!!! Timestamp %ld, Nsave = %d, g_mu = %e, g_mu1 = %e, g_mu_2 = %e, g_mu3 = %e, beta = %f, kappa = %f, C1 = %f, int0 = %d, int1 = %d, int2 = %d, int3 = %d, g_eps_sq_force = %e, g_eps_sq_acc = %e, ", t1.tv_sec, Nsave, g_mu, g_mu1, g_mu2, g_mu3, g_beta, g_kappa, g_rgi_C1, int_n[0], int_n[1], int_n[2], int_n[3], g_eps_sq_force, g_eps_sq_acc); fprintf(countfile, "Nsteps = %d, dtau = %e, tau = %e, integtyp = %d, rel. prec. = %d\n", Nsteps, dtau, tau, integtyp, g_relative_precision_flag); fclose(countfile); } /* HERE THE CALLS FOR SOME EIGENVALUES */ /* for lowest g_nev = 10; */ /* for largest */ g_nev = 10; max_iter_ev = 1000; stop_prec_ev = 1.e-10; if(g_proc_id==0) { printf(" Values of mu = %e mubar = %e eps = %e precision = %e \n \n", g_mu, g_mubar, g_epsbar, stop_prec_ev); } eigenvalues(&g_nev, operator_flag, max_iter_ev, stop_prec_ev); g_nev = 4; max_iter_ev = 200; stop_prec_ev = 1.e-03; max_eigenvalues(&g_nev, operator_flag, max_iter_ev, stop_prec_ev); if(g_proc_id==0) { printf(" Values of mu = %e mubar = %e eps = %e precision = %e \n \n", g_mu, g_mubar, g_epsbar, stop_prec_ev); /* printf(" Values of mu = %e precision = %e \n \n", g_mu, stop_prec_ev); */ } /* END OF EIGENVALUES CALLS */ if(g_proc_id==0) { rlxd_get(rlxd_state); rlxdfile=fopen("last_state","w"); fwrite(rlxd_state,sizeof(rlxd_state),1,rlxdfile); fclose(rlxdfile); printf("Acceptance Rate was: %e Prozent\n", 100.*(double)Rate/(double)Nmeas); fflush(stdout); parameterfile = fopen(parameterfilename, "a"); fprintf(parameterfile, "Acceptance Rate was: %e Prozent\n", 100.*(double)Rate/(double)Nmeas); fclose(parameterfile); } #ifdef TM_USE_MPI MPI_Finalize(); #endif free_gauge_tmp(); free_gauge_field(); free_geometry_indices(); free_spinor_field(); free_bispinor_field(); free_moment_field(); return(0); }
int main(void) { int k,test1,test2; int *state1,*state2; float sbase; float xs[NXS],ys[NXS],xsn[96]; double base; double xd[NXD],yd[NXD],xdn[48]; sbase=(float)(ldexp(1.0,24)); base=ldexp(1.0,48); state1=malloc(rlxs_size()*sizeof(int)); state2=malloc(rlxd_size()*sizeof(int)); rlxs_init(0,32767); rlxd_init(1,32767); /******************************************************************************* * * Check that the correct sequences of random numbers are obtained * *******************************************************************************/ for (k=0;k<20;k++) { ranlxs(xs,NXS); ranlxd(xd,NXD); } xsn[0]=13257445.0f; xsn[1]=15738482.0f; xsn[2]=5448599.0f; xsn[3]=9610459.0f; xsn[4]=1046025.0f; xsn[5]=2811360.0f; xsn[6]=14923726.0f; xsn[7]=2287739.0f; xsn[8]=16133204.0f; xsn[9]=16328320.0f; xsn[10]=12980218.0f; xsn[11]=9256959.0f; xsn[12]=5633754.0f; xsn[13]=7422961.0f; xsn[14]=6032411.0f; xsn[15]=14970828.0f; xsn[16]=10717272.0f; xsn[17]=2520878.0f; xsn[18]=8906135.0f; xsn[19]=8507426.0f; xsn[20]=11925022.0f; xsn[21]=12042827.0f; xsn[22]=12263021.0f; xsn[23]=4828801.0f; xsn[24]=5300508.0f; xsn[25]=13346776.0f; xsn[26]=10869790.0f; xsn[27]=8520207.0f; xsn[28]=11213953.0f; xsn[29]=14439320.0f; xsn[30]=5716476.0f; xsn[31]=13600448.0f; xsn[32]=12545579.0f; xsn[33]=3466523.0f; xsn[34]=113906.0f; xsn[35]=10407879.0f; xsn[36]=12058596.0f; xsn[37]=4390921.0f; xsn[38]=1634350.0f; xsn[39]=9823280.0f; xsn[40]=12569690.0f; xsn[41]=8267856.0f; xsn[42]=5869501.0f; xsn[43]=7210219.0f; xsn[44]=1362361.0f; xsn[45]=2956909.0f; xsn[46]=504465.0f; xsn[47]=6664636.0f; xsn[48]=6048963.0f; xsn[49]=1098525.0f; xsn[50]=1261330.0f; xsn[51]=2401071.0f; xsn[52]=8087317.0f; xsn[53]=1293933.0f; xsn[54]=555494.0f; xsn[55]=14872475.0f; xsn[56]=11261534.0f; xsn[57]=166813.0f; xsn[58]=13424516.0f; xsn[59]=15280818.0f; xsn[60]=4644497.0f; xsn[61]=6333595.0f; xsn[62]=10012569.0f; xsn[63]=6878028.0f; xsn[64]=9176136.0f; xsn[65]=8379433.0f; xsn[66]=11073957.0f; xsn[67]=2465529.0f; xsn[68]=13633550.0f; xsn[69]=12721649.0f; xsn[70]=569725.0f; xsn[71]=6375015.0f; xsn[72]=2164250.0f; xsn[73]=6725885.0f; xsn[74]=7223108.0f; xsn[75]=4890858.0f; xsn[76]=11298261.0f; xsn[77]=12086020.0f; xsn[78]=4447706.0f; xsn[79]=1164782.0f; xsn[80]=1904399.0f; xsn[81]=16669839.0f; xsn[82]=2586766.0f; xsn[83]=3605708.0f; xsn[84]=15761082.0f; xsn[85]=14937769.0f; xsn[86]=13965017.0f; xsn[87]=2175021.0f; xsn[88]=16668997.0f; xsn[89]=13996602.0f; xsn[90]=6313099.0f; xsn[91]=15646036.0f; xsn[92]=9746447.0f; xsn[93]=9596781.0f; xsn[94]=9244169.0f; xsn[95]=4731726.0f; xdn[0]=135665102723086.0; xdn[1]=259840970195871.0; xdn[2]=110726726657103.0; xdn[3]=53972500363809.0; xdn[4]=199301297412157.0; xdn[5]=63744794353870.0; xdn[6]=178745978725904.0; xdn[7]=243549380863176.0; xdn[8]=244796821836177.0; xdn[9]=223788809121855.0; xdn[10]=113720856430443.0; xdn[11]=124607822268499.0; xdn[12]=25705458431399.0; xdn[13]=155476863764950.0; xdn[14]=195602097736933.0; xdn[15]=183038707238950.0; xdn[16]=62268883953527.0; xdn[17]=157047615112119.0; xdn[18]=58134973897037.0; xdn[19]=26908869337679.0; xdn[20]=259927185454290.0; xdn[21]=130534606773507.0; xdn[22]=205295065526788.0; xdn[23]=40201323262686.0; xdn[24]=193822255723177.0; xdn[25]=239720285097881.0; xdn[26]=54433631586673.0; xdn[27]=31313178820772.0; xdn[28]=152904879618865.0; xdn[29]=256187025780734.0; xdn[30]=110292144635528.0; xdn[31]=26555117184469.0; xdn[32]=228913371644996.0; xdn[33]=126837665590799.0; xdn[34]=141069100232139.0; xdn[35]=96171028602910.0; xdn[36]=259271018918511.0; xdn[37]=65257892816619.0; xdn[38]=14254344610711.0; xdn[39]=137794868158301.0; xdn[40]=269703238916504.0; xdn[41]=35782602710520.0; xdn[42]=51447305327263.0; xdn[43]=247852246697199.0; xdn[44]=65072958134912.0; xdn[45]=273325640150591.0; xdn[46]=2768714666444.0; xdn[47]=173907458721736.0; test1=0; test2=0; for (k=0;k<96;k++) { if (xsn[k]!=(xs[k+60]*sbase)) test1=1; } for (k=0;k<48;k++) { if (xdn[k]!=(xd[k+39]*base)) test2=1; } if (test1==1) { printf("\n"); printf("Test failed: ranlxs gives incorrect results\n"); printf("=> do not use ranlxs on this machine\n"); printf("\n"); } if (test2==1) { printf("\n"); printf("Test failed: ranlxd gives incorrect results\n"); printf("=> do not use ranlxd on this machine\n"); printf("\n"); } /******************************************************************************* * * Check of the I/O routines * *******************************************************************************/ rlxs_get(state1); rlxd_get(state2); for (k=0;k<10;k++) { ranlxs(xs,NXS); ranlxd(xd,NXD); } rlxs_reset(state1); rlxd_reset(state2); for (k=0;k<10;k++) { ranlxs(ys,NXS); ranlxd(yd,NXD); } for (k=0;k<NXS;k++) { if (xs[k]!=ys[k]) test1=2; } for (k=0;k<NXD;k++) { if (xd[k]!=yd[k]) test2=2; } if (test1==2) { printf("\n"); printf("Test failed: I/O routines for ranlxs do not work properly\n"); printf("=> do not use ranlxs on this machine\n"); printf("\n"); } if (test2==2) { printf("\n"); printf("Test failed: I/O routines for ranlxd do not work properly\n"); printf("=> do not use ranlxd on this machine\n"); printf("\n"); } /******************************************************************************* * * Success messages * *******************************************************************************/ if ((test1==0)&&(test2==0)) { printf("\n"); printf("All tests passed\n"); printf("=> ranlxs and ranlxd work correctly on this machine\n"); printf("\n"); } else if (test1==0) { printf("\n"); printf("All tests on ranlxs passed\n"); printf("=> ranlxs works correctly on this machine\n"); printf("\n"); } else if (test2==0) { printf("\n"); printf("All tests on ranlxd passed\n"); printf("=> ranlxd works correctly on this machine\n"); printf("\n"); } exit(0); }
void random_spinor_field(spinor * const k, const int V, const int repro) { int ix; int rlxd_state[105]; spinor *s; double v[6]; #ifdef MPI int j=0; #endif if(g_proc_id==0 && repro == 1) { for (ix = 0; ix < V; ix++) { s = k + ix; gauss_vector(v,6); (*s).s0.c0.re=v[0]; (*s).s0.c0.im=v[1]; (*s).s0.c1.re=v[2]; (*s).s0.c1.im=v[3]; (*s).s0.c2.re=v[4]; (*s).s0.c2.im=v[5]; gauss_vector(v,6); (*s).s1.c0.re=v[0]; (*s).s1.c0.im=v[1]; (*s).s1.c1.re=v[2]; (*s).s1.c1.im=v[3]; (*s).s1.c2.re=v[4]; (*s).s1.c2.im=v[5]; gauss_vector(v,6); (*s).s2.c0.re=v[0]; (*s).s2.c0.im=v[1]; (*s).s2.c1.re=v[2]; (*s).s2.c1.im=v[3]; (*s).s2.c2.re=v[4]; (*s).s2.c2.im=v[5]; gauss_vector(v,6); (*s).s3.c0.re=v[0]; (*s).s3.c0.im=v[1]; (*s).s3.c1.re=v[2]; (*s).s3.c1.im=v[3]; (*s).s3.c2.re=v[4]; (*s).s3.c2.im=v[5]; } /* send the state for the random-number generator to 1 */ rlxd_get(rlxd_state); #ifdef MPI if(g_nproc > 1) { MPI_Send(&rlxd_state[0], 105, MPI_INT, 1, 102, MPI_COMM_WORLD); } #endif } #ifdef MPI if(g_proc_id != 0 && repro == 1) { MPI_Recv(&rlxd_state[0], 105, MPI_INT, g_proc_id-1, 102, MPI_COMM_WORLD, &status); rlxd_reset(rlxd_state); for (ix=0;ix<V;ix++) { s = k + ix; gauss_vector(v,6); (*s).s0.c0.re=v[0]; (*s).s0.c0.im=v[1]; (*s).s0.c1.re=v[2]; (*s).s0.c1.im=v[3]; (*s).s0.c2.re=v[4]; (*s).s0.c2.im=v[5]; gauss_vector(v,6); (*s).s1.c0.re=v[0]; (*s).s1.c0.im=v[1]; (*s).s1.c1.re=v[2]; (*s).s1.c1.im=v[3]; (*s).s1.c2.re=v[4]; (*s).s1.c2.im=v[5]; gauss_vector(v,6); (*s).s2.c0.re=v[0]; (*s).s2.c0.im=v[1]; (*s).s2.c1.re=v[2]; (*s).s2.c1.im=v[3]; (*s).s2.c2.re=v[4]; (*s).s2.c2.im=v[5]; gauss_vector(v,6); (*s).s3.c0.re=v[0]; (*s).s3.c0.im=v[1]; (*s).s3.c1.re=v[2]; (*s).s3.c1.im=v[3]; (*s).s3.c2.re=v[4]; (*s).s3.c2.im=v[5]; } /* send the state fo the random-number generator to k+1 */ j=g_proc_id+1; if(j==g_nproc){ j=0; } rlxd_get(rlxd_state); MPI_Send(&rlxd_state[0], 105, MPI_INT, j, 102, MPI_COMM_WORLD); } if(g_nproc > 1 && g_proc_id==0 && repro == 1) { MPI_Recv(&rlxd_state[0], 105, MPI_INT, g_nproc-1, 102, MPI_COMM_WORLD, &status); rlxd_reset(rlxd_state); } #endif if(repro != 1) { for (ix = 0; ix < V; ix++) { s = k + ix; gauss_vector(v,6); (*s).s0.c0.re=v[0]; (*s).s0.c0.im=v[1]; (*s).s0.c1.re=v[2]; (*s).s0.c1.im=v[3]; (*s).s0.c2.re=v[4]; (*s).s0.c2.im=v[5]; gauss_vector(v,6); (*s).s1.c0.re=v[0]; (*s).s1.c0.im=v[1]; (*s).s1.c1.re=v[2]; (*s).s1.c1.im=v[3]; (*s).s1.c2.re=v[4]; (*s).s1.c2.im=v[5]; gauss_vector(v,6); (*s).s2.c0.re=v[0]; (*s).s2.c0.im=v[1]; (*s).s2.c1.re=v[2]; (*s).s2.c1.im=v[3]; (*s).s2.c2.re=v[4]; (*s).s2.c2.im=v[5]; gauss_vector(v,6); (*s).s3.c0.re=v[0]; (*s).s3.c0.im=v[1]; (*s).s3.c1.re=v[2]; (*s).s3.c1.im=v[3]; (*s).s3.c2.re=v[4]; (*s).s3.c2.im=v[5]; } } }
void source_generation_nucleon(spinor * const P, spinor * const Q, const int is, const int ic, const int t, const int nt, const int nx, const int sample, const int nstore, const int meson) { double rnumber, si=0., co=0., sqr2; int rlxd_state[105]; int reset = 0, seed, r, tt, lt, xx, lx, yy, ly, zz, lz; int coords[4], id=0, i; complex * p = NULL; const double s0=0.; const double c0=1.; const double s1=sin(2.*M_PI/3.); const double c1=cos(2.*M_PI/3.); const double s2=sin(4.*M_PI/3.); const double c2=cos(4.*M_PI/3.); zero_spinor_field(P,VOLUME/2); zero_spinor_field(Q,VOLUME/2); sqr2 = 1./sqrt(2.); /* save the ranlxd_state if neccessary */ if(ranlxd_init == 1) { rlxd_get(rlxd_state); reset = 1; } /* Compute the seed */ seed =(int) abs(1 + sample + t*10*97 + nstore*100*53); rlxd_init(1, seed); for(tt = t; tt < T*g_nproc_t; tt+=nt) { lt = tt - g_proc_coords[0]*T; coords[0] = tt / T; for(xx = 0; xx < LX*g_nproc_x; xx+=nx) { lx = xx - g_proc_coords[1]*LX; coords[1] = xx / LX; for(yy = 0; yy < LY*g_nproc_y; yy+=nx) { ly = yy - g_proc_coords[2]*LY; coords[2] = yy / LY; for(zz = 0; zz < LZ*g_nproc_z; zz+=nx) { lz = zz - g_proc_coords[3]*LZ; coords[3] = zz / LZ; #ifdef MPI MPI_Cart_rank(g_cart_grid, coords, &id); #endif ranlxd(&rnumber, 1); if(g_cart_id == id) { if(meson) { r = (int)floor(4.*rnumber); if(r == 0) { si = sqr2; co = sqr2; } else if(r == 1) { si = -sqr2; co = sqr2; } else if(r==2) { si = sqr2; co = -sqr2; } else { si = -sqr2; co = -sqr2; } } else { r = (int)floor(3.*rnumber); if(r == 0) { si = s0; co = c0; } else if(r == 1) { si = s1; co = c1; } else { si = s2; co = c2; } } i = g_lexic2eosub[ g_ipt[lt][lx][ly][lz] ]; if((lt+lx+ly+lz+g_proc_coords[3]*LZ+g_proc_coords[2]*LY + g_proc_coords[0]*T+g_proc_coords[1]*LX)%2 == 0) { p = (complex*)(P + i); } else { p = (complex*)(Q + i); } (*(p+3*is+ic)).re = co; (*(p+3*is+ic)).im = si; } } } } } /* reset the ranlxd if neccessary */ if(reset) { rlxd_reset(rlxd_state); } return; }
/* Florian Burger 4.11.2009 */ void source_generation_pion_zdir(spinor * const P, spinor * const Q, const int z, const int sample, const int nstore) { int reset = 0, i, x, y, t, is, ic, lt, lx, ly, lz, id=0; int coords[4], seed, r; double rnumber, si=0., co=0.; int rlxd_state[105]; const double sqr2 = 1./sqrt(2.); complex * p = NULL; zero_spinor_field(P,VOLUME/2); zero_spinor_field(Q,VOLUME/2); /* save the ranlxd_state if neccessary */ if(ranlxd_init == 1) { rlxd_get(rlxd_state); reset = 1; } /* Compute the seed */ seed =(int) abs(1 + sample + z*10*97 + nstore*100*53 + g_cart_id*13); rlxd_init(1, seed); lz = z - g_proc_coords[3]*LZ; coords[3] = z / LZ; for(t = 0; t < T*g_nproc_t; t++) { lt = t - g_proc_coords[0]*T; coords[0] = t / T; for(x = 0; x < LX*g_nproc_x; x++) { lx = x - g_proc_coords[1]*LX; coords[1] = x / LX; for(y = 0; y < LY*g_nproc_y; y++) { ly = y - g_proc_coords[2]*LY; coords[2] = y / LY; #ifdef MPI MPI_Cart_rank(g_cart_grid, coords, &id); #endif for(is = 0; is < 4; is++) { for(ic = 0; ic < 3; ic++) { ranlxd(&rnumber, 1); if(g_cart_id == id) { r = (int)floor(4.*rnumber); if(r == 0) { si = sqr2; co = sqr2; } else if(r == 1) { si = -sqr2; co = sqr2; } else if(r==2) { si = sqr2; co = -sqr2; } else { si = -sqr2; co = -sqr2; } i = g_lexic2eosub[ g_ipt[lt][lx][ly][lz] ]; if((lt+lx+ly+lz+g_proc_coords[3]*LZ+g_proc_coords[2]*LY + g_proc_coords[0]*T+g_proc_coords[1]*LX)%2 == 0) { p = (complex*)(P + i); } else { p = (complex*)(Q + i); } (*(p+3*is+ic)).re = co; (*(p+3*is+ic)).im = si; } } } } } } /* reset the ranlxd if neccessary */ if(reset) { rlxd_reset(rlxd_state); } return; }
/************************************** * * Initialises the momenta * with the gaussian distribution * **************************************/ double ini_momenta(const int repro) { su3adj *xm; int i, mu; #ifdef MPI int k; int rlxd_state[105]; #endif static double y[8]; static double tt,tr,ts,kc,ks,sum; if(repro == 1) { if(g_proc_id==0){ kc=0.; ks=0.; for(i=0;i<VOLUME;i++){ for(mu=0;mu<4;mu++){ sum=0.; xm=&moment[i][mu]; gauss_vector(y,8); /* from the previous line we get exp(-y^2) distribution */ /* this means that <y^2> = sigma^2 = 1/2 */ /* in order to get <y^2> = 1 distribution ==> *sqrt(2) */ (*xm).d1=1.4142135623731*y[0]; (*xm).d2=1.4142135623731*y[1]; sum+=(*xm).d1*(*xm).d1+(*xm).d2*(*xm).d2; (*xm).d3=1.4142135623731*y[2]; (*xm).d4=1.4142135623731*y[3]; sum+=(*xm).d3*(*xm).d3+(*xm).d4*(*xm).d4; (*xm).d5=1.4142135623731*y[4]; (*xm).d6=1.4142135623731*y[5]; sum+=(*xm).d5*(*xm).d5+(*xm).d6*(*xm).d6; (*xm).d7=1.4142135623731*y[6]; (*xm).d8=1.4142135623731*y[7]; sum+=(*xm).d7*(*xm).d7+(*xm).d8*(*xm).d8; tr=sum+kc; ts=tr+ks; tt=ts-ks; ks=ts; kc=tr-tt; } } #ifdef MPI /* send the state for the random-number generator to 1 */ rlxd_get(rlxd_state); MPI_Send(&rlxd_state[0], 105, MPI_INT, 1, 101, MPI_COMM_WORLD); #endif } #ifdef MPI if(g_proc_id != 0){ MPI_Recv(&rlxd_state[0], 105, MPI_INT, g_proc_id-1, 101, MPI_COMM_WORLD, &status); rlxd_reset(rlxd_state); kc=0.; ks=0.; for(i=0;i<VOLUME;i++){ for(mu=0;mu<4;mu++){ sum=0.; xm=&moment[i][mu]; gauss_vector(y,8); (*xm).d1=1.4142135623731*y[0]; (*xm).d2=1.4142135623731*y[1]; sum+=(*xm).d1*(*xm).d1+(*xm).d2*(*xm).d2; (*xm).d3=1.4142135623731*y[2]; (*xm).d4=1.4142135623731*y[3]; sum+=(*xm).d3*(*xm).d3+(*xm).d4*(*xm).d4; (*xm).d5=1.4142135623731*y[4]; (*xm).d6=1.4142135623731*y[5]; sum+=(*xm).d5*(*xm).d5+(*xm).d6*(*xm).d6; (*xm).d7=1.4142135623731*y[6]; (*xm).d8=1.4142135623731*y[7]; sum+=(*xm).d7*(*xm).d7+(*xm).d8*(*xm).d8; tr=sum+kc; ts=tr+ks; tt=ts-ks; ks=ts; kc=tr-tt; } } /* send the state fo the random-number generator to next processor */ k=g_proc_id+1; if(k==g_nproc){ k=0; } rlxd_get(rlxd_state); MPI_Send(&rlxd_state[0], 105, MPI_INT, k, 101, MPI_COMM_WORLD); } #endif kc=0.5*(ks+kc); #ifdef MPI if(g_proc_id == 0){ MPI_Recv(&rlxd_state[0], 105, MPI_INT, g_nproc-1, 101, MPI_COMM_WORLD, &status); rlxd_reset(rlxd_state); } #endif } else { kc=0.; ks=0.; for(i=0;i<VOLUME;i++){ for(mu=0;mu<4;mu++){ sum=0.; xm=&moment[i][mu]; gauss_vector(y,8); (*xm).d1=1.4142135623731*y[0]; (*xm).d2=1.4142135623731*y[1]; sum+=(*xm).d1*(*xm).d1+(*xm).d2*(*xm).d2; (*xm).d3=1.4142135623731*y[2]; (*xm).d4=1.4142135623731*y[3]; sum+=(*xm).d3*(*xm).d3+(*xm).d4*(*xm).d4; (*xm).d5=1.4142135623731*y[4]; (*xm).d6=1.4142135623731*y[5]; sum+=(*xm).d5*(*xm).d5+(*xm).d6*(*xm).d6; (*xm).d7=1.4142135623731*y[6]; (*xm).d8=1.4142135623731*y[7]; sum+=(*xm).d7*(*xm).d7+(*xm).d8*(*xm).d8; tr=sum+kc; ts=tr+ks; tt=ts-ks; ks=ts; kc=tr-tt; } } kc=0.5*(ks+kc); } #ifdef MPI MPI_Allreduce(&kc, &ks, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); return ks; #endif return kc; }
int main(int argc, char **argv) { int c, gid, sid; unsigned long int ix, iix; int i, x0; int filename_set = 0; int N_ape=0, N_Jacobi=0, timeslice=0, Nlong=-1; int precision = 32; int *rng_state=NULL; int rng_readin=0; double alpha_ape=0., kappa_Jacobi = 0.; double ran[24]; double *gauge_field_f = (double*)NULL; char filename[800]; unsigned long int VOL3; FILE *ofs; DML_Checksum checksum; while ((c = getopt(argc, argv, "h?prf:i:a:n:l:K:t:")) != -1) { switch (c) { case 'f': strcpy(filename, optarg); filename_set = 1; break; case 'i': N_ape = atoi(optarg); break; case 'a': alpha_ape = atof(optarg); break; case 'n': N_Jacobi = atoi(optarg); break; case 'K': kappa_Jacobi = atof(optarg); break; case 'l': Nlong = atoi(optarg); break; case 't': timeslice = atoi(optarg); break; case 'p': precision = 64; break; case 'r': rng_readin = 1; break; case '?': default: usage(); break; } } /*********************** * read the input file * ***********************/ if(filename_set==0) strcpy(filename, "cvc.input"); if(g_cart_id==0) fprintf(stdout, "# Reading input from file %s\n", filename); read_input_parser(filename); /********************************* * some checks on the input data * *********************************/ if((T_global == 0) || (LX==0) || (LY==0) || (LZ==0)) { if(g_proc_id==0) fprintf(stdout, "T and L's must be set\n"); usage(); } /* initialize MPI parameters */ mpi_init(argc, argv); T = T_global; Tstart = 0; VOL3 = LX*LY*LZ; if(init_geometry() != 0) { fprintf(stderr, "ERROR from init_geometry\n"); return(102); } geometry(); /************************* * reset T to 1 *************************/ T = 1; Tstart = timeslice; /******************************************* * check for source type, has to be 2 *******************************************/ if(g_source_type!=1) { /* timeslice sources */ fprintf(stderr, "Warning, source type is %d, but will generate volume source\n", g_source_type); } /* initialize random number generator */ if(rng_readin==0) { fprintf(stdout, "# ranldxd: using seed %u and level 2\n", g_seed); rlxd_init(2, g_seed); } else { sprintf(filename, ".ranlxd_state"); if( (ofs = fopen(filename, "r")) == (FILE*)NULL) { fprintf(stderr, "Error, could not read the random number generator state\n"); return(105); } fprintf(stdout, "# reading rng state from file %s\n", filename); fscanf(ofs, "%d\n", &c); if( (rng_state = (int*)malloc(c*sizeof(int))) == (int*)NULL ) { fprintf(stderr, "Error, could not read the random number generator state\n"); return(106); } rng_state[0] = c; fprintf(stdout, "# rng_state[%3d] = %3d\n", 0, rng_state[0]); for(i=1; i<c; i++) { fscanf(ofs, "%d", rng_state+i); fprintf(stdout, "# rng_state[%3d] = %3d\n", i, rng_state[i]); } fclose(ofs); rlxd_reset(rng_state); free(rng_state); } /* prepare the spinor field */ no_fields=1; g_spinor_field = (double**)calloc(no_fields, sizeof(double*)); for(i=0; i<no_fields; i++) {alloc_spinor_field(&g_spinor_field[i], VOL3);} for(gid=g_gaugeid; gid<=g_gaugeid2; gid+=g_gauge_step) { for(sid=g_sourceid; sid<=g_sourceid2; sid+=g_sourceid_step) { fprintf(stdout, "# Generating volume sources for gid=%d and sid=%d\n", gid, sid); for(x0=0; x0<T_global; x0++) { for(ix=0; ix<VOL3; ix++) { switch(g_noise_type) { case 1: rangauss(ran, 24); break; case 2: ranz2(ran, 24); break; } _fv_eq_fv(g_spinor_field[0]+_GSI(ix), ran); } fprintf(stdout, "# finished generating source\n"); /* fprintf(stdout, "# source spinor field for timeslice no. %d\n", x0); for(ix=0; ix<VOL3; ix++) { for(c=0; c<12; c++) { fprintf(stdout, "%3d%6d%3d%25.16e%25.16e\n", x0, ix, c, g_spinor_field[0][_GSI(ix)+2*c], g_spinor_field[0][_GSI(ix)+2*c+1]); } } */ /****************************************************************** * write the source ******************************************************************/ //sprintf(filename, "%s.%.4d.%.2d", filename_prefix, gid, sid); sprintf(filename, "%s.%.4d.%.5d", filename_prefix, gid, sid); fprintf(stdout, "# writing source to file %s\n", filename); write_lime_spinor_timeslice(g_spinor_field[0], filename, precision, x0, &checksum); } fprintf(stdout, "#\t finished all for sid = %d\n", sid); } /* loop on sid */ fprintf(stdout, "# finished all for gid = %d\n", gid); } /* loop on gid */ for(i=0; i<no_fields; i++) free(g_spinor_field[i]); free(g_spinor_field); c = rlxd_size(); if( (rng_state = (int*)malloc(c*sizeof(int))) == (int*)NULL ) { fprintf(stderr, "Error, could not save the random number generator state\n"); return(102); } rlxd_get(rng_state); sprintf(filename, ".ranlxd_state"); if( (ofs = fopen(filename, "w")) == (FILE*)NULL) { fprintf(stderr, "Error, could not save the random number generator state\n"); return(103); } fprintf(stdout, "# writing rng state to file %s\n", filename); for(i=0; i<c; i++) fprintf(ofs, "%d\n", rng_state[i]); fclose(ofs); free(rng_state); return(0); }
void rlxdresetf_(int *state1) { rlxd_reset(state1); }