Exemplo n.º 1
0
int main(int argc, char *argv[])
{
    double a = 1, b = 2, S, I = primitive(b) - primitive(a);
    unsigned i, n = 10;
    if(argc > 1) n = atoi(argv[1]);
    rlxd_init(2,time(NULL));
    FILE *f1 = fopen("integral1.dat","a");
    FILE *f2 = fopen("integral2.dat","a");
    FILE *f3 = fopen("integral3.dat","a");
    FILE *f4 = fopen("integral4.dat","a");

    for(S = i = 0; i < n; i++)
        S += newton_cotes1(function, a+i*(b-a)/n, a+(i+1)*(b-a)/n);
    fprintf(f1,"%d\t%e\n", n, fabs(I-S));

    for(S = i = 0; i < n; i++)
        S += newton_cotes2(function, a+i*(b-a)/n, a+(i+1)*(b-a)/n);
    fprintf(f2,"%d\t%e\n", n, fabs(I-S));

    for(S = i = 0; i < n; i++)
        S += gauss5(function, a+i*(b-a)/n, a+(i+1)*(b-a)/n);
    fprintf(f3,"%d\t%e\n", n, fabs(I-S));

    S = monte_carlo(function, a, b, n);
    fprintf(f4,"%d\t%e\n", n, fabs(I-monte_carlo(function, a, b, n)));

    fclose(f1);
    fclose(f2);
    fclose(f3);
    fclose(f4);

    return 0;
}
Exemplo n.º 2
0
int main (int argc, char *argv[]) {
	double Pi  = 0;
	rlxd_init(1,time(NULL)%5000);
	Pi= meanPi();
	printf("Pi = %lf \n", (double) Pi);
	return (0);
	}
Exemplo n.º 3
0
void start_ranlux(int level,int seed)
{
   int max_seed,loc_seed;

   max_seed=2147483647/g_nproc;
   loc_seed=seed+g_proc_id*max_seed;

   rlxs_init(level-1,loc_seed);
   rlxd_init(level,loc_seed);
}
Exemplo n.º 4
0
int main(int argc, char **argv) 
{
 /* Initialize the random number generator */
 rlxd_init(2, 12345); 
 /* Initialize the lattice geometry */
 init_lattice(X1, X2);
  
 //Testing the hermiticity of gam5D_wilson
 //Operator is Hermitian if for any vectors x and y (y, Ax) = (Ay, x)
 //1. Write the procedure which fills a spinor field with gaussian-distributed complex random numbers such that <z z*> = 1
 //2. Initialize two random spinor fields X and Y (arrays of type spinor and size GRIDPOINTS) 
 //3. Check that (y, Ax) = (Ay, x)
 
 spinor X[GRIDPOINTS], Y[GRIDPOINTS], tmp[GRIDPOINTS];
 rand_spinor(X);
 rand_spinor(Y);
 //Calculating p1 = (y, Ax)
 gam5D_wilson(tmp, X);
 complex double p1 = scalar_prod(Y, tmp);
 //Calculating p2 = (Ax, y)
 gam5D_wilson(tmp, Y);
 complex double p2 = scalar_prod(tmp, X);
 //Check that p1 and p2 are equal
 double epsilon = cabs(p1 - p2);
 printf("\n\n\t Hermiticity check: |p1 - p2| = %2.2E - %s \n\n", epsilon, (epsilon < 1E-14)? "OK":"No");

 //Testing the performance of the Conjugate Gradient Solver
 //1. In order to monitor the progress of the solver, #define MONITOR_CG_PROGRESS in linalg.h
 //   This will print the squared norm of the residue at each iteration to the screen
 //2. Initialize the gauge fields with the coldstart() procedure
 //3. Generate a random spinor field  Y and use cg(X, Y, ITER_MAX, DELTACG, &gam5D_SQR_wilson)
 //   to solve the equation (gamma_5 D)^2 X = Y
 //   (gamma_5 D)^2 is implemented as gam5D_SQR_wilson(out, temp, in), see Dirac.h
 //4. Now apply gam5D_SQR_wilson to X, subtract Y and calculate the norm of the result
 //5. Do the same with hotstart() and see how the number of CG iterations changes

 coldstart();
 spinor Y1[GRIDPOINTS];
 rand_spinor(Y);
 cg(X, Y, ITER_MAX, DELTACG, &gam5D_SQR_wilson);
 gam5D_SQR_wilson(Y1, tmp, X);
 diff(tmp, Y1, Y);
 epsilon = sqrt(square_norm(tmp));
 printf("\n\n\t Test of CG inverter: |Q X - Y| = %2.2E - %s \n\n", epsilon, (epsilon < 1E-6)? "OK":"No");

 free(left1);
 free(left2);
 free(right1);
 free(right2);
  
 system("PAUSE");
 return 0;
}
Exemplo n.º 5
0
int main (){
  /* Estremi di integrazione */
	double min =-100 ;
	double max= 100;
	int N = Nstart;
	int i = 0;
	int j = 0;
	int momentIndex = 0;
	rtn_int_var result[Ncycle*MaxMoment/2];
	noise noise_result[Ncycle*MaxMoment/2];
	rlxd_init(2,time(NULL));
	printf("\t \t  \t flat  \t gauss  \t root_exp \n");
	nMoment=&momentIndex;
	momentIndex = 2;
	for ( j=0; j<Ncycle; j++){
		printf("I punti usati sono %d \n",N);
		momentIndex = 2;
		for(i=0; i < MaxMoment/2; i++){
			/* Calcola i valori di tutti gli integrali per le varie pdf e li salva nell'array di strutture result*/
			result[(MaxMoment/2)*j+i] = campionamentoImportanza(min,max,N,integrand);
			printf("Il momento  numero %d : %lf \t %lf \t %lf \t \n",momentIndex,
					result[(MaxMoment/2)*j+i].int_flat, result[(MaxMoment/2)*j+i].int_gauss,result[(MaxMoment/2)*j+i].int_root);
			printf("Errori: \t");
			printf("\t %lf \t %lf \t %lf \n",sqrt(result[(MaxMoment/2)*j+i].var_flat),sqrt(result[(MaxMoment/2)*j+i].var_gauss),		sqrt(result[(MaxMoment/2)*j+i].var_root));
			printf("\n");
			momentIndex+=2;
			}
		N*=2;
	}
	for(j=0; j< Ncycle*MaxMoment/2; j++){
	noise_result[j] = fitNoise(result[j]);
	}
	/*
	 *Stampano vari file:
	 * plot contiene tutti i risultati
	 * printplot per il valore del'integrale con errore
	 * fprintnoiseplot per il valore del rumore
	 */
	fprintStruct(result,Ncycle*MaxMoment/2,"../../data/plot.dat");
	fprintPlot(result,Ncycle*MaxMoment/2,1,"../../data/flat.dat");
	fprintPlot(result,Ncycle*MaxMoment/2,2,"../../data/gauss.dat");
	fprintPlot(result,Ncycle*MaxMoment/2,3,"../../data/root.dat");
	fprintNoisePlot(noise_result,Ncycle*MaxMoment/2,1,"../../data/flat_scaled.dat");
	fprintNoisePlot(noise_result,Ncycle*MaxMoment/2,2,"../../data/gauss_scaled.dat");
	fprintNoisePlot(noise_result,Ncycle*MaxMoment/2,3,"../../data/root_scaled.dat");
	plot("../../data/flat.dat","../../data/gauss.dat","../../data/root.dat");
	plot_noise("../../data/flat_scaled.dat","../../data/gauss_scaled.dat","../../data/root_scaled.dat");
	return(EXIT_SUCCESS);
}
Exemplo n.º 6
0
/* 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;
}
Exemplo n.º 7
0
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);
}
Exemplo n.º 8
0
int main(int argc, char **argv) 
{
	int i, l;
  	int accepted = 0;        //Total number of accepted configurations
  	int total_updates = 0;   //Total number of updates
	clock_t begin, end;

  	/* Initialize the random number generator */
  	rlxd_init(2, time(NULL)); 
  	/* Initialize the lattice geometry */
  	init_lattice(Lx, Ly, Lt);
  	/* Initialize the fields */
  	hotstart();
  	/* Print out the run parameters */
  	echo_sim_params();
	
	mc_init();
  	/* thermalization */
  	mc_iter = 0; //Counts the total number of calls to the update() routine
  	printf("\n Thermalization: \n\n");

	//begin = clock();
  	for(i=0; i<g_thermalize; i++)
  	{
   		mc_update();
		//printf("\t Step %04i\n", i);
  	};
	//end = clock();
	//printf("Time for one MC update: %f\n", (double)(end - begin) / CLOCKS_PER_SEC);

	/* measure the iterations only during real simulation, not thermalization */
  	R              = 0; //Counts the total number of accepted configurations
  	mc_iter       = 0; //Counts the total number of calls to the update() routine

  	printf("\n Generation: \n\n");
	measurement_init();
	measure();
	printf("Average density: \t %.5f %.5f\n", creal(m_density[measure_iter]), cimag(m_density[measure_iter]));
	printf("Wilson plaquette: \t %.5f\n", mean_plaq());

  	for(i=0; i<g_measurements; i++) 
  	{
   	/* do g_intermediate updates before measurement */
   		for (l=0; l<g_intermediate; l++)
   		{
    		mc_update();
   		};
   		mc_update();

		/* doing measurement */
		measure();
		printf("Average density: \t %.5f %.5f\n", creal(m_density[measure_iter]), cimag(m_density[measure_iter]));
		printf("Wilson plaquette: \t %.5f\n", mean_plaq());
		fflush(stdout);
  	};
	printf("Wrapping up...\n");
	output_measurement();
 	measurement_finish();
	
  	/* Some output for diagnostics */
  	total_updates = g_measurements*(g_intermediate + 1)*GRIDPOINTS;
  	printf("\n\n Algorithm performance:\n");
  	printf("\t Acceptance rate:             %.4f\n", (double)R/(double)total_updates);

  	return 0;
}
Exemplo n.º 9
0
int main(){

   int ieq,imeas,iskp;
   int i,j,readval,parity,val;   
   double norm; 
   extern void neighbours();
   extern void neighchk();
   extern double ran();
   extern void clusteven();
   extern void clustodd();
   extern void chkconf();
   extern void measureMAB();
   extern void measureflux(int);
   extern void constflux();
   extern void initconf();
   extern double **allocatedouble2d(int,int);
   extern void deallocatedouble2d(double**,int,int);
   extern int **allocate2d(int,int);
   extern void deallocate2d(int**,int,int);
   

   FILE *fptr;
   char st[20];
   /* read file */
   fptr=fopen("QUEUE","r");
   if(fptr == NULL) {printf("QUEUE error.\n"); exit(1);}
   readval = fscanf(fptr,"%s %d\n",st,&LX);
   if(readval == -1) printf("Error\n");
   readval = fscanf(fptr,"%s %d\n",st,&LY);
   if(readval == -1) printf("Error\n");
   readval = fscanf(fptr,"%s %d\n",st,&LT2);
   if(readval == -1) printf("Error\n");
   readval = fscanf(fptr,"%s %d\n",st,&SEED);
   if(readval == -1) printf("Error\n");
   readval = fscanf(fptr,"%s %d\n",st,&ieq);
   if(readval == -1) printf("Error\n");
   readval = fscanf(fptr,"%s %d\n",st,&imeas);
   if(readval == -1) printf("Error\n");
   readval = fscanf(fptr,"%s %lf\n",st,&beta);
   if(readval == -1) printf("Error\n");
   readval = fscanf(fptr,"%s %lf\n",st,&J);
   if(readval == -1) printf("Error\n");
   readval = fscanf(fptr,"%s %lf\n",st,&lam);
   if(readval == -1) printf("Error\n");
   fclose(fptr);
  
  printf("Multi-Cluster Algorithm for the U(1) quantum link model\n");
  printf("Nx=%d, Ny=%d, Nt=%d\n",LX,LY,LT2);
  printf("beta=%2.4f; J=%2.3f; lam=%2.3f\n",beta,J,lam);
  printf("Starting seed=%d\n",SEED);

   LT  = 2*LT2; /* the dof are spread over twice actual length */
   VOL = LX*LY*LT;
   SVOL= LX*LY/2;
   SPV = 2*SVOL;
   SIZE= 2*SVOL+1;
   VOL2= VOL/2;
   VOL4= VOL/4;
   minMA = minMB = -LX*LY/2;
   maxMA = maxMB =  LX*LY/2;
   
   /* allocate memory */
   ixc   = (int *)malloc(VOL*sizeof(int));
   iyc   = (int *)malloc(VOL*sizeof(int));
   itc   = (int *)malloc(VOL*sizeof(int));
   ising = (int *)malloc(VOL*sizeof(int));
   list  = (int *)malloc(VOL*sizeof(int));
   avflx1= (double *)malloc(SPV*sizeof(double));
   avfly1= (double *)malloc(SPV*sizeof(double));
   avflx2= (double *)malloc(SPV*sizeof(double));
   avfly2= (double *)malloc(SPV*sizeof(double));
   chptr = (int *)malloc(VOL2*sizeof(double)); 
   backt = (int *)malloc(LT*sizeof(double));
   /* MA and MB will be measured for each of the LT/2 timeslices and avg-d */
   MA    = (int *)malloc((LT2)*sizeof(int));
   MB    = (int *)malloc((LT2)*sizeof(int));
   pMAB  = allocatedouble2d(SIZE,SIZE);
   refC  = allocate2d(LX,LY);
   fx    = allocate2d(LT,SPV);
   fy    = allocate2d(LT,SPV);
   for(i=0;i<NNBR;i++) neigh[i] = (int *)malloc(VOL*sizeof(int));
   for(i=0;i<2*DIM+1;i++) next[i] = (int *)malloc(VOL*sizeof(int));

   /* Set parameters */
   eps=1.0*beta/((double)LT);
   iskp=1;

  /* Initialize ranlux */
  rlxd_init(1,SEED);

  /* initialize neighbours */
  neighbours();
  //neighchk();

  /* Define the probabilities */
  double x,coshx,sinhx;
  x     = eps*J;
  coshx = (exp(x)+exp(-x))/2.0;
  sinhx = (exp(x)-exp(-x))/2.0;
  p1    = exp(-x)/coshx;
  p2    = 1.0 - exp(eps*lam)/coshx;
  printf("eps = %f\n",eps);
  printf("Prob p1: %f;  Prob p2: %f\n",p1,p2);

  initconf();
  chkconf();
  
  /* initialize back-t pointers */
  for(i=0;i<LT;i++) backt[i]=(i-1+LT)%LT;

  /* initialize the reference configuration */
  for(i=0;i<LX;i++) for(j=0;j<LY;j++){
       parity=(i+j)%2;
       val=(i-j)%4;
       if(parity==0){ /* for the even-time slices */
          if(val==0) refC[i][j]=1;
          else refC[i][j]=-1;
       }
       else{  /* for the odd-time slices */
          if((val==-1)||(val==3)) refC[i][j]=-1;
          else refC[i][j]=1;
       }
  }

  /* initialize average flux variable */
  for(i=0;i<SPV;i++) avflx1[i]=avfly1[i]=avflx2[i]=avflx2[i]=0.0;

  /* update */
  thermflag=1;
  for(i=0;i<ieq;i++){
     nclusevn = 0; nclusevsq=0; mA=0;
     nclusodd = 0; nclusodsq=0; mB=0;
     clusteven();
     clustodd();
     chkconf();
  }
  thermflag=0;
  /* measure */ 
  flxcnt1=flxcnt2=0;
  for(i=0;i<SIZE;i++) for(j=0;j<SIZE;j++) pMAB[i][j]=0.0;
  fptr=fopen("multi.dat","w");
  for(i=0;i<imeas;i++){
     nclusevn = 0; nclusevsq=0; mA=0; 
     nclusodd = 0; nclusodsq=0; mB=0;
     clusteven();
     nclusevsq = nclusevsq/VOL4;
     clustodd();
     nclusodsq = nclusodsq/VOL4;
     nclus = nclusevn + nclusodd;
     measureMAB();
     //measureflux();
     constflux();
     chkconf();
     fprintf(fptr,"%d %d %d %lf %lf %d %d\n",nclusevn,nclusodd,nclus,nclusevsq,nclusodsq,mA,mB);
     //fprintf(fptr,"%e %e %e %e %d %d\n",(double)mA,(double)mB,flx,fly,flt1,flt2);
  }
  fclose(fptr);

  /* normalize and print histogram */
  norm=0.0;
  for(i=0;i<SIZE;i++) for(j=0;j<SIZE;j++) norm += pMAB[i][j];
  fptr=fopen("magdist.dat","w");
  for(i=0;i<SIZE;i++){
  for(j=0;j<SIZE;j++){
   pMAB[i][j] /= norm;
   fprintf(fptr,"%d %d %le\n",i,j,pMAB[i][j]);}
  fprintf(fptr,"\n");}
  fclose(fptr);

  /* average and normalize the flux profile and print it */
  fptr=fopen("fprof.dat","w");
  printf("# meas: %d + %d = %d\n",flxcnt1,flxcnt2,flxcnt1+flxcnt2);
  for(i=0;i<SPV;i++){
    avflx1[i] /= (2.0*LT2*flxcnt1);
    avfly1[i] /= (2.0*LT2*flxcnt1);
    avflx2[i] /= (2.0*LT2*flxcnt2);
    avfly2[i] /= (2.0*LT2*flxcnt2);
    fprintf(fptr,"%d %.5f %.5f %.5f %.5f\n",i,avflx1[i],avfly1[i],avflx2[i],avfly2[i]);
  }
  fclose(fptr);

  /* free memory */
  free(ixc); free(iyc); free(itc);
  free(MA);  free(MB);
  free(avflx1); free(avfly1);
  free(avflx2); free(avfly2);
  free(chptr); free(backt);
  for(i=0;i<NNBR;i++) free(neigh[i]);
  for(i=0;i<2*DIM+1;i++) free(next[i]);
  deallocatedouble2d(pMAB,SIZE,SIZE);
  deallocate2d(refC,LX,LY);
  deallocate2d(fx,LT,SPV);
  deallocate2d(fy,LT,SPV);
  return 0;
 }
