COMBINATORIAL_BLAS
1.6
Loading...
Searching...
No Matches
ReduceTest.cpp
Go to the documentation of this file.
1
/****************************************************************/
2
/* Parallel Combinatorial BLAS Library (for Graph Computations) */
3
/* version 1.6 -------------------------------------------------*/
4
/* date: 11/15/2016 --------------------------------------------*/
5
/* authors: Ariful Azad, Aydin Buluc, Adam Lugowski ------------*/
6
/****************************************************************/
7
/*
8
Copyright (c) 2010-2016, 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
38
using namespace
std;
39
using namespace
combblas
;
40
41
// Simple helper class for declarations: Just the numerical type is templated
42
// The index type and the sequential matrix type stays the same for the whole code
43
// In this case, they are "int" and "SpDCCols"
44
template
<
class
NT>
45
class
PSpMat
46
{
47
public
:
48
typedef
SpDCCols < int, NT >
DCCols
;
49
typedef
SpParMat < int, NT, DCCols >
MPI_DCCols
;
50
};
51
52
int
main
(
int
argc
,
char
*
argv
[])
53
{
54
int
nprocs
, myrank;
55
MPI_Init
(&
argc
, &
argv
);
56
MPI_Comm_size
(
MPI_COMM_WORLD
,&
nprocs
);
57
MPI_Comm_rank
(
MPI_COMM_WORLD
,&myrank);
58
59
if
(
argc
< 4)
60
{
61
if
(myrank == 0)
62
{
63
cout
<<
"Usage: ./ReduceTest <MatrixA> <SumColumns> <SumRows>"
<<
endl
;
64
cout
<<
"<Matrix>,<SumColumns>,<SumRows> are absolute addresses, and files should be in triples format"
<<
endl
;
65
}
66
MPI_Finalize
();
67
return
-1;
68
}
69
{
70
string
Aname
(
argv
[1]);
71
string
Bname
(
argv
[2]);
72
string
Cname
(
argv
[3]);
73
74
ifstream
inputB
(
Bname
.c_str());
75
ifstream
inputC
(
Cname
.c_str());
76
MPI_Barrier
(
MPI_COMM_WORLD
);
77
78
shared_ptr<CommGrid>
fullWorld
;
79
fullWorld
.reset(
new
CommGrid
(
MPI_COMM_WORLD
, 0, 0) );
80
81
PSpMat<double>::MPI_DCCols
A
(
fullWorld
);
82
FullyDistVec<int,double>
colsums
(
A
.getcommgrid());
83
FullyDistVec<int,double>
rowsums
(
A
.getcommgrid());
84
85
A
.ReadDistribute(
Aname
, 0);
86
colsums
.ReadDistribute(
inputB
, 0);
87
rowsums
.ReadDistribute(
inputC
, 0);
88
89
FullyDistVec< int, double >
rowsums_control
(
fullWorld
);
90
FullyDistVec< int, double >
colsums_control
(
fullWorld
);
91
A
.Reduce(
rowsums_control
,
Row
, std::plus<double>() , 0.0);
92
A
.Reduce(
colsums_control
,
Column
, std::plus<double>() , 0.0);
93
94
if
(
rowsums_control
==
rowsums
&&
colsums_control
==
colsums
)
95
{
96
SpParHelper::Print
(
"Reduction via summation working correctly\n"
);
97
}
98
else
99
{
100
SpParHelper::Print
(
"ERROR in Reduce via summation, go fix it!\n"
);
101
}
102
103
inputB
.clear();
104
inputB
.close();
105
inputC
.clear();
106
inputC
.close();
107
}
108
MPI_Finalize
();
109
return
0;
110
}
111
112
main
int main()
Definition
Driver.cpp:12
PSpMat
Definition
BcastTest.cpp:35
PSpMat::MPI_DCCols
SpParMat< int, NT, DCCols > MPI_DCCols
Definition
ReduceTest.cpp:49
PSpMat::DCCols
SpDCCols< int, NT > DCCols
Definition
ReduceTest.cpp:48
combblas::CommGrid
Definition
CommGrid.h:45
combblas::DistEdgeList
Definition
DistEdgeList.h:82
combblas::SpParHelper::Print
static void Print(const std::string &s)
Definition
SpParHelper.cpp:836
nprocs
int nprocs
Definition
comms.cpp:55
combblas
Definition
CCGrid.h:4
combblas::Column
@ Column
Definition
SpDefs.h:115
combblas::Row
@ Row
Definition
SpDefs.h:116
A
double A
time.h
ReleaseTests
ReduceTest.cpp
Generated by
1.9.8