summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/cluster.h35
-rw-r--r--lib/state.h11
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 <class T>
-void init(T*);
-
-template <class T>
-T scalar_multiple(v_t a, T b);
-
-template <class R_t, class X_t>
-X_t act(R_t a, X_t b);
-
-template <class R_t, class X_t>
-X_t act_inverse(R_t a, X_t b);
-
-template <class T>
-T copy(T a);
-
-template <class T>
-void free_spin(T a);
-
-template <class T>
-T add(T, T);
-
-template <class T>
-T subtract(T, T);
-
template <class R_t, class X_t>
void flip_cluster(state_t <R_t, X_t> *state, v_t v0, R_t r, gsl_rng *rand) {
v_t nv = 0;
@@ -114,12 +90,13 @@ void flip_cluster(state_t <R_t, X_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 <double(X_t, X_t)> J;
std::function <double(X_t)> 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);
}
};