COMBINATORIAL_BLAS  1.6
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 
10 using namespace std;
11 using 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"
18 template <class NT>
19 class PSpMat
20 {
21 public:
24 };
25 
27 {
28 public:
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 
53 int 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>());
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 
double B
SpDCCols< int64_t, NT > DCCols
Definition: ParIOTest.cpp:22
FullyDistVec< IT, std::array< char, MAXVERTNAME > > ReadGeneralizedTuples(const std::string &, _BinaryOperation)
Definition: SpParMat.cpp:3319
Compute the maximum of two values.
Definition: Operations.h:154
array< char, MAXVERTNAME > read(std::basic_istream< c, t > &is, int64_t index)
Definition: ParIOTest.cpp:32
#define MAXVERTNAME
Definition: SpDefs.h:68
SelectMaxSRing< bool, int32_t > SR
Definition: SpMSpVBench.cpp:59
void SaveGathered(std::string filename, HANDLER handler, bool transpose=false) const
Definition: SpParMat.cpp:3027
int main(int argc, char *argv[])
Definition: ParIOTest.cpp:53
void save(std::basic_ostream< c, t > &os, const array< char, MAXVERTNAME > &strarray, int64_t index)
Definition: ParIOTest.cpp:44
double A
long int64_t
Definition: compat.h:21
void ParallelWrite(const std::string &filename, bool onebased, HANDLER handler, bool includeindices=true)
Definition: FullyDistVec.h:96
SpParMat< int64_t, NT, DCCols > MPI_DCCols
Definition: ParIOTest.cpp:23
Definition: CCGrid.h:4
array< char, MAXVERTNAME > getNoNum(int64_t index)
Definition: ParIOTest.cpp:29
void ParallelReadMM(const std::string &filename, bool onebased, _BinaryOperation BinOp)
Definition: SpParMat.cpp:3417