COMBINATORIAL_BLAS 1.6
 
Loading...
Searching...
No Matches
ssp.cpp
Go to the documentation of this file.
1#include <mpi.h>
2#include <sys/time.h>
3#include <iostream>
4#include <stdio.h>
5#include <functional>
6#include <algorithm>
7#include <vector>
8#include <sstream>
9#include <ctime>
10
11#include "../../trunk/CombBLAS/CombBLAS.h"
12
13#include "Node.h"
14
15using namespace std;
16
17class BinaryOp {
18 public:
20 if (a.dist >= b.dist)
21 return Node(b);
22 else
23 return Node(a);
24 }
25};
26
27class DoOp {
28 public:
29 bool operator() (Node a, Node b) {
30 if (a.dist >= b.dist)
31 return false;
32 else
33 return true;
34 }
35};
36
37int main(int argc, char* argv[])
38{
39 MPI::Init(argc, argv);
40 int nprocs = MPI::COMM_WORLD.Get_size();
41 int myrank = MPI::COMM_WORLD.Get_rank();
42 extern MPI_Op staticMPIop;
43
44 {
45 // int id, double dist, int parent
46 MPI::Datatype types[3] = {MPI::INT, MPI::DOUBLE, MPI::INT};
47 int lengths[3] = {1, 1, 1};
48 Node n;
49 MPI::Aint disp[3];
50 disp[0] = MPI::Get_address(&n.id) - MPI::Get_address(&n);
51 disp[1] = MPI::Get_address(&n.dist) - MPI::Get_address(&n);
52 disp[2] = MPI::Get_address(&n.parent) - MPI::Get_address(&n);
53
54 Node_MPI_datatype = MPI::Datatype::Create_struct(3, lengths, disp, types);
55 Node_MPI_datatype.Commit();
56 MPI_Op_create(apply, true , &staticMPIop);
57 }
58
59 {
60 if (argc != 4) {
61 cout << endl << "Require 3 args..." << endl <<
62 "fileName startV testV" << endl;
63 MPI::Finalize();
64 return -1;
65 }
66
67 char* fileName = argv[1];
68 stringstream sstr(argv[2]);
69 int startVert;
70 sstr >> startVert;
71 stringstream sstr2(argv[3]);
72 int testVert;
73 sstr2 >> testVert;
74
75 if (myrank == 0)
76 cout << "startV: " << startVert << endl;
77
78 MPI::COMM_WORLD.Barrier();
79
80 // the graph
81 SpParMat<int, double, SpDCCols <int, double> > G;
82 G.ReadDistribute(fileName, 0);
83 int numVerts = G.getncol();
84 if (myrank == 0)
85 cout << "numVerts: " << numVerts << endl;
86
87 if (startVert > numVerts || startVert <= 0) {
88 cout << "Invalid start vertex id." << endl;
89 return -1;
90 }
91
92 G.Transpose();
93 Node zero(double(0), -1);
94
95 time_t startTime, endTime;
96 double elapsedTime;
97 if (myrank == 0) {
98 startTime = time(NULL);
99 cout << "start computing" << endl;
100 }
101
102 int iteration;
103 bool finished = false;
104
105 FullyDistVec<int, Node> result(G.getcommgrid(), G.getncol(), Node());
106 FullyDistSpVec<int, Node> frontier(G.getcommgrid(), G.getncol());
107
108 frontier.SetElement(startVert - 1, zero);
109 frontier.setNumToInd();
110
111 BinaryOp binaryOp;
112 DoOp doOp;
113
114 frontier = EWiseApply<Node>(frontier, result, binaryOp, doOp, false, Node());
115 result.EWiseApply(frontier, binaryOp, false, Node());
116
117 for(iteration = 1; iteration < numVerts; iteration++) {
118 frontier = SpMV<SPSRing>(G, frontier);
119 frontier.setNumToInd();
120 frontier = EWiseApply<Node>(frontier, result, binaryOp, doOp, false, Node());
121 if (frontier.getnnz() == 0) {
122 finished = true;
123 break;
124 }
125 result.EWiseApply(frontier, binaryOp, false, Node());
126 }
127
128 Node res = result[testVert - 1];
129 if (myrank == 0) {
130 endTime = time(NULL);
131 elapsedTime = difftime(endTime, startTime);
132 if(finished) {
133 cout << "finished" << endl;
134 cout << res << endl;
135 } else {
136 cout << "negative loop" << endl;
137 }
138 cout << "number of iterations: " << iteration << endl;
139 cout << "running time: " << elapsedTime << "s" << endl;
140 }
141 // G.Transpose();
142 }
143
144 MPI::Finalize();
145 return 0;
146}
147
int main()
Definition Driver.cpp:12
Node operator()(Node a, Node b)
Definition ssp.cpp:19
Definition ssp.cpp:27
bool operator()(Node a, Node b)
Definition ssp.cpp:29
int nprocs
Definition comms.cpp:55
MPI::Datatype Node_MPI_datatype
Definition Node.h:91
MPI_Op staticMPIop
Definition Node.h:12
void apply(void *invec, void *inoutvec, int *len, MPI_Datatype *datatype)
Definition Node.h:109
Definition Node.h:14
int parent
Definition Node.h:17
int id
Definition Node.h:15
double dist
Definition Node.h:16