Skip to content

Commit

Permalink
split bench.c into bench.c and fftw_bench_common.c so that we can re-…
Browse files Browse the repository at this point in the history
…use some of the code in the MPI test program

[empty commit message]
  • Loading branch information
stevengj committed Sep 13, 2006
1 parent 3b3b95a commit 792aaa1
Show file tree
Hide file tree
Showing 5 changed files with 227 additions and 212 deletions.
2 changes: 1 addition & 1 deletion tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ else
LIBFFTWTHREADS =
endif

bench_SOURCES = bench.c hook.c
bench_SOURCES = bench.c hook.c fftw_bench_common.c fftw_bench.h
bench_LDADD = $(LIBFFTWTHREADS) \
$(top_builddir)/libfftw3@[email protected] \
$(top_builddir)/libbench2/libbench2.a $(THREADLIBS)
Expand Down
216 changes: 6 additions & 210 deletions tests/bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,16 @@
/* NOTE to users: this is the FFTW self-test and benchmark program.
It is probably NOT a good place to learn FFTW usage, since it has a
lot of added complexity in order to exercise and test the full API,
etcetera. We suggest reading the manual. */
etcetera. We suggest reading the manual.
(Some of the self-test code is split off into fftw_bench_common.c and
hook.c.) */
/**************************************************************************/

#include "bench-user.h"
#include <math.h>
#include <stdio.h>
#include <fftw3.h>
#include <string.h>

#define CONCAT(prefix, name) prefix ## name
#if defined(BENCHFFT_SINGLE)
#define FFTW(x) CONCAT(fftwf_, x)
#elif defined(BENCHFFT_LDOUBLE)
#define FFTW(x) CONCAT(fftwl_, x)
#else
#define FFTW(x) CONCAT(fftw_, x)
#endif
#include "fftw_bench.h"

static const char *mkversion(void) { return FFTW(version); }
static const char *mkcc(void) { return FFTW(cc); }
Expand All @@ -31,94 +24,6 @@ BENCH_DOCF("cc", mkcc)
BENCH_DOCF("codelet-optim", mkcodelet_optim)
END_BENCH_DOC

FFTW(plan) the_plan = 0;

static const char *wisdat = "wis.dat";
unsigned the_flags = 0;
int paranoid = 0;
int usewisdom = 0;
int havewisdom = 0;
int nthreads = 1;
int amnesia = 0;

extern void install_hook(void); /* in hook.c */
extern void uninstall_hook(void); /* in hook.c */

void useropt(const char *arg)
{
int x;
double y;

if (!strcmp(arg, "patient")) the_flags |= FFTW_PATIENT;
else if (!strcmp(arg, "estimate")) the_flags |= FFTW_ESTIMATE;
else if (!strcmp(arg, "estimatepat")) the_flags |= FFTW_ESTIMATE_PATIENT;
else if (!strcmp(arg, "exhaustive")) the_flags |= FFTW_EXHAUSTIVE;
else if (!strcmp(arg, "unaligned")) the_flags |= FFTW_UNALIGNED;
else if (!strcmp(arg, "nosimd")) the_flags |= FFTW_NO_SIMD;
else if (!strcmp(arg, "noindirectop")) the_flags |= FFTW_NO_INDIRECT_OP;
else if (sscanf(arg, "flag=%d", &x) == 1) the_flags |= x;
else if (!strcmp(arg, "paranoid")) paranoid = 1;
else if (!strcmp(arg, "wisdom")) usewisdom = 1;
else if (!strcmp(arg, "amnesia")) amnesia = 1;
else if (sscanf(arg, "nthreads=%d", &x) == 1) nthreads = x;
else if (sscanf(arg, "timelimit=%lg", &y) == 1) {
FFTW(set_timelimit)(y);
}

else fprintf(stderr, "unknown user option: %s. Ignoring.\n", arg);
}

void rdwisdom(void)
{
FILE *f;
double tim;
int success = 0;

if (havewisdom) return;

#ifdef HAVE_THREADS
BENCH_ASSERT(FFTW(init_threads)());
FFTW(plan_with_nthreads)(nthreads);
#endif

if (!usewisdom) return;

timer_start(USER_TIMER);
if ((f = fopen(wisdat, "r"))) {
if (!FFTW(import_wisdom_from_file)(f))
fprintf(stderr, "bench: ERROR reading wisdom\n");
else
success = 1;
fclose(f);
}
tim = timer_stop(USER_TIMER);

if (success) {
if (verbose > 1) printf("READ WISDOM (%g seconds): ", tim);

if (verbose > 3)
FFTW(export_wisdom_to_file)(stdout);
if (verbose > 1)
printf("\n");
}
havewisdom = 1;
}

void wrwisdom(void)
{
FILE *f;
double tim;
if (!havewisdom) return;

timer_start(USER_TIMER);
if ((f = fopen(wisdat, "w"))) {
FFTW(export_wisdom_to_file)(f);
fclose(f);
}
tim = timer_stop(USER_TIMER);
if (verbose > 1) printf("write wisdom took %g seconds\n", tim);
}

static FFTW(iodim) *bench_tensor_to_fftw_iodim(bench_tensor *t)
{
FFTW(iodim) *d;
Expand Down Expand Up @@ -613,7 +518,7 @@ static FFTW(plan) mkplan_r2r(bench_problem *p, int flags)
return pln;
}

static FFTW(plan) mkplan(bench_problem *p, int flags)
FFTW(plan) mkplan(bench_problem *p, int flags)
{
switch (p->kind) {
case PROBLEM_COMPLEX: return mkplan_complex(p, flags);
Expand All @@ -623,112 +528,3 @@ static FFTW(plan) mkplan(bench_problem *p, int flags)
}
}

static unsigned preserve_input_flags(bench_problem *p)
{
/*
* fftw3 cannot preserve input for multidimensional c2r transforms.
* Enforce FFTW_DESTROY_INPUT
*/
if (p->kind == PROBLEM_REAL &&
p->sign > 0 &&
!p->in_place &&
p->sz->rnk > 1)
p->destroy_input = 1;

if (p->destroy_input)
return FFTW_DESTROY_INPUT;
else
return FFTW_PRESERVE_INPUT;
}

int can_do(bench_problem *p)
{
double tim;

if (verbose > 2 && p->pstring)
printf("Planning %s...\n", p->pstring);
rdwisdom();

timer_start(USER_TIMER);
the_plan = mkplan(p, preserve_input_flags(p) | the_flags | FFTW_ESTIMATE);
tim = timer_stop(USER_TIMER);
if (verbose > 2) printf("estimate-planner time: %g s\n", tim);

if (the_plan) {
FFTW(destroy_plan)(the_plan);
return 1;
}
return 0;
}

void setup(bench_problem *p)
{
double tim;

if (amnesia)
FFTW(forget_wisdom)();

/* Regression test: check that fftw_malloc exists and links
* properly */
FFTW(free(FFTW(malloc(42))));

rdwisdom();
install_hook();

#ifdef HAVE_THREADS
if (verbose > 1 && nthreads > 1) printf("NTHREADS = %d\n", nthreads);
#endif

timer_start(USER_TIMER);
the_plan = mkplan(p, preserve_input_flags(p) | the_flags);
tim = timer_stop(USER_TIMER);
if (verbose > 1) printf("planner time: %g s\n", tim);

BENCH_ASSERT(the_plan);

if (verbose > 1) {
double add, mul, nfma;
FFTW(print_plan)(the_plan);
printf("\n");
FFTW(flops)(the_plan, &add, &mul, &nfma);
printf("flops: %0.0f add, %0.0f mul, %0.0f fma\n", add, mul, nfma);
printf("estimated cost: %f\n", FFTW(estimate_cost)(the_plan));
}
}


void doit(int iter, bench_problem *p)
{
int i;
FFTW(plan) q = the_plan;

UNUSED(p);
for (i = 0; i < iter; ++i)
FFTW(execute)(q);
}

void done(bench_problem *p)
{
UNUSED(p);

FFTW(destroy_plan)(the_plan);
uninstall_hook();
}

void cleanup(void)
{
wrwisdom();
#ifdef HAVE_THREADS
FFTW(cleanup_threads)();
#else
FFTW(cleanup)();
#endif

# ifdef FFTW_DEBUG_MALLOC
{
/* undocumented memory checker */
FFTW_EXTERN void FFTW(malloc_print_minfo)(int v);
FFTW(malloc_print_minfo)(verbose);
}
# endif
}
16 changes: 16 additions & 0 deletions tests/fftw_bench.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* declarations of common subroutines, etc. for use with FFTW
self-test/benchmark program (see bench.c). */

#include "bench-user.h"
#include "fftw3.h"

#define CONCAT(prefix, name) prefix ## name
#if defined(BENCHFFT_SINGLE)
#define FFTW(x) CONCAT(fftwf_, x)
#elif defined(BENCHFFT_LDOUBLE)
#define FFTW(x) CONCAT(fftwl_, x)
#else
#define FFTW(x) CONCAT(fftw_, x)
#endif

extern FFTW(plan) mkplan(bench_problem *p, int flags);
Loading

0 comments on commit 792aaa1

Please sign in to comment.