Esempio n. 1
0
u8 init_simulation(command* cmd, simulation* sim, timer* t, ocrGuid_t** list)
{
  sim->step = 0;
  sim->steps = cmd->steps;
  sim->period = cmd->period;
  sim->dt = cmd->dt;
  sim->e_potential = 0.0;
  sim->e_kinetic = 0.0;

  u8 insane = 0;
  if(cmd->doeam)
    insane = init_eam(cmd->pot_dir, cmd->pot_name, cmd->pot_type, &sim->pot, sim->dt);
  else
    init_lj(&sim->pot, sim->dt);
  if(insane) return insane;

  real_t lattice_const = cmd->lat;
  if(cmd->lat < 0.0)
    lattice_const = sim->pot.lat;
  insane = sanity_checks(cmd, sim->pot.cutoff, lattice_const, sim->pot.lattice_type);
  if(insane) return insane;

  ocrGuid_t box_tmp;
  box** box_ptr = init_lattice(sim, cmd, lattice_const, list, &box_tmp);

  profile_start(redistribute_timer,t);
  redistribute_atoms(sim, box_ptr, sim->bxs.boxes_num);
  profile_stop(redistribute_timer,t);

  ocrDbDestroy(box_tmp);

  return 0;
}
Esempio n. 2
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;
}
Esempio n. 3
0
void static_load_arrays()
{
init_lattice();
load_vs();
load_omega(0.50,0);
load_omega(0.45,1);
load_omega(0.40,2);
load_omega(0.35,3);
load_omega(0.30,4);
load_omega(0.25,5);
load_omega(0.20,6);
load_omega(0.15,7);
}
Esempio n. 4
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;
}
Esempio n. 5
0
void Decoder::decode(Instance * inst) {
  init_lattice(inst);
  viterbi_decode(inst);
  get_result(inst);
  free_lattice();
}
Esempio n. 6
0
int main(int argc, char ** argv){
  int *lattice;
  int neigh[4];
  int n_side;
  int i_flip=0;
  int i,j;
  double r;
  double delta_E;
  double T = atof(argv[2]);
  double beta = 1.0/T;
  double E;
  double M;
  double alpha;
  double h;
  int n_steps;

  double average_m = 0.0;
  double average_E = 0.0;
  double average_E2 = 0.0;

  n_side = atoi(argv[1]);
  lattice = init_lattice(n_side);
  E = compute_energy(lattice, n_side);
  M = compute_magnetiza(lattice, n_side);
  /*printf("%f %f\n", E, M);*/
  n_steps = n_side * n_side * 10;
  
  for(i=0;i<n_steps;i++){
    i_flip = random_between(0,n_side*n_side-1);
    get_neighbors(lattice, n_side, i_flip, neigh);
    
    h = 0.0;
    for(j=0;j<4;j++){
      h += lattice[neigh[j]];
    }
    delta_E = 2.0 * h * lattice[i_flip];

    r = MIN(1.0, exp(-beta * delta_E));
    alpha = drand48();
    if(alpha < r){
      lattice[i_flip] = -lattice[i_flip];
      E = E + delta_E;
    }    
    M = compute_magnetiza(lattice, n_side);
    /*printf("%f %f\n", E, M);*/

    if(i>30000){
      average_m += fabs(M)/(n_side*n_side);
      average_E += E;
      average_E2 += E*E;
    }
  }
  
  average_m = average_m/(n_steps-30000);
  average_E = average_E/(n_steps-30000);
  average_E2 = average_E2/(n_steps-30000);
  
  double varE = average_E2 - average_E*average_E;
  
  printf("%f %f %f\n", T, average_m, varE);
  
  return 0;
}