1
1
#include <binsparse/binsparse.h>
2
2
#include <stdio.h>
3
3
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
+
4
12
int main (int argc , char * * argv ) {
5
13
6
14
if (argc < 3 ) {
7
15
printf ("usage: ./mtx2bsp [input.mtx] [output.bsp.h5]:[optional: group] "
8
- "[optional: format]\n" );
16
+ "[optional: format] [optional: compression level 0-9] \n" );
9
17
printf ("\n" );
10
18
printf ("Description: Convert a Matrix Market file to a Binsparse HDF5 "
11
19
"file.\n" );
@@ -29,6 +37,13 @@ int main(int argc, char** argv) {
29
37
"example: ./mtx2bsp chesapeake.mtx chesapeake.bsp.h5:chesapeake CSR\n" );
30
38
printf (" - Same as previous example, but matrix will use CSR "
31
39
"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" );
32
47
return 1 ;
33
48
}
34
49
@@ -49,6 +64,12 @@ int main(int argc, char** argv) {
49
64
format_name = argv [3 ];
50
65
}
51
66
67
+ int compression_level = 9 ;
68
+
69
+ if (argc >= 5 ) {
70
+ compression_level = atoi (argv [4 ]);
71
+ }
72
+
52
73
char * input_file_extension = bsp_get_file_extension (input_fname );
53
74
char * output_file_extension = bsp_get_file_extension (output_fname );
54
75
@@ -90,32 +111,57 @@ int main(int argc, char** argv) {
90
111
printf ("File has very long comments, not printing.\n" );
91
112
}
92
113
114
+ printf ("Printing with compression level %d.\n" , compression_level );
115
+
93
116
cJSON * user_json = cJSON_CreateObject ();
94
117
95
118
assert (user_json != NULL );
96
119
97
120
cJSON_AddStringToObject (user_json , "comment" , m .comments );
98
121
99
122
printf (" === Reading file... ===\n" );
123
+ double begin = gettime ();
100
124
bsp_matrix_t matrix = bsp_mmread (input_fname );
125
+ double end = gettime ();
101
126
printf (" === Done reading. ===\n" );
102
127
128
+ double duration = end - begin ;
129
+ printf ("%lf seconds reading Matrix Market file...\n" , duration );
130
+
103
131
if (perform_suitesparse_declamping ) {
132
+ begin = gettime ();
104
133
bsp_matrix_declamp_values (matrix );
134
+ end = gettime ();
135
+ duration = end - begin ;
136
+ printf ("%lf seconds declamping...\n" , duration );
105
137
}
106
138
139
+ begin = gettime ();
107
140
matrix = bsp_matrix_minimize_values (matrix );
141
+ end = gettime ();
142
+ duration = end - begin ;
143
+ printf ("%lf seconds minimizing values...\n" , duration );
108
144
109
145
if (format != BSP_COOR ) {
146
+ begin = gettime ();
110
147
bsp_matrix_t converted_matrix = bsp_convert_matrix (matrix , format );
111
148
bsp_destroy_matrix_t (matrix );
112
149
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 ));
113
154
}
114
155
115
156
bsp_print_matrix_info (matrix );
116
157
117
158
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 );
119
165
printf (" === Done writing. ===\n" );
120
166
121
167
bsp_destroy_matrix_t (matrix );
0 commit comments