15template <
class integrator_type>
16void update_hmc(integrator_type &integrator,
int steps,
double traj_length) {
18 static int accepted = 0, trajectory = 1;
19 struct timeval start, end;
23 integrator.draw_gaussian_fields();
26 integrator.backup_fields();
28 gettimeofday(&start, NULL);
31 double start_action = integrator.action();
32 hila::out0 <<
"Begin HMC Trajectory " << trajectory <<
": Action " << start_action
36 for (
int step = 0; step < steps; step++) {
37 integrator.step(traj_length / steps);
41 double end_action = integrator.action();
42 double edS =
exp(-(end_action - start_action));
52 integrator.restore_backup();
55 hila::out0 <<
"End HMC: Action " << end_action <<
" " << end_action - start_action
56 <<
" exp(-dS) " << edS <<
". Acceptance " << accepted <<
"/" << trajectory
57 <<
" " << (double)accepted / (
double)trajectory <<
"\n";
59 gettimeofday(&end, NULL);
60 timing = (double)(end.tv_sec - start.tv_sec) + 1e-6 * (end.tv_usec - start.tv_usec);
62 hila::out0 <<
"HMC done in " << timing <<
" seconds \n";
Array< n, m, T > exp(Array< n, m, T > a)
Exponential.
double random()
Real valued uniform random number generator.
std::ostream out0
This writes output only from main process (node 0)
T broadcast(T &var, int rank=0)
Broadcast the value of var to all MPI ranks from rank (default=0).