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