11#include <binsparse/binsparse.h>
22#include <stdio.h>
33
4+ #include <time.h>
5+
6+ double gettime () {
7+ struct timespec time ;
8+ clock_gettime (CLOCK_MONOTONIC , & time );
9+ return ((double ) time .tv_sec ) + ((double ) 1e-9 ) * time .tv_nsec ;
10+ }
11+
412int main (int argc , char * * argv ) {
513
614 if (argc < 3 ) {
715 printf ("usage: ./mtx2bsp [input.mtx] [output.bsp.h5]:[optional: group] "
8- "[optional: format]\n" );
16+ "[optional: format] [optional: compression level 0-9] \n" );
917 printf ("\n" );
1018 printf ("Description: Convert a Matrix Market file to a Binsparse HDF5 "
1119 "file.\n" );
@@ -29,6 +37,13 @@ int main(int argc, char** argv) {
2937 "example: ./mtx2bsp chesapeake.mtx chesapeake.bsp.h5:chesapeake CSR\n" );
3038 printf (" - Same as previous example, but matrix will use CSR "
3139 "format.\n" );
40+ printf ("example: ./mtx2bsp chesapeake.mtx chesapeake.bsp.h5:chesapeake CSR "
41+ "5\n" );
42+ printf (" - Same as previous example, but will use GZip compression "
43+ "level 5.\n" );
44+ printf (" 0 is no compression, 1-9 correspond to GZip compression "
45+ "levels.\n" );
46+ printf (" Default is 9.\n" );
3247 return 1 ;
3348 }
3449
@@ -49,6 +64,12 @@ int main(int argc, char** argv) {
4964 format_name = argv [3 ];
5065 }
5166
67+ int compression_level = 9 ;
68+
69+ if (argc >= 5 ) {
70+ compression_level = atoi (argv [4 ]);
71+ }
72+
5273 char * input_file_extension = bsp_get_file_extension (input_fname );
5374 char * output_file_extension = bsp_get_file_extension (output_fname );
5475
@@ -90,32 +111,57 @@ int main(int argc, char** argv) {
90111 printf ("File has very long comments, not printing.\n" );
91112 }
92113
114+ printf ("Printing with compression level %d.\n" , compression_level );
115+
93116 cJSON * user_json = cJSON_CreateObject ();
94117
95118 assert (user_json != NULL );
96119
97120 cJSON_AddStringToObject (user_json , "comment" , m .comments );
98121
99122 printf (" === Reading file... ===\n" );
123+ double begin = gettime ();
100124 bsp_matrix_t matrix = bsp_mmread (input_fname );
125+ double end = gettime ();
101126 printf (" === Done reading. ===\n" );
102127
128+ double duration = end - begin ;
129+ printf ("%lf seconds reading Matrix Market file...\n" , duration );
130+
103131 if (perform_suitesparse_declamping ) {
132+ begin = gettime ();
104133 bsp_matrix_declamp_values (matrix );
134+ end = gettime ();
135+ duration = end - begin ;
136+ printf ("%lf seconds declamping...\n" , duration );
105137 }
106138
139+ begin = gettime ();
107140 matrix = bsp_matrix_minimize_values (matrix );
141+ end = gettime ();
142+ duration = end - begin ;
143+ printf ("%lf seconds minimizing values...\n" , duration );
108144
109145 if (format != BSP_COOR ) {
146+ begin = gettime ();
110147 bsp_matrix_t converted_matrix = bsp_convert_matrix (matrix , format );
111148 bsp_destroy_matrix_t (matrix );
112149 matrix = converted_matrix ;
150+ end = gettime ();
151+ duration = end - begin ;
152+ printf ("%lf seconds converting to %s format...\n" , duration ,
153+ bsp_get_matrix_format_string (format ));
113154 }
114155
115156 bsp_print_matrix_info (matrix );
116157
117158 printf (" === Writing to %s... ===\n" , output_fname );
118- bsp_write_matrix (output_fname , matrix , group_name , user_json );
159+ begin = gettime ();
160+ bsp_write_matrix (output_fname , matrix , group_name , user_json ,
161+ compression_level );
162+ end = gettime ();
163+ duration = end - begin ;
164+ printf ("%lf seconds writing Binsparse file...\n" , duration );
119165 printf (" === Done writing. ===\n" );
120166
121167 bsp_destroy_matrix_t (matrix );
0 commit comments