-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.c
More file actions
66 lines (50 loc) · 1.48 KB
/
main.c
File metadata and controls
66 lines (50 loc) · 1.48 KB
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
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <complex.h>
#include <fftw3.h>
#include <time.h>
#include <string.h>
#include "lalgebra.h"
#include "fht.h"
#include "io.h"
#include "parameters.h"
int main(int argc, char *argv[]) {
clock_t fclock, nclock;
int i;
double *data = (double*) fftw_malloc(sizeof(double) * (2*LITN+1));
double *naiveResult = (double*) fftw_malloc(sizeof(double) * BIGN);
double *fancyResult = (double*) fftw_malloc(sizeof(double) * BIGN);
// Load input data
oneDFileReader("data/input.txt", (2*LITN+1), data);
for(i=0; i<=2*LITN; ++i) {
data[i] *= exp(0 - pow(xk(i), 2) / 2);
}
// Perform transformations
initFastFouriers(BIGN);
initRns(BIGN);
nclock = clock();
naiveTransform(data, naiveResult);
nclock -= clock();
fclock = clock();
oneDTransform(data, fancyResult);
fclock -= clock();
destroyFastFouriers(BIGN);
// Save output data
FILE *resultsn;
FILE *resultsf;
resultsn = fopen("data/result_n.txt", "wt+");
resultsf = fopen("data/result_f.txt", "wt+");
for(i=0; i<BIGN; ++i){
fancyResult[i] *= (2*BIGC) / LITN;
naiveResult[i] *= (2*BIGC) / LITN;
fprintf(resultsn, "%.16lf\n", naiveResult[i]);
fprintf(resultsf, "%.16lf\n", fancyResult[i]);
}
fclose(resultsn);
fclose(resultsf);
fprintf(stdout, "Naive transform took %li\n", -nclock);
fprintf(stdout, "Fancy transform took %li\n", -fclock);
fprintf(stdout, "Clocks per second: %li\n", CLOCKS_PER_SEC);
return 0;
}