Commit 95e35ec7 authored by Izzard, Robert Dr (Physics)'s avatar Izzard, Robert Dr (Physics)

Merge branch 'master' of gitlab.eps.surrey.ac.uk:ri0005/librinterpolate

parents aa8bf403 a4142bb6
......@@ -11,7 +11,7 @@ LDFLAGS ?=
C_SRC := $(wildcard *.c)
OBJECTS := $(C_SRC:.c=.o)
#OBJECTS := rinterpolate.o rinterpolate-debug.o
CFLAGS := -fPIC -O2 -march=native -mtune=native -Wall -Wstrict-prototypes -ffast-math -D__RINTERPOLATE__ $(COPTFLAGS)
CFLAGS := -fPIC -O2 -march=native -mtune=native -Wall -Wstrict-prototypes -ffast-math -D__RINTERPOLATE__ -D__RINTERPOLATE_BUILD_BUILD_FLAGS__ $(COPTFLAGS)
ifeq ($(PREFIX),)
PREFIX := /usr/local
endif
......
#include "rinterpolate.h"
#include "rinterpolate_internal.h"
/*
* librinterpolate
*
......@@ -162,7 +162,7 @@ struct rinterpolate_data_t * rinterpolate(
#if defined RINTERPOLATE_DEBUG && defined RINTERPOLATE_SHOW_TABLE
register rinterpolate_counter_t i=0;
#endif
Iprint("DEBUG RINTERPOLATE datatable=%p n=%d d=%d l=%d x=%p r=%p cache_length=%d\n",
Rinterpolate_print("DEBUG RINTERPOLATE datatable=%p n=%d d=%d l=%d x=%p r=%p cache_length=%d\n",
datatable,
n,d,l,x,r,cache_length);
......@@ -197,7 +197,7 @@ struct rinterpolate_data_t * rinterpolate(
datatable);
}
Iprint("Table ID %d\n",table_id);
Rinterpolate_print("Table ID %d\n",table_id);
if(table_id == -1)
{
......@@ -210,7 +210,7 @@ struct rinterpolate_data_t * rinterpolate(
d,
l,
cache_length);
Iprint("New table ID %d\n",table_id);
Rinterpolate_print("New table ID %d\n",table_id);
}
/*
......@@ -236,13 +236,13 @@ struct rinterpolate_data_t * rinterpolate(
{
for(i=0;i<l;i++)
{
Iprint("L%d ",i);
Rinterpolate_print("L%d ",i);
rinterpolate_counter_t j;
for(j=0;j<table->line_length;j++)
{
Iprint("%g ",*(datatable+i*table->line_length+j));
Rinterpolate_print("%g ",*(datatable+i*table->line_length+j));
}
Iprint("\n");
Rinterpolate_print("\n");
FLUSH;
}
}
......@@ -271,20 +271,20 @@ struct rinterpolate_data_t * rinterpolate(
if(rinterpolate_debug==TRUE)
{
rinterpolate_counter_t j;
Iprint("Parameter (x) values: ");
Rinterpolate_print("Parameter (x) values: ");
for(j=0;j<table->n;j++)
{
Iprint("% 3.3e ",x[j]);
Rinterpolate_print("% 3.3e ",x[j]);
}
Iprint("\n");
Rinterpolate_print("\n");
Iprint("Interpolation (f) factors: ");
Rinterpolate_print("Interpolation (f) factors: ");
for(j=0;j<table->n;j++)
{
Iprint("% 3.3e ",table->hypertable->f[j]);
Rinterpolate_print("% 3.3e ",table->hypertable->f[j]);
}
Iprint("\n");
Iprint("Interpolation hypertable:\n");
Rinterpolate_print("\n");
Rinterpolate_print("Interpolation hypertable:\n");
}
#endif
......@@ -301,17 +301,17 @@ struct rinterpolate_data_t * rinterpolate(
#ifdef RINTERPOLATE_DEBUG
{
rinterpolate_counter_t j;
Iprint("Result\n");
Rinterpolate_print("Result\n");
for(j=0;j<table->n;j++)
{
Iprint("% 3.3e ",*(table->hypertable->data+j));
Rinterpolate_print("% 3.3e ",*(table->hypertable->data+j));
}
Iprint(" | ");
Rinterpolate_print(" | ");
for(j=n;j<table->line_length;j++)
{
Iprint("% 3.3e ",*(table->hypertable->data+j));
Rinterpolate_print("% 3.3e ",*(table->hypertable->data+j));
}
Iprint("\n");FLUSH;
Rinterpolate_print("\n");FLUSH;
}
#endif
......
......@@ -31,6 +31,10 @@ typedef int rinterpolate_signed_counter_t;
typedef double rinterpolate_float_t;
typedef unsigned int rinterpolate_Boolean_t;
/* debugging */
#define Rinterpolate_print(...) /* do nothing */
//#define Rinterpolate_print(...) fprintf(stdout,__VA_ARGS__);
/* error codes */
#define RINTERPOLATE_NO_ERROR 0
#define RINTERPOLATE_CALLOC_FAILED 1
......@@ -168,4 +172,5 @@ struct rinterpolate_data_t {
#include "rinterpolate_prototypes.h"
#endif // RINTERPOLATE_H
#include "rinterpolate.h"
#include "rinterpolate_internal.h"
rinterpolate_counter_t rinterpolate_add_new_table(
struct rinterpolate_data_t * RESTRICT rinterpolate_data,
......
#include "rinterpolate.h"
#include "rinterpolate_internal.h"
#ifdef RINTERPOLATE_CACHE
......@@ -8,7 +9,7 @@ void rinterpolate_alloc_cacheline(struct rinterpolate_table_t * table)
table->cache_spin_line = -1;
#ifdef RINTERPOLATE_DEBUG
Iprint("Allocated new cache array for table_id=%d\n",
Rinterpolate_print("Allocated new cache array for table_id=%d\n",
table->table_number);
#endif
/*
......
#include "rinterpolate.h"
#include "rinterpolate_internal.h"
/*
* Allocate memory for rinterpolate: to be called ONCE per process only.
*/
......
#include "rinterpolate.h"
#include "rinterpolate_internal.h"
#ifdef RINTERPOLATE_USE_REALLOC
#include <malloc.h>
#endif
......@@ -9,7 +10,7 @@ void rinterpolate_alloc_hypertable(struct rinterpolate_table_t * RESTRICT table)
table->hypertable = RINTERPOLATE_MALLOC(sizeof(struct rinterpolate_hypertable_t));
#ifdef RINTERPOLATE_DEBUG
Iprint("Interpolate: memory allocation\n");FLUSH;
Rinterpolate_print("Interpolate: memory allocation\n");FLUSH;
#endif
table->hypertable->table = table;
table->hypertable->data = RINTERPOLATE_MALLOC(table->hypertable_length*table->line_length_sizeof);
......@@ -17,7 +18,7 @@ void rinterpolate_alloc_hypertable(struct rinterpolate_table_t * RESTRICT table)
table->hypertable->sum = RINTERPOLATE_CALLOC(1,table->sum_sizeof);
#ifdef RINTERPOLATE_DEBUG
Iprint("MALLOC data at %p size %ld, f at %p size %ld, sum at %p size %ld\n",
Rinterpolate_print("MALLOC data at %p size %ld, f at %p size %ld, sum at %p size %ld\n",
table->hypertable->data,table->hypertable_length*table->line_length_sizeof,
table->hypertable->f,table->n_float_sizeof,
table->hypertable->sum,table->sum_sizeof);
......@@ -34,7 +35,7 @@ void rinterpolate_alloc_hypertable(struct rinterpolate_table_t * RESTRICT table)
#endif//RINTERPOLATE_ALLOC_CHECKS
#ifdef RINTERPOLATE_DEBUG
Iprint("table->hypertable->data alloc 2 * %d * %ld\n",table->hypertable_length,table->line_length_sizeof);
Rinterpolate_print("table->hypertable->data alloc 2 * %d * %ld\n",table->hypertable_length,table->line_length_sizeof);
#endif
#ifdef RINTERPOLATE_USE_REALLOC
......
#include "rinterpolate.h"
#include "rinterpolate_internal.h"
void rinterpolate_alloc_varcount(struct rinterpolate_table_t * RESTRICT table)
{
......@@ -18,7 +19,7 @@ void rinterpolate_alloc_varcount(struct rinterpolate_table_t * RESTRICT table)
for(j=0; j<table->n; j++)
{
#ifdef RINTERPOLATE_DEBUG
Iprint("Interpolate debug: varcount[%d]=%d, b=%d, steps[%d]=%d\n",
Rinterpolate_print("Interpolate debug: varcount[%d]=%d, b=%d, steps[%d]=%d\n",
j,table->varcount[j],b,j,table->steps[j]);
FLUSH;
#endif
......
#ifdef __RINTERPOLATE_BUILD_BUILD_FLAGS__
#include "rinterpolate.h"
#include "rinterpolate_internal.h"
#include <stdarg.h>
#include <string.h>
/*
* Macro to convert a macro to a string
*/
#ifndef Stringify
#define Stringify(item) "" #item
#endif
/*
* Macro to expand a macro and then convert to a string
*/
#ifndef Stringify_macro
#define Stringify_macro(item) (Stringify(item))
#endif
#ifndef Macrotest
/*
* Macro to test a macro
*/
......@@ -19,6 +28,7 @@
"" #macro, \
(strcmp("" #macro, \
Stringify(macro)) ? "on" : "off" ));
#endif
void rinterpolate_build_flags(struct rinterpolate_data_t * RESTRICT rinterpolate_data)
{
......@@ -35,3 +45,4 @@ void rinterpolate_build_flags(struct rinterpolate_data_t * RESTRICT rinterpolate
}
#endif
#include "rinterpolate.h"
#ifdef RINTERPOLATE_CACHE
#include "rinterpolate_internal.h"
rinterpolate_Boolean_t rinterpolate_check_cache(
struct rinterpolate_table_t * RESTRICT table,
const rinterpolate_float_t * RESTRICT x,
......@@ -41,19 +41,19 @@ rinterpolate_Boolean_t rinterpolate_check_cache(
#ifdef RINTERPOLATE_CACHE_USE_MEMCMP
#ifdef RINTERPOLATE_DEBUG
{
Iprint("check cache : cf %d\n x={ ",iline);
Rinterpolate_print("check cache : cf %d\n x={ ",iline);
int m;
for(m=0;m<table->n;m++)
{
Iprint("%g%s",*(x+m),m==(table->n-1) ? " }\n":",");
Rinterpolate_print("%g%s",*(x+m),m==(table->n-1) ? " }\n":",");
}
rinterpolate_float_t * cl = RINTERPOLATE_CACHE_PARAM(iline);
Iprint(" c={ ");
Rinterpolate_print(" c={ ");
for(m=0;m<table->n;m++)
{
Iprint("%g%s",*(cl+m),m==(table->n-1) ? " }\n":",");
Rinterpolate_print("%g%s",*(cl+m),m==(table->n-1) ? " }\n":",");
}
Iprint("memcmp = %d\n",
Rinterpolate_print("memcmp = %d\n",
memcmp(RINTERPOLATE_CACHE_PARAM(iline),x,table->n_float_sizeof));
}
#endif//RINTERPOLATE_DEBUG
......@@ -62,7 +62,7 @@ rinterpolate_Boolean_t rinterpolate_check_cache(
rinterpolate_counter_t m;
rinterpolate_float_t * cacheline = RINTERPOLATE_CACHE_PARAM(iline);
match = TRUE;
Iprint("start of for loop\n");
Rinterpolate_print("start of for loop\n");
for(m=0; m<table->n; m++)
{
if(!FEQUAL(x[m],cacheline[m]))
......@@ -71,9 +71,12 @@ rinterpolate_Boolean_t rinterpolate_check_cache(
break;
}
}
Rinterpolate_print("end of for loop\n");
#endif // RINTERPOLATE_CACHE_USE_MEMCMP
Iprint("Post Match = %d\n",match);
Rinterpolate_print("Post Match = %d\n",match);
if(match==TRUE)
{
......@@ -84,7 +87,7 @@ rinterpolate_Boolean_t rinterpolate_check_cache(
*/
memcpy(r,RINTERPOLATE_CACHE_RESULT(iline),table->d_float_sizeof);
Iprint("cache match at line iline=%d (iloop=%d loop start %d)\n",iline,iloop,table->cache_match_line);
Rinterpolate_print("cache match at line iline=%d (iloop=%d loop start %d)\n",iline,iloop,table->cache_match_line);
/*
* Save the position of the match for
......@@ -100,7 +103,7 @@ rinterpolate_Boolean_t rinterpolate_check_cache(
}
cache_match:
Iprint("return match = %d\n",match);
Rinterpolate_print("return match = %d\n",match);
return match;
}
#endif//RINTERPOLATE_CACHE
#include "rinterpolate.h"
#include "rinterpolate_internal.h"
void rinterpolate_construct_hypercube(struct rinterpolate_table_t * RESTRICT table)
{
......@@ -12,9 +13,9 @@ void rinterpolate_construct_hypercube(struct rinterpolate_table_t * RESTRICT tab
rinterpolate_counter_t i;
for(i=0;i<table->hypertable_length;i++)
{
Iprint("SUM %d was %d now ",i,hypertable->sum[i]);
Rinterpolate_print("SUM %d was %d now ",i,hypertable->sum[i]);
hypertable->sum[i] *= table->line_length;
Iprint("%d (lnl = %d)\n",hypertable->sum[i],table->line_length);
Rinterpolate_print("%d (lnl = %d)\n",hypertable->sum[i],table->line_length);
}
register rinterpolate_counter_t k = 0;
......@@ -23,7 +24,7 @@ void rinterpolate_construct_hypercube(struct rinterpolate_table_t * RESTRICT tab
#ifdef RINTERPOLATE_DEBUG
if(rinterpolate_debug==TRUE)
{
Iprint("memcpy k=%d i=%d : from %p to %p ( = %p + %d )\n",
Rinterpolate_print("memcpy k=%d i=%d : from %p to %p ( = %p + %d )\n",
k,
i,
hypertable->data + k,
......@@ -42,18 +43,18 @@ void rinterpolate_construct_hypercube(struct rinterpolate_table_t * RESTRICT tab
#ifdef RINTERPOLATE_DEBUG
{
Iprint("Line %d : ",i);FLUSH;
Rinterpolate_print("Line %d : ",i);FLUSH;
rinterpolate_counter_t j;
for(j=0;j<table->n;j++)
{
Iprint("% 3.3e ",*(hypertable->data+i*table->line_length+j));FLUSH;
Rinterpolate_print("% 3.3e ",*(hypertable->data+i*table->line_length+j));FLUSH;
}
Iprint(" | ");FLUSH;
Rinterpolate_print(" | ");FLUSH;
for(j=table->n;j<table->line_length;j++)
{
Iprint("% 3.3e ",*(hypertable->data+i*table->line_length+j));FLUSH;
Rinterpolate_print("% 3.3e ",*(hypertable->data+i*table->line_length+j));FLUSH;
}
Iprint(" %d/%d\n",i,table->hypertable_length-1);FLUSH;
Rinterpolate_print(" %d/%d\n",i,table->hypertable_length-1);FLUSH;
}
#endif
......@@ -61,14 +62,14 @@ void rinterpolate_construct_hypercube(struct rinterpolate_table_t * RESTRICT tab
#ifdef RINTERPOLATE_DEBUG
{
Iprint("done hypertable\n");
Iprint("Interpolation (f) factors: ");
Rinterpolate_print("done hypertable\n");
Rinterpolate_print("Interpolation (f) factors: ");
rinterpolate_counter_t j;
for(j=0;j<table->n;j++)
{
Iprint("% 3.3e ",hypertable->f[j]);
Rinterpolate_print("% 3.3e ",hypertable->f[j]);
}
Iprint("\n");
Rinterpolate_print("\n");
}
#endif
}
#include "rinterpolate.h"
#include <stdarg.h>
#include "rinterpolate_internal.h"
void rinterpolate_error(rinterpolate_counter_t errnum,
char * RESTRICT format,
......
#include "rinterpolate.h"
#include "rinterpolate_internal.h"
/*
* rinterpolate_free_data
*
......
#include "rinterpolate.h"
#include "rinterpolate_internal.h"
/*
* Given a hypertable struct, free everything in it.
*/
......
#include "rinterpolate.h"
#include "rinterpolate_internal.h"
/*
* Attempt to match a table to those in the rinterpolate
* data structure.
......@@ -14,8 +14,8 @@ rinterpolate_signed_counter_t rinterpolate_id_table(
rinterpolate_Boolean_t found = FALSE;
Iprint("Look for table in existing table ids\n");
Iprint("currently have %d tables\n",rinterpolate_data->number_of_interpolation_tables);
Rinterpolate_print("Look for table in existing table ids\n");
Rinterpolate_print("currently have %d tables\n",rinterpolate_data->number_of_interpolation_tables);
rinterpolate_counter_t table_num = 0;
while(table_num < rinterpolate_data->number_of_interpolation_tables)
......@@ -34,12 +34,12 @@ rinterpolate_signed_counter_t rinterpolate_id_table(
if(found==FALSE)
{
/* if not found, allocate */
Iprint("Not found : realloc\n");
Rinterpolate_print("Not found : realloc\n");
table_num = -1;
}
else
{
Iprint("Found at %d\n",table_num);
Rinterpolate_print("Found at %d\n",table_num);
}
return table_num;
......
#include "rinterpolate.h"
#include "rinterpolate_internal.h"
void rinterpolate_interpolate(
const struct rinterpolate_table_t * table,
......@@ -26,7 +27,7 @@ void rinterpolate_interpolate(
* Do the interpolation
*/
#ifdef RINTERPOLATE_DEBUG
Iprint("Interpolate n=%d f=%g\n",table->n,hypertable->f[n]);
Rinterpolate_print("Interpolate n=%d f=%g\n",table->n,hypertable->f[n]);
FLUSH;
#endif
#ifdef RINTERPOLATE_USE_POINTER_ARITHMETIC
......@@ -41,7 +42,7 @@ void rinterpolate_interpolate(
{
// u=0 v=1: unusual case but easy to calculate (no inner loop required)
#ifdef RINTERPOLATE_DEBUG
Iprint("u=0 v=1\n");
Rinterpolate_print("u=0 v=1\n");
#endif
rinterpolate_float_t *xxx;
rinterpolate_counter_t i;
......@@ -97,7 +98,7 @@ void rinterpolate_interpolate(
}
#ifdef RINTERPOLATE_DEBUG
Iprint("memcopy results\n");
Rinterpolate_print("memcopy results\n");
FLUSH;
#endif
......
#include "rinterpolate.h"
#include "rinterpolate_internal.h"
#ifdef RINTERPOLATE_PRESEARCH
void rinterpolate_make_presearch(struct rinterpolate_table_t * RESTRICT table)
......
#include "rinterpolate.h"
#include "rinterpolate_internal.h"
void rinterpolate_make_steps(struct rinterpolate_table_t * RESTRICT table)
{
......@@ -18,7 +19,7 @@ void rinterpolate_make_steps(struct rinterpolate_table_t * RESTRICT table)
/* loop, find where variables change */
#ifdef RINTERPOLATE_DEBUG
Iprint("Find where vars change (i.e. set steps_array/steps) \n");
Rinterpolate_print("Find where vars change (i.e. set steps_array/steps) \n");
#endif
rinterpolate_counter_t i,j;
......@@ -42,7 +43,7 @@ void rinterpolate_make_steps(struct rinterpolate_table_t * RESTRICT table)
for(i=1; i<table->l; i++)
{
/*
Iprint("Line %d, item %d/%d : cf %g to prev %g \n",
Rinterpolate_print("Line %d, item %d/%d : cf %g to prev %g \n",
i,
j,
table->n,
......@@ -59,7 +60,7 @@ void rinterpolate_make_steps(struct rinterpolate_table_t * RESTRICT table)
{
// change
table->steps[j] = i;
Iprint("SET STEPS for var %d to %d\n",j,table->steps[j]);
Rinterpolate_print("SET STEPS for var %d to %d\n",j,table->steps[j]);
i=table->l+1; // break i loop
}
}
......
......@@ -19,7 +19,6 @@ void rinterpolate_free_data(struct rinterpolate_data_t * RESTRICT rinterpolate_d
rinterpolate_counter_t rinterpolate_alloc_dataspace(struct rinterpolate_data_t ** RESTRICT r);
void rinterpolate_build_flags(struct rinterpolate_data_t * RESTRICT rinterpolate_data);
#ifdef __RINTERPOLATE__
/*
* Internal functions
*/
......@@ -83,7 +82,6 @@ rinterpolate_counter_t rinterpolate_add_new_table(
const rinterpolate_counter_t line_length,
const rinterpolate_counter_t cache_length);
#endif //__RINTERPOLATE__
void rinterpolate_free_hypertable(struct rinterpolate_hypertable_t * RESTRICT hypertable);
......
#include "rinterpolate.h"
#include "rinterpolate_internal.h"
#ifdef RINTERPOLATE_CACHE
......
#include "rinterpolate.h"
#include "rinterpolate_internal.h"
void rinterpolate_search_table(
struct rinterpolate_table_t * RESTRICT table,
......@@ -7,10 +8,10 @@ void rinterpolate_search_table(
{
register rinterpolate_counter_t j;
#ifdef RINTERPOLATE_DEBUG
Iprint("search table for span of { ");
Rinterpolate_print("search table for span of { ");
for(j=0;j<table->n;j++)
{
Iprint("x[%d]=%g%s",j,x[j],j!=(table->n-1)?", ":" }\n");
Rinterpolate_print("x[%d]=%g%s",j,x[j],j!=(table->n-1)?", ":" }\n");
}
FLUSH;
#endif
......@@ -58,7 +59,7 @@ void rinterpolate_search_table(
#ifdef RINTERPOLATE_DEBUG
if(rinterpolate_debug)
{
Iprint("Construct variable %d hypertable position\n",
Rinterpolate_print("Construct variable %d hypertable position\n",
j);
FLUSH;
......@@ -142,7 +143,7 @@ void rinterpolate_search_table(
}
#endif // BINARY_SEARCH
Iprint("Binary search : indices a=%d b=%d : vars %g < v=%g < %g\n",
Rinterpolate_print("Binary search : indices a=%d b=%d : vars %g < v=%g < %g\n",
a,
b,
*(tpre+a),
......@@ -219,10 +220,10 @@ void rinterpolate_search_table(
//sum[i] += tmp*a+(1-tmp)*b;
/* same thing without a temporary variable */
Iprint("DSUM(%d)=%d += (%d%%%d)==0? %d : %d -> ",
Rinterpolate_print("DSUM(%d)=%d += (%d%%%d)==0? %d : %d -> ",
m,sum[m],m,c,a,b);
sum[m] += ((m&c)==0 ? a : b);
Iprint("%d\n",sum[m]);
Rinterpolate_print("%d\n",sum[m]);
}
}
......
#include "rinterpolate.h"
#include "rinterpolate_internal.h"
#ifdef RINTERPOLATE_CACHE
void rinterpolate_store_cache(struct rinterpolate_table_t * RESTRICT table,
......
#ifdef __TEST_RINTERPOLATE__
#include "rinterpolate.h"
#include "rinterpolate_internal.h"
#ifdef _MSC_VER
#include <intrin.h>
#else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment