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