-
Notifications
You must be signed in to change notification settings - Fork 23
/
ParIOTest.cpp
98 lines (80 loc) · 2.47 KB
/
ParIOTest.cpp
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
#include <mpi.h>
#include <sys/time.h>
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
#include <sstream>
#include "CombBLAS/CombBLAS.h"
using namespace std;
using namespace combblas;
// Simple helper class for declarations: Just the numerical type is templated
// The index type and the sequential matrix type stays the same for the whole code
// In this case, they are "int" and "SpDCCols"
template <class NT>
class PSpMat
{
public:
typedef SpDCCols < int64_t, NT > DCCols;
typedef SpParMat < int64_t, NT, DCCols > MPI_DCCols;
};
class StdArrayReadSaveHandler
{
public:
array<char,MAXVERTNAME> getNoNum(int64_t index) { return array<char,MAXVERTNAME>(); }
template <typename c, typename t>
array<char,MAXVERTNAME> read(std::basic_istream<c,t>& is, int64_t index)
{
array<char,MAXVERTNAME> strarray;
string str;
is >> str; // read into str
std::copy( str.begin(), str.end(), strarray.begin() );
if(str.length() < MAXVERTNAME) strarray[str.length()] = '\0'; // null terminating char
return strarray;
}
template <typename c, typename t>
void save(std::basic_ostream<c,t>& os, const array<char,MAXVERTNAME>& strarray, int64_t index)
{
auto locnull = find(strarray.begin(), strarray.end(), '\0');
string str(strarray.begin(), locnull);
os << str;
}
};
int main(int argc, char* argv[])
{
int nprocs, myrank;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
if(argc < 3)
{
if(myrank == 0)
{
cout << "Usage: ./ParIOTest <MatrixA> <MatrixB_general>" << endl;
cout << "<MatrixA> is an absolute address, and file should be in Matrix Market format" << endl;
cout << "<MatrixB_general> is an absolute address, file is in general triples format (MCL calls this label input)" << endl;
}
MPI_Finalize();
return -1;
}
{
string Aname(argv[1]);
string Bname(argv[2]);
PSpMat<double>::MPI_DCCols A, B;
A.ParallelReadMM(Aname, true, maximum<double>());
FullyDistVec<int64_t, array<char, MAXVERTNAME> > perm = B.ReadGeneralizedTuples(Bname, maximum<double>());
if (A == B)
{
SpParHelper::Print("Parallel Matrix Market I/O working correctly\n");
}
else
{
SpParHelper::Print("ERROR in Parallel Matrix Market I/O");
A.ParallelWriteMM("A_Error.mtx", true);
B.ParallelWriteMM("B_Error.mtx", true);
}
perm.ParallelWrite("PermutationVec.mtx", 1, StdArrayReadSaveHandler(), true);
}
MPI_Finalize();
return 0;
}