comparison src/fftw-3.3.3/libbench2/allocate.c @ 10:37bf6b4a2645

Add FFTW3
author Chris Cannam
date Wed, 20 Mar 2013 15:35:50 +0000
parents
children
comparison
equal deleted inserted replaced
9:c0fb53affa76 10:37bf6b4a2645
1 /* not worth copyrighting */
2
3
4 #include "bench.h"
5
6 static void bounds(bench_problem *p, int *ilb, int *iub, int *olb, int *oub)
7 {
8 bench_tensor *t = tensor_append(p->sz, p->vecsz);
9 tensor_ibounds(t, ilb, iub);
10 tensor_obounds(t, olb, oub);
11 tensor_destroy(t);
12 }
13
14 /*
15 * Allocate I/O arrays for a problem.
16 *
17 * This is the default routine that can be overridden by the user in
18 * complicated cases.
19 */
20 void problem_alloc(bench_problem *p)
21 {
22 int ilb, iub, olb, oub;
23 int isz, osz;
24
25 bounds(p, &ilb, &iub, &olb, &oub);
26 isz = iub - ilb;
27 osz = oub - olb;
28
29 if (p->kind == PROBLEM_COMPLEX) {
30 bench_complex *in, *out;
31
32 p->iphyssz = isz;
33 p->inphys = in = (bench_complex *) bench_malloc(isz * sizeof(bench_complex));
34 p->in = in - ilb;
35
36 if (p->in_place) {
37 p->out = p->in;
38 p->outphys = p->inphys;
39 p->ophyssz = p->iphyssz;
40 } else {
41 p->ophyssz = osz;
42 p->outphys = out = (bench_complex *) bench_malloc(osz * sizeof(bench_complex));
43 p->out = out - olb;
44 }
45 } else if (p->kind == PROBLEM_R2R) {
46 bench_real *in, *out;
47
48 p->iphyssz = isz;
49 p->inphys = in = (bench_real *) bench_malloc(isz * sizeof(bench_real));
50 p->in = in - ilb;
51
52 if (p->in_place) {
53 p->out = p->in;
54 p->outphys = p->inphys;
55 p->ophyssz = p->iphyssz;
56 } else {
57 p->ophyssz = osz;
58 p->outphys = out = (bench_real *) bench_malloc(osz * sizeof(bench_real));
59 p->out = out - olb;
60 }
61 } else if (p->kind == PROBLEM_REAL && p->sign < 0) { /* R2HC */
62 bench_real *in;
63 bench_complex *out;
64
65 isz = isz > osz*2 ? isz : osz*2;
66 p->iphyssz = isz;
67 p->inphys = in = (bench_real *) bench_malloc(p->iphyssz * sizeof(bench_real));
68 p->in = in - ilb;
69
70 if (p->in_place) {
71 p->out = p->in;
72 p->outphys = p->inphys;
73 p->ophyssz = p->iphyssz / 2;
74 } else {
75 p->ophyssz = osz;
76 p->outphys = out = (bench_complex *) bench_malloc(osz * sizeof(bench_complex));
77 p->out = out - olb;
78 }
79 } else if (p->kind == PROBLEM_REAL && p->sign > 0) { /* HC2R */
80 bench_real *out;
81 bench_complex *in;
82
83 osz = osz > isz*2 ? osz : isz*2;
84 p->ophyssz = osz;
85 p->outphys = out = (bench_real *) bench_malloc(p->ophyssz * sizeof(bench_real));
86 p->out = out - olb;
87
88 if (p->in_place) {
89 p->in = p->out;
90 p->inphys = p->outphys;
91 p->iphyssz = p->ophyssz / 2;
92 } else {
93 p->iphyssz = isz;
94 p->inphys = in = (bench_complex *) bench_malloc(isz * sizeof(bench_complex));
95 p->in = in - ilb;
96 }
97 } else {
98 BENCH_ASSERT(0); /* TODO */
99 }
100 }
101
102 void problem_free(bench_problem *p)
103 {
104 if (p->outphys && p->outphys != p->inphys)
105 bench_free(p->outphys);
106 if (p->inphys)
107 bench_free(p->inphys);
108 tensor_destroy(p->sz);
109 tensor_destroy(p->vecsz);
110 }