COMBINATORIAL_BLAS  1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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.h"
11 
14 
15 
19 
20 #define ValueType int64_t
24 
26 DECLARE_PROMOTE(DCColsType, DCColsType, DCColsType)
27 
28 int main(int argc, char* argv[])
29 {
30  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};
31  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};
32 
33  int nprocs, myrank;
34  MPI_Init(&argc, &argv);
35  MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
36  MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
37  {
38  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");
39  // Declare objects
40  MatType G1;
41  MatType G2;
42  if (argc > 1)
43  {
44  SpParHelper::Print("Reading torus.mtx\n");
45  ifstream input("torus.mtx");
46  G1.ReadDistribute(input, 0); // read it from file
47  ifstream input2("torus.mtx");
48  G2.ReadDistribute(input2, 0);
49  SpParHelper::Print("Read input\n");
50 
51  }
52  else
53  {
54  SpParHelper::Print("Creating matrices from built-in vectors\n");
55  FullyDistVec<int64_t, ValueType> dpvi(64, 0, 0);
56  FullyDistVec<int64_t, ValueType> dpvj(64, 0, 0);
57  FullyDistVec<int64_t, ValueType> dpvv(64, 1, 0);
58  for (int i = 0; i <64; i++)
59  {
60  dpvi.SetElement(i, torusi[i]);
61  dpvj.SetElement(i, torusj[i]);
62  }
63  dpvi.DebugPrint();
64  dpvj.DebugPrint();
65  G1 = MatType(16, 16, dpvi, dpvj, dpvv);
66  G2 = MatType(16, 16, dpvi, dpvj, dpvv);
67 
68  ofstream out1("G1.txt");
69  ofstream out2("G2.txt");
70  out1 << G1;
71  out2 << G2;
72  }
73 
74  MatType G3(G1);
75  G1.PrintInfo();
76  G2.PrintInfo();
77  G3.PrintInfo();
78  SpParHelper::Print("The nnz values should be 112, 112, 112:\n");
79 
80 
81  MatType G12 = Mult_AnXBn_Synch<PlusTimesSRing<int64_t, ValueType> >(G1, G2);
82  G12.PrintInfo();
83  ofstream out12("G12.txt");
84  out12 << G12;
85 
86  MatType G13 = Mult_AnXBn_Synch<PlusTimesSRing<int64_t, ValueType> >(G1, G3);
87  G13.PrintInfo();
88 
89  MatType G23 = Mult_AnXBn_Synch<PlusTimesSRing<int64_t, ValueType> >(G2, G3);
90  G23.PrintInfo();
91 
92  }
93  MPI_Finalize();
94  return 0;
95 }
96