COMBINATORIAL_BLAS 1.6
 
Loading...
Searching...
No Matches
ParIOTest.cpp
Go to the documentation of this file.
1#include <mpi.h>
2#include <sys/time.h>
3#include <iostream>
4#include <functional>
5#include <algorithm>
6#include <vector>
7#include <sstream>
8#include "CombBLAS/CombBLAS.h"
9
10using namespace std;
11using namespace combblas;
12
13
14
15// Simple helper class for declarations: Just the numerical type is templated
16// The index type and the sequential matrix type stays the same for the whole code
17// In this case, they are "int" and "SpDCCols"
18template <class NT>
19class PSpMat
20{
21public:
22 typedef SpDCCols < int64_t, NT > DCCols;
23 typedef SpParMat < int64_t, NT, DCCols > MPI_DCCols;
24};
25
27{
28public:
29 array<char,MAXVERTNAME> getNoNum(int64_t index) { return array<char,MAXVERTNAME>(); }
30
31 template <typename c, typename t>
32 array<char,MAXVERTNAME> read(std::basic_istream<c,t>& is, int64_t index)
33 {
34 array<char,MAXVERTNAME> strarray;
35 string str;
36 is >> str; // read into str
37 std::copy( str.begin(), str.end(), strarray.begin() );
38 if(str.length() < MAXVERTNAME) strarray[str.length()] = '\0'; // null terminating char
39
40 return strarray;
41 }
42
43 template <typename c, typename t>
44 void save(std::basic_ostream<c,t>& os, const array<char,MAXVERTNAME>& strarray, int64_t index)
45 {
46 auto locnull = find(strarray.begin(), strarray.end(), '\0');
47 string str(strarray.begin(), locnull);
48 os << str;
49 }
50};
51
52
53int main(int argc, char* argv[])
54{
55 int nprocs, myrank;
56 MPI_Init(&argc, &argv);
57 MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
58 MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
59
60 if(argc < 2)
61 {
62 if(myrank == 0)
63 {
64 cout << "Usage: ./ParIOTest <MatrixA> <MatrixB_general>" << endl;
65 cout << "<MatrixA> is an absolute address, and file should be in Matrix Market format" << endl;
66 cout << "<MatrixB_general> is an absolute address, file is in general triples format (MCL calls this label input)" << endl;
67
68 }
69 MPI_Finalize();
70 return -1;
71 }
72 {
73 string Aname(argv[1]);
74 string Bname(argv[2]);
75
76 typedef PlusTimesSRing<double, double> PTDOUBLEDOUBLE;
78
80
81 A.ParallelReadMM(Aname, true, maximum<double>());
82 FullyDistVec<int64_t, array<char, MAXVERTNAME> > perm = B.ReadGeneralizedTuples(Bname, maximum<double>());
83
84
85 if (A == B)
86 {
87 SpParHelper::Print("Parallel Matrix Market I/O working correctly\n");
88 }
89 else
90 {
91 SpParHelper::Print("ERROR in Parallel Matrix Market I/O");
92 A.SaveGathered("A_Error.txt");
93 B.SaveGathered("B_Error.txt");
94 }
95
96 perm.ParallelWrite("PermutationVec.mtx", 1, StdArrayReadSaveHandler(), true);
97 }
98 MPI_Finalize();
99 return 0;
100}
101
int main(int argc, char *argv[])
Definition ParIOTest.cpp:53
SelectMaxSRing< bool, int64_t > SR
Definition SpMMError.cpp:18
SpParMat< int64_t, NT, DCCols > MPI_DCCols
Definition ParIOTest.cpp:23
SpDCCols< int64_t, NT > DCCols
Definition ParIOTest.cpp:22
array< char, MAXVERTNAME > getNoNum(int64_t index)
Definition ParIOTest.cpp:29
array< char, MAXVERTNAME > read(std::basic_istream< c, t > &is, int64_t index)
Definition ParIOTest.cpp:32
void save(std::basic_ostream< c, t > &os, const array< char, MAXVERTNAME > &strarray, int64_t index)
Definition ParIOTest.cpp:44
void ParallelWrite(const std::string &filename, bool onebased, HANDLER handler, bool includeindices=true)
static void Print(const std::string &s)
long int64_t
Definition compat.h:21
#define MAXVERTNAME
Definition SpDefs.h:68
double A
double B
Definition options.h:15
Compute the maximum of two values.
Definition Operations.h:155