Skip to content

Commit f5a4589

Browse files
committed
Added support for pattern option for MatrixMarket format
1 parent da64598 commit f5a4589

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

include/GMDP/utils/edgelist.h

+8-6
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ bool readLine (FILE * ifile, int * src, int * dst, T * val, bool binaryformat=tr
133133
}
134134

135135
template<typename T>
136-
void get_maxid_and_nnz(FILE* fp, int* m, int* n, unsigned long int* nnz, bool* symmetric, bool binaryformat=true, bool header=true, bool edgeweights=true) {
136+
void get_maxid_and_nnz(FILE* fp, int* m, int* n, unsigned long int* nnz, bool* symmetric, bool *pattern, bool binaryformat=true, bool header=true, bool edgeweights=true) {
137137
if (header) {
138138
int tmp_[3];
139139
if (binaryformat) {
@@ -151,6 +151,8 @@ void get_maxid_and_nnz(FILE* fp, int* m, int* n, unsigned long int* nnz, bool* s
151151
position = ftell(fp);
152152
fgets(line, 256, fp);
153153
*symmetric = strstr(line, "symmetric") != NULL;
154+
*pattern = strstr(line, "pattern") != NULL;
155+
edgeweights = *pattern;
154156

155157
// skip all the comments
156158
line[0] = '%';
@@ -266,7 +268,7 @@ void load_edgelist(const char* dir, edgelist_t<T>* edgelist, bool single=true,
266268
edgelist->m = 0;
267269
edgelist->n = 0;
268270
edgelist->nnz = 0;
269-
bool symmetric;
271+
bool symmetric, pattern;
270272
for(int i = global_myrank ; ; i += global_nrank)
271273
{
272274
std::stringstream fname_ss;
@@ -287,7 +289,7 @@ void load_edgelist(const char* dir, edgelist_t<T>* edgelist, bool single=true,
287289

288290
int m_, n_;
289291
unsigned long nnz_;
290-
get_maxid_and_nnz<T>(fp, &m_, &n_, &nnz_, &symmetric, binaryformat, header, edgeweights);
292+
get_maxid_and_nnz<T>(fp, &m_, &n_, &nnz_, &symmetric, &pattern, binaryformat, header, edgeweights);
291293
edgelist->m = std::max(m_, edgelist->m);
292294
edgelist->n = std::max(n_, edgelist->n);
293295
edgelist->nnz += nnz_;
@@ -304,7 +306,7 @@ void load_edgelist(const char* dir, edgelist_t<T>* edgelist, bool single=true,
304306
edgelist->m = max_m;
305307
edgelist->n = max_n;
306308

307-
std::cout << (symmetric ? "Undirected graph" : "Directed graph") << std::endl;
309+
std::cout << (symmetric ? "Undirected " : "Directed ") << (pattern ? "Unweighted" : "Weighted") << std::endl;
308310
std::cout << "Got: " << edgelist->m << " by " << edgelist->n << " vertices" << std::endl;
309311
std::cout << "Got: " << edgelist->nnz << " edges" << std::endl;
310312

@@ -330,14 +332,14 @@ void load_edgelist(const char* dir, edgelist_t<T>* edgelist, bool single=true,
330332
if (header) { //remove header
331333
int m_, n_;
332334
unsigned long nnz_;
333-
get_maxid_and_nnz<T>(fp, &m_, &n_, &nnz_, &symmetric, binaryformat, header, edgeweights);
335+
get_maxid_and_nnz<T>(fp, &m_, &n_, &nnz_, &symmetric, &pattern, binaryformat, header, edgeweights);
334336
}
335337
int j = 0;
336338
while(true) {
337339
if (feof(fp)) {
338340
break;
339341
}
340-
if (!readLine<T>(fp, &(edgelist->edges[nnzcnt].src), &(edgelist->edges[nnzcnt].dst), &(edgelist->edges[nnzcnt].val), binaryformat, edgeweights)) {
342+
if (!readLine<T>(fp, &(edgelist->edges[nnzcnt].src), &(edgelist->edges[nnzcnt].dst), &(edgelist->edges[nnzcnt].val), binaryformat, !pattern && edgeweights)) {
341343
break;
342344
}
343345
#ifdef __DEBUG

0 commit comments

Comments
 (0)