From 78d56f043d77961c3967e56dc65ea040eb38a55f Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 17 Nov 2009 17:04:53 +0100 Subject: Add memoization to scattering factor calculation --- src/sfac.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'src/sfac.c') diff --git a/src/sfac.c b/src/sfac.c index 342c9615..45514992 100644 --- a/src/sfac.c +++ b/src/sfac.c @@ -20,6 +20,9 @@ #include "sfac.h" +#define N_MEMO 1024 + + /* Look up f1 and f2 for this atom at this energy (in J/photon) */ static double complex get_f1f2(const char *n, double en) { @@ -28,6 +31,17 @@ static double complex get_f1f2(const char *n, double en) char line[1024]; char *rval; double last_E, last_f1, last_f2; + static char *memo_n[N_MEMO]; + static double memo_en[N_MEMO]; + static double complex memo_res[N_MEMO]; + static int n_memo = 0; + int i; + + for ( i=0; i