-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench-disk.c
109 lines (99 loc) · 3.46 KB
/
bench-disk.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
/*
* Benchmark dSFMT and ranlux performances.
*
* Dario Mapelli, [email protected]
*
* Detailed analysis of the time required by the various operations.
* It does not use huge arrays, it tests how saving the data to the disk
* affects the execution time
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include "ranlxd.h"
#include "dSFMT.h"
#include "dSFMT-api.h"
#include "ranlux-api.h"
int main (int numArg, char * listArg[])
{
int rand_length = 1e6 ;
double max_disk = 100. ; //MiB
double disk_dimension =
(double) 18 * 2 * rand_length / 1024. / 1024. ;
printf(" rand_arr storage dimension: %f MiB \n\n", disk_dimension);
if (2*disk_dimension > max_disk) {
printf("rand_arr too big (check on disk)\n");
return 0;
}
char filename[64];
int idx_file = (int) time(NULL);
printf ("File produced ID: %d\n", idx_file);
sprintf (filename, "rand_%d.txt", idx_file);
FILE *output_file = fopen (filename, "w+");
//defined in time.h, used to compute the execution times
clock_t start, checkpoint, checkpoint1, checkpoint2, end;
double alloc_time, gen_time, copy_time, free_time, cpu_time_tot;
//this is the array that will be used to generate the random numbers
double *rand_arr;
// ranlux
start = clock();
int ranlux_check = ranlux_alloc (&rand_arr, rand_length) ;
if (ranlux_check==1){
exit(EXIT_FAILURE) ;
}
checkpoint = clock();
rlxd_init(1,time(NULL));
ranlxd (rand_arr,rand_length);
checkpoint1 = clock();
int i=0;
for (i=0; i<rand_length; i++) {
fprintf(output_file, "%.15f\n", rand_arr[i]);
}
checkpoint2 = clock();
free(rand_arr) ;
end = clock();
alloc_time = ((double) (checkpoint - start)) / CLOCKS_PER_SEC ;
printf("ranlux alloc time: %10f sec\n", alloc_time);
gen_time = ((double) (checkpoint1 - checkpoint)) / CLOCKS_PER_SEC ;
printf("ranlux gen time: %10f sec\n", gen_time);
copy_time = ((double) (checkpoint2 - checkpoint1)) / CLOCKS_PER_SEC ;
printf("ranlux fprintf time: %10f sec\n", copy_time);
free_time = ((double) (end - checkpoint2)) / CLOCKS_PER_SEC ;
printf("ranlux free time: %10f sec\n", free_time);
cpu_time_tot = ((double) (end - start)) / CLOCKS_PER_SEC ;
printf("ranlux total time: %10f sec\n", cpu_time_tot);
// dSFMT
printf("\n");
start = clock();
int size = dsfmt_get_min_array_size();
if (size < rand_length) {
size = rand_length;
}
int dSFMT_check = dSFMT_alloc (&rand_arr, size) ;
if (dSFMT_check == 1) {
exit(EXIT_FAILURE) ;
}
checkpoint = clock();
dsfmt_gv_init_gen_rand( time (NULL) ) ;
dsfmt_gv_fill_array_close_open(rand_arr, size);
checkpoint1 = clock();
for (i=0; i<rand_length; i++) {
fprintf(output_file, "%.15f\n", rand_arr[i]);
}
checkpoint2 = clock();
free(rand_arr) ;
end = clock();
alloc_time = ((double) (checkpoint - start)) / CLOCKS_PER_SEC ;
printf("dSFMT alloc time: %10f sec\n", alloc_time);
gen_time = ((double) (checkpoint1 - checkpoint)) / CLOCKS_PER_SEC ;
printf("dSFMT gen time: %10f sec\n", gen_time);
copy_time = ((double) (checkpoint2 - checkpoint1)) / CLOCKS_PER_SEC ;
printf("dSFMT fprintf time: %10f sec\n", copy_time);
free_time = ((double) (end - checkpoint2)) / CLOCKS_PER_SEC ;
printf("dSFMT free time: %10f sec\n", free_time);
cpu_time_tot = ((double) (end - start)) / CLOCKS_PER_SEC ;
printf("dSFMT total time: %10f sec\n", cpu_time_tot);
fclose(output_file);
return 0;
}