summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/wolff.h1
-rw-r--r--lib/wolff_tools.c13
2 files changed, 8 insertions, 6 deletions
diff --git a/lib/wolff.h b/lib/wolff.h
index bd49bf0..84b3d22 100644
--- a/lib/wolff.h
+++ b/lib/wolff.h
@@ -36,6 +36,7 @@ typedef struct {
int32_t dJb;
int32_t dHb;
bool hit_ghost;
+ ll_t *spins;
} cluster_t;
typedef struct {
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;