COMBINATORIAL_BLAS  1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ReduceTest.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.h"
9 
10 using namespace std;
11 
12 // Simple helper class for declarations: Just the numerical type is templated
13 // The index type and the sequential matrix type stays the same for the whole code
14 // In this case, they are "int" and "SpDCCols"
15 template <class NT>
16 class PSpMat
17 {
18 public:
21 };
22 
23 int main(int argc, char* argv[])
24 {
25  int nprocs, myrank;
26  MPI_Init(&argc, &argv);
27  MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
28  MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
29 
30  if(argc < 4)
31  {
32  if(myrank == 0)
33  {
34  cout << "Usage: ./ReduceTest <MatrixA> <SumColumns> <SumRows>" << endl;
35  cout << "<Matrix>,<SumColumns>,<SumRows> are absolute addresses, and files should be in triples format" << endl;
36  }
37  MPI_Finalize();
38  return -1;
39  }
40  {
41  string Aname(argv[1]);
42  string Bname(argv[2]);
43  string Cname(argv[3]);
44 
45  ifstream inputB(Bname.c_str());
46  ifstream inputC(Cname.c_str());
47  MPI_Barrier(MPI_COMM_WORLD);
48 
52 
53  A.ReadDistribute(Aname, 0);
54  colsums.ReadDistribute(inputB, 0);
55  rowsums.ReadDistribute(inputC, 0);
56 
57  FullyDistVec< int, double > rowsums_control, colsums_control;
58  A.Reduce(rowsums_control, Row, std::plus<double>() , 0.0);
59  A.Reduce(colsums_control, Column, std::plus<double>() , 0.0);
60 
61  if (rowsums_control == rowsums && colsums_control == colsums)
62  {
63  SpParHelper::Print("Reduction via summation working correctly\n");
64  }
65  else
66  {
67  SpParHelper::Print("ERROR in Reduce via summation, go fix it!\n");
68  }
69 
70  inputB.clear();
71  inputB.close();
72  inputC.clear();
73  inputC.close();
74  }
75  MPI_Finalize();
76  return 0;
77 }
78 
79