Exemplo n.º 10
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);
}
Exemplo n.º 11
0
int main(){
	int i, j, nsfere, nurti, nbin, k;
	double diametro, frimp, tempo, vmedia[2], encin, temperatura, press, auxilium, intervallofrimp;
	double *x, *y, *vx, *vy, *dativx, *dativy, **datitempicollisioni;
	double **matricetempi;
	FILE *filefreqvx, *filefreqvy;
	
	/*Inizializzo le variabili*/
	i = 0;
	j = 0;
	k = 0;
	nsfere = 0;
	nurti = 0;
	nbin = 0;
	diametro = 0.0;
	frimp = 0.0;
	tempo = 0.0;
	encin = 0.0;
	temperatura = 0.0;
	press = 0.0;
	auxilium = 0.0;
	intervallofrimp = 0.0;
	x = NULL;
	y = NULL;
	vx = NULL;
	vy = NULL;
	dativx = NULL;
	dativy = NULL;
	datitempicollisioni = NULL;
	matricetempi = NULL;
	
	for( i = 0; i < 2; i++ )
	{
		vmedia[i] = 0.0;
	}
	
	/*Titolo*/
	printf("\n\n__________SFERE RIGIDE IN 2 DIMENSIONI__________\n\n");
	
	/*Richiedo il numero di sfere*/
	printf("Numero sfere (usare 2, 8, 18, 32, 50, 72, 98, 128, 162, 200, ...): ");
	scanf("%d", &nsfere);
	
	/*Richiedo la frazione di impacchettamento*/
	printf("\n\nFrazione di impacchettamento: ");
	scanf("%lf", &frimp);
	
	/*Calcolo il diametro*/
	diametro = 2.0*sqrt(frimp/((double)(nsfere)*PI));
	printf("\n\nDiametro = %lf\n", diametro);
	
	/*Alloco memoria per posizioni e velocità*/
	x = (double *) malloc( nsfere*(sizeof(double)) );
	y = (double *) malloc( nsfere*(sizeof(double)) );
	vx = (double *) malloc( nsfere*(sizeof(double)) );
	vy = (double *) malloc( nsfere*(sizeof(double)) );
	
	/*Inizializzo le posizioni delle sfere*/
	for( i = 0; i < nsfere; i++ )
	{
		*(x + i) = 0.0;
		*(y + i) = 0.0;
		*(vx + i) = 0.0;
		*(vy + i) = 0.0;
	}
	
	/*Creo la disposizione bcc*/
	BCCdisp( x, y, nsfere, diametro );
	
	/*Controllo che le sfere non entrino una nell'altra a causa della frazione di impacchettamento troppo grande*/
	for( i = 0; i < nsfere -1; i++ )
	{
		for( j = i + 1; j < nsfere; j++ )
		{		
			if( distanza(x, y, i, j) <= diametro )
			{
				printf("\n\nAttenzione: la frazione di impacchettamento è troppo alta e le sfere %d e %d entrano una nell'altra\n\n", i, j);
				
				printf("\ndistanza = %lf\n", distanza(x, y, i, j));
				
				return 0;
			}
		}
	}

	/*Inizializzazione generatore numeri casuali*/
	rlxd_init(1, 1);

	/*Generazione casuale delle velocità*/
	ranlxd( vx, nsfere );
	ranlxd( vy, nsfere );

	/*I numeri sono estratti in [0, 1]: raddoppio e shifto di -1 per avere velocità in [-1, 1].*/
	for( i = 0; i < nsfere; i++ )
	{
		*(vx + i) = 2.0*(*(vx + i)) - 1.0;

		*(vy + i) = 2.0*(*(vy + i)) - 1.0;
	}
	
	/*Calcolo le componenti della velocità media*/
	for( i = 0; i < nsfere; i++ )
	{
		vmedia[0] = vmedia[0] + *(vx + i);
		vmedia[1] = vmedia[1] + *(vy + i);
	}
	
	vmedia[0] = vmedia[0]/(double)(nsfere);
	vmedia[1] = vmedia[1]/(double)(nsfere);
	
	/*Shifto le velocità per avere momento totale nullo*/
	for( i = 0; i < nsfere; i++ )
	{
		*(vx + i) = *(vx + i) - vmedia[0];
		*(vy + i) = *(vy + i) - vmedia[1];
	}
	
	/*Alloco memoria per la matrice dei tempi*/
	matricetempi = (double **) malloc(nsfere*sizeof(double *));
	
	for( i = 0; i < nsfere; i++ )
	{
		*(matricetempi + i) = (double *) malloc(nsfere*sizeof(double));
	}
	
	/*Inizializzo le entrate della matrice*/
	for( i = 0; i < nsfere; i++ )
	{
		for( j = 0; j < nsfere; j++ )
		{
			*(*(matricetempi + i) + j) = 0.0;
		}
	}
	
	/*Riempio metà matrice dei tempi con i tempi di collisione di tutte le sfere, l'altra metà è simmetrica, e non sarà mai letta*/
	for( i = 0; i < nsfere; i++ )
	{
		for( j = 0; j <= i; j++ )
		{
			*(*(matricetempi + i) + j) = tempocollisione( x, y, vx, vy, nsfere, diametro, i, j );
		}
	}
	
	printf("\nTempo iniziale = %lf\n", tempo);
	
	printf("\n\nNumero urti per la termalizzazione: ");
	scanf("%d", &nurti);
	printf("\n\n");
	
	/*Si realizzano nurti urti*/
	for( i = 0; i < nurti; i++ )
	{	
		tempo = tempo + urto( x, y, vx, vy, matricetempi, nsfere, diametro, &auxilium, &auxilium );
	
		printf("Tempo = %lf\n", tempo);
	}
	
	/*Calcolo dell'energia cinetica totale*/
	for( i = 0; i < nsfere; i++ )
	{
		encin = encin + (*(vx + i))*(*(vx + i)) + (*(vy + i))*(*(vy + i));
	}
	
	encin = encin/2.0;
	
	/*Calcolo della temperatura dal teorema di equipartizione dell'energia*/
	temperatura = encin/(double)(nsfere);
	
	printf("\nEnergia cinetica totale = %lf\nTemperatura*kb = %lf\n", encin, temperatura );
	
	/*Acquisisco il numero di campionamenti delle velocità per l'istogramma. Il numero di dati sarà nsfere*nurti*/
	printf("\n\nNumero campionamenti per l'istogramma delle velocità: ");
	scanf("%d", &nurti);
	
	/*Acquisisco il numero di bin (deve essere pari)*/
	printf("\nNumero di bin (pari): ");
	scanf("%d", &nbin);
	printf("\n");
	
	/*Alloco memoria per i vettori che conterranno tutti i valori campionati delle velocità*/
	dativx = (double *) malloc(nsfere*nurti*sizeof(double));
	dativy = (double *) malloc(nsfere*nurti*sizeof(double));
	
	/*Si realizza un campionamento di velocità ogni nsfere urti*/
	for( i = 0; i < nurti; i++ )
	{
		for( j = 0; j < nsfere; j++ )
		{
			tempo = tempo + urto( x, y, vx, vy, matricetempi, nsfere, diametro, &auxilium, &auxilium );
		}
		
		printf("Tempo = %lf\n", tempo);
		
		for( j = 0; j < nsfere; j++ )
		{
			*(dativx + i*nsfere + j) = *(vx + j);
			*(dativy + i*nsfere + j) = *(vy + j);
		}
	}
	
	filefreqvx = fopen("fv_x.txt", "w");
	filefreqvy = fopen("fv_y.txt", "w");
    hist(dativx,nsfere,nbin,nurti,filefreqvx);
    hist(dativy,nsfere,nbin,nurti,filefreqvy);
		
	free( x );
	free( y );
	free( vx );
	free( vy );
	free( dativx );
	free( dativy );
	
	for( i = 0; i < nsfere; i++ )
	{
		free( *(matricetempi + i) );
	}
	
	free( matricetempi );
	
	fclose( filefreqvx );
	fclose( filefreqvy );

	return 0;
}
Exemplo n.º 12
0
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;
}
Exemplo n.º 13
0
/* 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;
}
Exemplo n.º 14
0
int main (int argc, char * argv[])
{
	if(argc == 1)
	{
		printf("\nNumero di parametri insufficiente!");
		printf("\nImpostare tipo di inzializzazione:\n");
		printf("\t1 -> a freddo;\n");
		printf("\t2 -> a caldo\n\n");
		exit(EXIT_FAILURE);
	}

	if(argc > 2)
	{
		STEPS = atoi(argv[2]);
		if(STEPS%DBIN != 0)
		{
			printf("\n# sweeps non è multiplo intero della lunghezza dei bins!\n\n");
			exit(EXIT_FAILURE);
		}
	}

	int Nbins = STEPS/DBIN;
	int i, step, Dt, bin, t;
	int choice = 0;
	double action, Sum, Sum1, Err, Err1;
	
	/* Stringhe per il nome del file di output */
	char *file_autocorr, *file_action;
	file_autocorr	= malloc(100*sizeof(char));
	file_action		= malloc(100*sizeof(char));

	/*
	 * Vettori utili:
	 * _ state -> contiene la posizione dell'oscillatore in ogni passo del 
	 * 		reticolo (N passi totali);
	 * 
	 * _ corrDtstep -> contiene i valori stimati a ciascun passo del Metropolis 
	 * 		di <x_i*x_{i+Dt}>;
	 * 
	 * _ Vtemp, Vtemp1 -> vettori ausiliari per costruire i correlatori di x e
	 *		di x^2 con il metodo del binning;
	 **/
	double *state, *corrDtstep, *Vtemp, *Vtemp1, *autocorr;

	/*
	 * Clusters jackknife utili:
	 * _ clusterDt -> N cluster jk che contengono i correlatori di x e gli
	 *		errori;
	 * 
	 * _ clusterSQDt -> cluster jk che contengono i correlatori di x^2 e gli
	 *		errori;
	 *
	 * _ DEtemp e EMtemp -> clusters jk ausiliari per il calcolo del gap di
	 *		energia e dell'elemento di matrice <0|x|1>
	 **/
	cluster *clusterDt, *clusterSQDt;
	cluster DEtemp, EMtemp;

	/* Eliminazione dei vecchi dati e creazione cartelle per i nuovi dati
	 * dell'autocorrelazione
	 */
	system("rm -r harmosc/autocorrelation");
	system("mkdir harmosc/autocorrelation");

	/* 
	 * File di output utili:
	 * _ out_action -> azione dell'oscillatore armonico in funzione dello sweep
	 * 		del Metropolis;
	 * 
	 * _ out_corr -> correlatori <x_l x_k> ed errori;
	 * 
	 * _ out_deltaE -> valori di deltaE (mediato sugli Nbins bin) in funzione di
	 * 		Dt (variabile della correlazione);
	 * _ out_deltaE_errors -> errori sul calcolo di DeltaE;
	 * 
	 * _ out_EM -> valore elemento di matrice di <0|x|1>;
	 * _ out_EM_errors -> errori sul calcolo di <0|x|1>;
	 *
	 * _ out_x2gs -> risultati ed errori di <x^2> sullo stato
	 *		fondamentale;
	 * 
	 * _ out_corrsq -> correlatori <x^2_l x^2_k> ed errori;
	 * 
	 * _ out_autocorr -> files labellati dal valore di Dt in cui viene salvata
	 * 		la funzione di autocorrelazione per <x_l x_{l+Dt}>
	 */
	FILE *out_action, *out_corr, *out_deltaE, *out_EM, *out_deltaE_errors,\
		*out_EM_errors, *out_x2gs, *out_corrsq;
	FILE *out_autocorr[DMAX+1];
	out_corr	= fopen("harmosc/corr_results.dat","w");
	out_deltaE	= fopen("harmosc/deltaE_results.dat","a");
	out_EM		= fopen("harmosc/matrixelement_results.dat","a");
	out_deltaE_errors	= fopen("harmosc/deltaE_errors.dat","a");
	out_EM_errors		= fopen("harmosc/matrixelement_errors.dat","a");
	out_x2gs	= fopen("harmosc/Egs_results.dat", "a");
	out_corrsq	= fopen("harmosc/corrSQ_results.dat", "a");
	for(i=0; i<DMAX+1; i++)
	{
		sprintf(file_autocorr, "harmosc/autocorrelation/autocorr_%d", i);
		out_autocorr[i] = fopen(file_autocorr, "w");
	}

	/* Allocazione vettori e cluster jk utili */
	state 		= malloc(N*sizeof(double));
	corrDtstep	= malloc((N*STEPS)*sizeof(double));
	Vtemp		= malloc(N*sizeof(double));
	Vtemp1		= malloc(N*sizeof(double));
	autocorr	= malloc(N*sizeof(double));
	clusterDt	= malloc(N*sizeof(cluster));
	clusterSQDt	= malloc(N*sizeof(cluster));

	/* Inizializzazione strutture cluster jackknife */
	for(Dt=0; Dt<N; Dt++)
	{
		cluster_init(clusterDt+Dt,Nbins);
		cluster_init(clusterSQDt+Dt,Nbins);
	}
	cluster_init(&DEtemp,Nbins);
	cluster_init(&EMtemp,Nbins);

	srand(time(NULL));
	rlxd_init(1,rand());

	/* Scelta di inizializzazione "a freddo" o "a caldo" dello stato iniziale */
	choice = atoi(argv[1]);
	switch(choice)
	{
		case 1:
			cold_init(state,N);
			sprintf(file_action, "harmosc/action_coldinit.dat");
			break;

		case 2:
			hot_init(state,N);
			sprintf(file_action, "harmosc/action_hotinit.dat");
			break;
	}
	out_action	= fopen(file_action,"w");

	cold_init(Vtemp,N);

	fprintf(out_action,\
		"#\n# Azione euclidea ad ogni sweep dell'algoritmo Metropolis\n");
	fprintf(out_action,"# Le colonne sono:\n");
	fprintf(out_action,"# Sweep\t azione\n#\n");


	/* Valuto l'azione del sistema nella configurazione iniziale
	 * (dipenderà dal tipo di inizializzazione di state scelta)
	 */
	action = HOeAction(state,N);
	fprintf(out_action,"%d\t%e\n", -1, action);

	/* Finché non si è raggiunto il tempo di termalizzazione NTH faccio evolvere
	 * il sistema con il Metropolis
	 */
	for(step=0; step<NTH; step++)
	{
		action += HOmetropolis(state,N);
		fprintf(out_action,"%d\t%e\n", step, action);
	}

	bin = 0;
	/* Raggiunto il tempo di termalizzazione, si fa evolvere il sistema per un
	 * numero STEPS di sweeps del Metropolis utilizzando gli stati ottenuti
	 * per il calcolo della correlazione
	 */
	for(step=NTH; step<STEPS+NTH; step++)
	{
		action += HOmetropolis(state,N);
		fprintf(out_action,"%d\t%e\n", step, action);

		for(Dt=0; Dt<N; Dt++)
		{
			Sum = 0;
			Sum1 = 0;
			/* media sul vettore di reticolo (somme su i) di x_i*x_{i+K} e di
			 * x^2_i*x^2_{i+K}
			 */
			for(i=0; i<N; i++)
			{
				Sum  += state[i]*state[(i+Dt)%N];
				Sum1 += state[i]*state[(i+Dt)%N]*state[i]*state[(i+Dt)%N];
			}
			Vtemp[Dt]  += Sum/((double)N);
			Vtemp1[Dt] += Sum1/((double)N);
		}

		/* Salvataggio della media sul bin nell vettore del cluster jackknife */
		if((step-NTH+1)%DBIN == 0)
		{
			for(Dt=0; Dt<N; Dt++)
			{
				clusterDt[Dt].Vec[bin] = Vtemp[Dt]/(double)DBIN;
				Vtemp[Dt] = 0;
				clusterSQDt[Dt].Vec[bin] = Vtemp1[Dt]/(double)DBIN;
				Vtemp1[Dt] = 0;
			}
			bin++;
		}
	}

	Sum = 0; Err = 0;
	/* Calcolo e stampa di media e deviazione standard della media dei 
	 * correlatori.
	 */
	for(Dt=0; Dt<N; Dt++)
	{
		clusterJK(clusterDt+Dt);
		fprintf(out_corr,"%d\t%e\t%e\n", Dt, clusterDt[Dt].Mean, \
			sqrt(clusterDt[Dt].Sigma));
		clusterJK(clusterSQDt+Dt);		
		fprintf(out_corrsq, "%d\t%e\t%e\n", Dt, clusterSQDt[Dt].Mean, \
			sqrt(clusterSQDt[Dt].Sigma));
		
		/* Calcolo l'elemento di matrice di x^2 sul ground state */
		EMtemp = sqrt_jk(clusterSQDt+Dt);
		Sum		+= (EMtemp.Mean)/(EMtemp.Sigma);
		Err		+= 1.0/(EMtemp.Sigma);
	}
	fprintf(out_x2gs, "%e\t%e\n",Sum/Err, sqrt(Err/((double)Nbins)));
	fprintf(out_x2gs, "%e\n", Sum/Err);

	/* Calcolo del gap di energia e degli elementi di matrice con varianze.
	 * Si prendono in considerazione soltanto i correlatori per piccoli
	 * valodi di Dt: i valori centrali non hanno un andamento regolare
	 * (si veda dal plot dei correlatori)
	 */
	for(Dt=2; Dt<NCL; Dt++)
	{
		Sum = 0; Sum1 = 0;
		Err = 0; Err1 = 0;
		
		DEtemp = DeltaE(clusterDt+(Dt-1), clusterDt+Dt, clusterDt+(Dt+1));
		EMtemp = MatrixElementX(&DEtemp, clusterDt+Dt, Dt, N);
			
		/* Si effettua la media pesata di DeltaE per i valori di Dt
		 * presi in considerazione
		 */
		Sum		+= (DEtemp.Mean)/(DEtemp.Sigma);
		Sum1	+= (EMtemp.Mean)/(EMtemp.Sigma);

		Err		+= 1.0/(DEtemp.Sigma);
		Err1	+= 1.0/(EMtemp.Sigma);
	}

	fprintf(out_deltaE_errors,	"%d\t%e\n", STEPS, sqrt(Err/((double)Nbins)));
	fprintf(out_EM_errors,		"%d\t%e\n", STEPS, sqrt(Err1/((double)Nbins)));

	fprintf(out_deltaE,	"%e\n",Sum/Err);
	fprintf(out_EM,		"%e\n",Sum1/Err1);

	/*
	 * Calcolo e stampa delle autocorrelazioni per i correlatori delle x per i
	 * primi TMAX+1 valori di Dt
	 */
	for(t=0; t<TMAX+1; t++)
	{
		autocorrelation(corrDtstep, t, autocorr, N, STEPS);
		for(Dt=0; Dt<DMAX+1; Dt++)
		{
			fprintf(out_autocorr[Dt], "%d\t%e\n", t, autocorr[Dt]);
		}
	}

	for(i=0; i<DMAX+1; i++)
		fclose(out_autocorr[i]);
	for(i=0; i<N; i++)
	{
		free((clusterDt + i)->Vec);
		free((clusterSQDt + i)->Vec);
	}
	free(clusterDt);
	free(clusterSQDt);
	fclose(out_corr);
	fclose(out_action);
	fclose(out_deltaE);
	fclose(out_EM);
	fclose(out_x2gs);
	fclose(out_corrsq);
	fclose(out_deltaE_errors);
	fclose(out_EM_errors);

	exit(EXIT_SUCCESS);
}
Exemplo n.º 15
0
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);
}
Exemplo n.º 16
0
void rlxdinit_(int *lux,int *seed) {
    int lux1,seed1;
    lux1=*lux;
    seed1=*seed;
    rlxd_init(lux1,seed1);
}