COMBINATORIAL_BLAS
1.6
Loading...
Searching...
No Matches
SpGEMM3D.cpp
Go to the documentation of this file.
1
/****************************************************************/
2
/* Parallel Combinatorial BLAS Library (for Graph Computations) */
3
/* version 1.6 -------------------------------------------------*/
4
/* date: 6/15/2017 ---------------------------------------------*/
5
/* authors: Ariful Azad, Aydin Buluc --------------------------*/
6
/****************************************************************/
7
/*
8
Copyright (c) 2010-2017, The Regents of the University of California
9
10
Permission is hereby granted, free of charge, to any person obtaining a copy
11
of this software and associated documentation files (the "Software"), to deal
12
in the Software without restriction, including without limitation the rights
13
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
copies of the Software, and to permit persons to whom the Software is
15
furnished to do so, subject to the following conditions:
16
17
The above copyright notice and this permission notice shall be included in
18
all copies or substantial portions of the Software.
19
20
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26
THE SOFTWARE.
27
*/
28
29
#include <mpi.h>
30
#include <
sys/time.h
>
31
#include <iostream>
32
#include <functional>
33
#include <algorithm>
34
#include <vector>
35
#include <sstream>
36
#include "CombBLAS/CombBLAS.h"
37
#include "CombBLAS/CommGrid3D.h"
38
#include "CombBLAS/SpParMat3D.h"
39
#include "CombBLAS/ParFriends.h"
40
41
using namespace
std;
42
using namespace
combblas
;
43
44
#define EPS 0.0001
45
46
#ifdef _OPENMP
47
int
cblas_splits
=
omp_get_max_threads
();
48
#else
49
int
cblas_splits
= 1;
50
#endif
51
52
53
// Simple helper class for declarations: Just the numerical type is templated
54
// The index type and the sequential matrix type stays the same for the whole code
55
// In this case, they are "int" and "SpDCCols"
56
template
<
class
NT>
57
class
PSpMat
58
{
59
public
:
60
typedef
SpDCCols < int64_t, NT >
DCCols
;
61
typedef
SpParMat < int64_t, NT, DCCols >
MPI_DCCols
;
62
};
63
64
int
main
(
int
argc
,
char
*
argv
[])
65
{
66
int
nprocs
, myrank;
67
MPI_Init
(&
argc
, &
argv
);
68
MPI_Comm_size
(
MPI_COMM_WORLD
,&
nprocs
);
69
MPI_Comm_rank
(
MPI_COMM_WORLD
,&myrank);
70
71
if
(
argc
< 2){
72
if
(myrank == 0)
73
{
74
cout
<<
"Usage: ./<Binary> <MatrixA> "
<<
endl
;
75
}
76
MPI_Finalize
();
77
return
-1;
78
}
79
else
{
80
double
vm_usage
,
resident_set
;
81
string
Aname
(
argv
[1]);
82
if
(myrank == 0){
83
fprintf
(
stderr
,
"Data: %s\n"
,
argv
[1]);
84
}
85
shared_ptr<CommGrid>
fullWorld
;
86
fullWorld
.reset(
new
CommGrid
(
MPI_COMM_WORLD
, 0, 0) );
87
88
double
t0
,
t1
;
89
90
SpParMat<int64_t, double, SpDCCols < int64_t, double >
> M(
fullWorld
);
91
93
//t0 = MPI_Wtime();
94
//M.ParallelReadMM(Aname, true, maximum<double>());
95
//t1 = MPI_Wtime();
96
//if(myrank == 0) fprintf(stderr, "Time taken to read file: %lf\n", t1-t0);
97
//t0 = MPI_Wtime();
98
//FullyDistVec<int64_t, int64_t> p( M.getcommgrid() );
99
//FullyDistVec<int64_t, int64_t> q( M.getcommgrid() );
100
//p.iota(M.getnrow(), 0);
101
//q.iota(M.getncol(), 0);
102
//p.RandPerm();
103
//q.RandPerm();
104
//(M)(p,q,true);// in-place permute to save memory
105
//t1 = MPI_Wtime();
106
//if(myrank == 0) fprintf(stderr, "Time taken to permuatate input: %lf\n", t1-t0);
107
108
// Read labelled triple files
109
t0
=
MPI_Wtime
();
110
M.ReadGeneralizedTuples(
Aname
,
maximum<double>
());
111
t1
=
MPI_Wtime
();
112
if
(myrank == 0)
fprintf
(
stderr
,
"Time taken to read file: %lf\n"
,
t1
-
t0
);
113
114
typedef
PlusTimesSRing<double, double>
PTFF
;
115
116
// Run 2D multiplication to compare against
117
SpParMat<int64_t, double, SpDCCols < int64_t, double >
>
A2D
(M);
118
SpParMat<int64_t, double, SpDCCols < int64_t, double >
>
B2D
(M);
119
SpParMat<int64_t, double, SpDCCols < int64_t, double >
>
C2D
=
120
Mult_AnXBn_Synch<PTFF, double, SpDCCols<int64_t, double>
,
int64_t
,
double
,
double
,
SpDCCols<int64_t, double>
,
SpDCCols<int64_t, double>
>
121
(
A2D
,
B2D
);
122
123
if
(myrank == 0)
fprintf
(
stderr
,
"2D Multiplication done \n"
);
124
125
// Increase number of layers 1 -> 4 -> 16
126
for
(
int
layers = 1; layers <= 16; layers = layers * 4){
127
// Create two copies of input matrix which would be used in multiplication
128
SpParMat<int64_t, double, SpDCCols < int64_t, double >
>
A2
(M);
129
SpParMat<int64_t, double, SpDCCols < int64_t, double >
>
B2
(M);
130
131
// Convert 2D matrices to 3D
132
SpParMat3D<int64_t, double, SpDCCols < int64_t, double >
>
A3D
(
A2
, layers,
true
,
false
);
133
SpParMat3D<int64_t, double, SpDCCols < int64_t, double >
>
B3D
(
B2
, layers,
false
,
false
);
134
if
(myrank == 0)
fprintf
(
stderr
,
"Running 3D with %d layers\n"
, layers);
135
136
SpParMat3D<int64_t, double, SpDCCols < int64_t, double >
>
C3D
=
137
Mult_AnXBn_SUMMA3D<PTFF, double, SpDCCols<int64_t, double>
,
int64_t
,
double
,
double
,
SpDCCols<int64_t, double>
,
SpDCCols<int64_t, double>
>
138
(
A3D
,
B3D
);
139
140
SpParMat<int64_t, double, SpDCCols < int64_t, double >
>
C3D2D
=
C3D
.Convert2D();
141
if
(
C2D
==
C3D2D
){
142
if
(myrank == 0)
fprintf
(
stderr
,
"Correct!\n"
);
143
}
144
else
{
145
if
(myrank == 0)
fprintf
(
stderr
,
"Not correct!\n"
);
146
}
147
}
148
149
}
150
MPI_Finalize
();
151
return
0;
152
}
main
int main()
Definition
Driver.cpp:12
cblas_splits
int cblas_splits
Definition
SpGEMM3D.cpp:49
PSpMat
Definition
BcastTest.cpp:35
PSpMat::MPI_DCCols
SpParMat< int64_t, NT, DCCols > MPI_DCCols
Definition
SpGEMM3D.cpp:61
PSpMat::DCCols
SpDCCols< int64_t, NT > DCCols
Definition
SpGEMM3D.cpp:60
combblas::CommGrid
Definition
CommGrid.h:45
combblas::DistEdgeList
Definition
DistEdgeList.h:82
nprocs
int nprocs
Definition
comms.cpp:55
int64_t
long int64_t
Definition
compat.h:21
combblas
Definition
CCGrid.h:4
time.h
Applications
SpGEMM3D.cpp
Generated by
1.9.8