From b5998a15cdbab21f03a65d9885dbde39615dc087 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Fri, 20 Jul 2018 23:21:39 -0400 Subject: cos and sin calls for computing fourier term now precomputed --- lib/cluster.h | 35 ++++++----------------------------- lib/state.h | 11 +++++++++++ 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/lib/cluster.h b/lib/cluster.h index 4b3c2f6..d90dc64 100644 --- a/lib/cluster.h +++ b/lib/cluster.h @@ -29,30 +29,6 @@ #include "dihinf.h" #include "yule_walker.h" -template -void init(T*); - -template -T scalar_multiple(v_t a, T b); - -template -X_t act(R_t a, X_t b); - -template -X_t act_inverse(R_t a, X_t b); - -template -T copy(T a); - -template -void free_spin(T a); - -template -T add(T, T); - -template -T subtract(T, T); - template void flip_cluster(state_t *state, v_t v0, R_t r, gsl_rng *rand) { v_t nv = 0; @@ -114,12 +90,13 @@ void flip_cluster(state_t *state, v_t v0, R_t r, gsl_rng *rand) { state->E += dE; for (D_t i = 0; i < state->D; i++) { - double x = (double)((non_ghost / (v_t)pow(state->L, state->D - i - 1)) % state->L) / (double)state->L; - add(&(state->ReF[i]), -cos(2 * M_PI * x), rs_old); - add(&(state->ReF[i]), cos(2 * M_PI * x), rs_new); + L_t x = (non_ghost / (v_t)pow(state->L, state->D - i - 1)) % state->L; + + add(&(state->ReF[i]), -state->precomputed_cos[i], rs_old); + add(&(state->ReF[i]), state->precomputed_cos[i], rs_new); - add(&(state->ImF[i]), -sin(2 * M_PI * x), rs_old); - add(&(state->ImF[i]), sin(2 * M_PI * x), rs_new); + add(&(state->ImF[i]), -state->precomputed_sin[i], rs_old); + add(&(state->ImF[i]), state->precomputed_sin[i], rs_new); } free_spin (rs_old); diff --git a/lib/state.h b/lib/state.h index b40b85c..76d3e5a 100644 --- a/lib/state.h +++ b/lib/state.h @@ -23,6 +23,9 @@ class state_t { v_t last_cluster_size; typename X_t::F_t *ReF; typename X_t::F_t *ImF; + // updating fourier terms F requires many cos and sin calls, faster to do it beforehand. + double *precomputed_cos; + double *precomputed_sin; std::function J; std::function H; @@ -47,6 +50,12 @@ class state_t { ReF[i] = scalar_multiple(0, spins[0]); ImF[i] = scalar_multiple(0, spins[0]); } + precomputed_cos = (double *)malloc(L * sizeof(double)); + precomputed_sin = (double *)malloc(L * sizeof(double)); + for (L_t i = 0; i < L; i++) { + precomputed_cos[i] = cos(2 * M_PI * (double)i / (double)L); + precomputed_sin[i] = sin(2 * M_PI * (double)i / (double)L); + } } ~state_t() { @@ -63,6 +72,8 @@ class state_t { } free(ReF); free(ImF); + free(precomputed_sin); + free(precomputed_cos); } }; -- cgit v1.2.3-70-g09d2