COMBINATORIAL_BLAS  1.6
SpMMError.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 <string>
8 #include <sstream>
9 #include <stdint.h>
10 #include "CombBLAS/CombBLAS.h"
11 
12 using namespace combblas;
13 
16 
17 
21 
22 #define ValueType int64_t
26 
29 
30 int main(int argc, char* argv[])
31 {
32  int torusi[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
33  int torusj[] = {3,0,1,2,7,4,5,6,11,8,9,10,15,12,13,14,1,2,3,0,5,6,7,4,9,10,11,8,13,14,15,12,12,13,14,15,0,1,2,3,4,5,6,7,8,9,10,11,4,5,6,7,8,9,10,11,12,13,14,15,0,1,2,3};
34 
35  int nprocs, myrank;
36  MPI_Init(&argc, &argv);
37  MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
38  MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
39  {
40  SpParHelper::Print("Usage: SpMMError [arg]\nIf arg is present then matrix will be read from torus.mtx (no error).\nIf arg is absent, matrix will be created from vectors (error present)\n\n");
41  // Declare objects
42  MatType G1;
43  MatType G2;
44  if (argc > 1)
45  {
46  SpParHelper::Print("Reading torus.mtx\n");
47  std::ifstream input("torus.mtx");
48  G1.ReadDistribute(input, 0); // read it from file
49  ifstream input2("torus.mtx");
50  G2.ReadDistribute(input2, 0);
51  SpParHelper::Print("Read input\n");
52 
53  }
54  else
55  {
56  SpParHelper::Print("Creating matrices from built-in vectors\n");
57  FullyDistVec<int64_t, ValueType> dpvi(64, 0, 0);
58  FullyDistVec<int64_t, ValueType> dpvj(64, 0, 0);
59  FullyDistVec<int64_t, ValueType> dpvv(64, 1, 0);
60  for (int i = 0; i <64; i++)
61  {
62  dpvi.SetElement(i, torusi[i]);
63  dpvj.SetElement(i, torusj[i]);
64  }
65  dpvi.DebugPrint();
66  dpvj.DebugPrint();
67  G1 = MatType(16, 16, dpvi, dpvj, dpvv);
68  G2 = MatType(16, 16, dpvi, dpvj, dpvv);
69 
70  ofstream out1("G1.txt");
71  ofstream out2("G2.txt");
72  out1 << G1;
73  out2 << G2;
74  }
75 
76  MatType G3(G1);
77  G1.PrintInfo();
78  G2.PrintInfo();
79  G3.PrintInfo();
80  SpParHelper::Print("The nnz values should be 112, 112, 112:\n");
81 
82 
83  MatType G12 = Mult_AnXBn_Synch<PlusTimesSRing<int64_t, ValueType> >(G1, G2);
84  G12.PrintInfo();
85  ofstream out12("G12.txt");
86  out12 << G12;
87 
88  MatType G13 = Mult_AnXBn_Synch<PlusTimesSRing<int64_t, ValueType> >(G1, G3);
89  G13.PrintInfo();
90 
91  MatType G23 = Mult_AnXBn_Synch<PlusTimesSRing<int64_t, ValueType> >(G2, G3);
92  G23.PrintInfo();
93 
94  }
95  MPI_Finalize();
96  return 0;
97 }
98 
PSpMat_Int64 MatType
Definition: SpMMError.cpp:25
int main(int argc, char *argv[])
Definition: SpMMError.cpp:30
SpDCCols< int64_t, ValueType > DCColsType
Definition: SpMMError.cpp:23
SpParMat< int64_t, bool, SpDCCols< int64_t, bool > > PSpMat_Bool
Definition: SpMMError.cpp:19
SelectMaxSRing< bool, int64_t > SR
Definition: SpMMError.cpp:18
double cblas_allgathertime
Definition: SpMMError.cpp:15
double cblas_alltoalltime
Definition: SpMMError.cpp:14
SpParMat< int64_t, ValueType, DCColsType > PSpMat_Int64
Definition: SpMMError.cpp:24
SpParMat< int64_t, int, SpDCCols< int64_t, int > > PSpMat_Int
Definition: SpMMError.cpp:20
void SetElement(IT indx, NT numx)
static void Print(const std::string &s)
void ReadDistribute(const std::string &filename, int master, bool nonum, HANDLER handler, bool transpose=false, bool pario=false)
Definition: SpParMat.cpp:3560
void PrintInfo() const
Definition: SpParMat.cpp:2387
Definition: CCGrid.h:4
DECLARE_PROMOTE(int64_t, bool, int64_t)