@@ -68,41 +68,63 @@ void delete_file(char* file_name) {
6868
6969int main (int argc , char * * argv ) {
7070 if (argc < 2 ) {
71- fprintf (stderr , "usage: ./benchmark_read [file_name.h5] [optional: "
72- "compression_level]\n" );
71+ fprintf (stderr ,
72+ "usage: ./benchmark_read [file_name.h5] [scratch_space] [optional: "
73+ "compression_level]\n" );
7374 return 1 ;
7475 }
7576
7677 char * file_name = argv [1 ];
78+ char * scratch_space = argv [2 ];
7779
7880 int compression_level = 0 ;
7981
80- if (argc >= 3 ) {
81- compression_level = atoi (argv [2 ]);
82+ if (argc >= 4 ) {
83+ compression_level = atoi (argv [3 ]);
8284 }
8385
8486 printf ("Opening %s\n" , file_name );
8587
86- const int num_trials = 10 ;
88+ const int num_trials = 1 ;
8789
8890 double durations [num_trials ];
8991
9092 bsp_matrix_t mat = bsp_read_matrix (file_name , NULL );
9193 size_t nbytes = bsp_matrix_nbytes (mat );
9294
9395 char output_filename [2048 ];
94- strncpy (output_filename , "benchmark_write_file_n.h5" , 2047 );
96+ strncpy (output_filename , scratch_space , 2047 );
97+ strncpy (output_filename + strlen (scratch_space ), "/benchmark_write_file_n.h5" ,
98+ 2047 - strlen (scratch_space ));
99+
100+ // Current output name logic does not do much.
101+ assert (num_trials <= 10 );
102+
103+ // To flush the filesystem cache before each trial, change to `true`.
104+ bool cold_cache = false;
105+
106+ // To flush each write to the filesystem and include this in the timing,
107+ // change to `true`.
108+ bool flush_each_write = true;
95109
96110 for (size_t i = 0 ; i < num_trials ; i ++ ) {
97- flush_cache ();
98- output_filename [21 ] = '0' + i ;
111+ if (cold_cache ) {
112+ flush_cache ();
113+ }
114+
115+ output_filename [strlen (scratch_space ) + 21 ] = '0' + i ;
99116 printf ("Writing to file %s\n" , output_filename );
100117
101118 double begin = gettime ();
102119 bsp_write_matrix (output_filename , mat , NULL , NULL , compression_level );
103- flush_writes ();
120+
121+ if (flush_each_write ) {
122+ flush_writes ();
123+ }
124+
104125 double end = gettime ();
105126 durations [i ] = end - begin ;
127+
106128 delete_file (output_filename );
107129 }
108130
@@ -119,13 +141,17 @@ int main(int argc, char** argv) {
119141
120142 double variance = compute_variance (durations , num_trials );
121143
122- printf ( "Wrote file in %lf seconds\n" , durations [num_trials / 2 ]) ;
144+ double median_time = durations [num_trials / 2 ];
123145
124- printf ("Variance is %lf seconds, standard devication is %lf seconds\n" ,
125- variance , sqrt (variance ));
146+ printf ("Wrote file in %lf seconds\n" , median_time );
147+
148+ if (num_trials > 1 ) {
149+ printf ("Variance is %lf seconds, standard devication is %lf seconds\n" ,
150+ variance , sqrt (variance ));
151+ }
126152
127153 double gbytes = ((double ) nbytes ) / 1024 / 1024 / 1024 ;
128- double gbytes_s = gbytes / durations [ num_trials / 2 ] ;
154+ double gbytes_s = gbytes / median_time ;
129155
130156 printf ("Achieved %lf GiB/s\n" , gbytes_s );
131157
@@ -138,5 +164,7 @@ int main(int argc, char** argv) {
138164 }
139165 printf ("]\n" );
140166
167+ printf ("FORPARSER: %s,%lf,%lf\n" , file_name , median_time , gbytes_s );
168+
141169 return 0 ;
142170}
0 commit comments