From 1e8779cbc8d9497b6622f93fd52dd3b918967a6e Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Wed, 18 Oct 2017 16:49:12 -0400 Subject: made the wolff hybrid more efficient --- lib/wolff_tools.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'lib/wolff_tools.c') diff --git a/lib/wolff_tools.c b/lib/wolff_tools.c index 5e88a57..6b1e006 100644 --- a/lib/wolff_tools.c +++ b/lib/wolff_tools.c @@ -93,6 +93,9 @@ cluster_t *flip_cluster(const graph_t *g, const double *ps, bool *x, bool stop_o if (x[v] == x0 && !(c->hit_ghost && stop_on_ghost)) { // if the vertex hasn't already been flipped x[v] = !x[v]; // flip the vertex + if (stop_on_ghost) { + stack_push(&(c->spins), v); + } for (uint32_t i = 0; i < nn; i++) { bool is_ext; @@ -195,19 +198,17 @@ uint32_t wolff_step(double T, double H, ising_state_t *s, sim_t sim, gsl_rng *r, } break; case WOLFF_GHOST: { - bool *spins_bak; - spins_bak = (bool *)malloc(s->g->nv * sizeof(bool)); - memcpy(spins_bak, s->spins, s->g->nv * sizeof(bool)); - cluster_t *c = flip_cluster(s->g, ps, s->spins, true, r); if (c->hit_ghost) { - memcpy(s->spins, spins_bak, s->g->nv * sizeof(bool)); + while (c->spins != NULL) { + uint32_t v = stack_pop(&(c->spins)); + s->spins[v] = !s->spins[v]; + } } else { s->M += - sign(H) * 2 * c->dHb; s->H += 2 * (c->dJb + sign (H) * H * c->dHb); } - free(spins_bak); n_flips = c->nv; -- cgit v1.2.3-70-g09d2