-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_decompression_speed.c
134 lines (106 loc) · 3.23 KB
/
test_decompression_speed.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* This program has been designed to test the speed of the polynomial
* compression. It is *not* included in the test suite, as it does not
* check the results. If you want to hack libpolycomp's source code to
* make it faster, use this program as a benchmark. */
#include "libpolycomp.h"
#include <stdio.h>
#include <sys/time.h>
#include <fitsio.h>
#include <stdlib.h>
#ifdef WITH_OPENMP
#include <omp.h>
#else
typedef int omp_int_t;
static omp_int_t omp_get_max_threads(void) { return 1; }
#endif
static struct timeval tstart, tstop;
void start_timer() { gettimeofday(&tstart, NULL); }
double stop_timer()
{
gettimeofday(&tstop, NULL);
return (tstop.tv_sec + tstop.tv_usec / 1000000.0)
- (tstart.tv_sec + tstart.tv_usec / 1000000.0);
}
void* read_file_data(const char* file_name)
{
FILE* f;
long file_size;
void* buf;
f = fopen(file_name, "rb");
if (f == NULL) {
fprintf(stderr, "error opening file \"%s\": ", file_name);
perror(NULL);
exit(1);
}
fseek(f, 0, SEEK_END);
file_size = ftell(f);
fseek(f, 0, SEEK_SET);
buf = malloc(file_size);
if (fread(buf, 1, file_size, f) < file_size) {
fprintf(stderr, "error reading file \"%s\": ", file_name);
perror(NULL);
exit(1);
}
fclose(f);
return buf;
}
void save_data_in_fits_file(const char* file_name, double* data,
size_t num_of_elements)
{
fitsfile* file;
int status = 0;
char* ttype[] = { "SAMPLE" };
char* tform[] = { "1D" };
char* tunit[] = { "" };
if (fits_create_file(&file, file_name, &status) != 0)
goto error;
if (fits_create_tbl(file, BINARY_TBL, 0, 1, ttype, tform, tunit,
"DECOMPR", &status) != 0)
goto error;
if (fits_write_col(file, TDOUBLE, 1, 1, 1, num_of_elements, data,
&status) != 0)
goto error;
fits_close_file(file, &status);
return;
error:
fits_report_error(stderr, status);
if (file != NULL)
fits_close_file(file, &status);
exit(1);
}
int main(int argc, const char* argv[])
{
void* buf;
double* decompr;
size_t num_of_elements;
size_t num_of_chunks;
pcomp_polycomp_chunk_t** chunks;
double duration;
if (argc != 3) {
fputs("usage: test_decompression_speed BINARY_FILE "
"OUTPUT_FITS_FILE\n",
stderr);
return 1;
}
#if WITH_OPENMP
printf("OpenMP enabled: 1\n");
printf("number of OpenMP threads: %d\n", omp_get_max_threads());
#else
printf("OpenMP enabled: 0\n");
#endif
printf("input file name: %s\n", argv[1]);
printf("output file name: %s\n", argv[2]);
buf = read_file_data(argv[1]);
start_timer();
pcomp_decode_chunks(&chunks, &num_of_chunks, buf);
duration = stop_timer();
printf("decoding elapsed time (s): %lf\n", duration);
num_of_elements = pcomp_total_num_of_samples(chunks, num_of_chunks);
decompr = malloc(sizeof(double) * num_of_elements);
start_timer();
pcomp_decompress_polycomp(decompr, chunks, num_of_chunks);
duration = stop_timer();
printf("decompression elapsed time (s): %lf\n", duration);
save_data_in_fits_file(argv[2], decompr, num_of_elements);
return 0;
}