forked from realstolz/polymer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConvertTmp.C
92 lines (87 loc) · 3.29 KB
/
ConvertTmp.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// This code is part of the project "Ligra: A Lightweight Graph Processing
// Framework for Shared Memory", presented at Principles and Practice of
// Parallel Programming, 2013.
// Copyright (c) 2013 Julian Shun and Guy Blelloch
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights (to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "ligra.h"
#include "gettime.h"
using namespace std;
struct BF_F {
intE* ShortestPathLen;
int* Visited;
BF_F(intE* _ShortestPathLen, int* _Visited) :
ShortestPathLen(_ShortestPathLen), Visited(_Visited) {}
inline bool update (intT s, intT d, intE edgeLen) { //Update ShortestPathLen if found a shorter path
intE newDist = ShortestPathLen[s] + edgeLen;
if(ShortestPathLen[d] > newDist) {
ShortestPathLen[d] = newDist;
if(Visited[d] == 0) { Visited[d] = 1 ; return 1;}
}
return 0;
}
inline bool updateAtomic (intT s, intT d, intE edgeLen){ //atomic Update
intE newDist = ShortestPathLen[s] + edgeLen;
return (writeMin(&ShortestPathLen[d],newDist) &&
CAS(&Visited[d],0,1));
}
inline bool cond (intT d) { return 1; } //does nothing
};
//reset visited vertices
struct BF_Vertex_F {
int* Visited;
BF_Vertex_F(int* _Visited) : Visited(_Visited) {}
inline bool operator() (intT i){
Visited[i] = 0;
return 1;
}
};
template <class vertex>
int* BellmanFord(intT start, wghGraph<vertex> GA) {
for (intT i = 0; i < GA.n; i++) {
if (GA.V[i].getOutDegree() + GA.V[i].getInDegree() <= 0)
continue;
for (intT j = 0; j < GA.V[i].getOutDegree(); j++) {
printf("%" PRIintT "\t%" PRIintT "\t%" PRIintE "\n", i, GA.V[i].getOutNeighbor(j), GA.V[i].getOutWeight(j));
}
}
return NULL;
}
int parallel_main(int argc, char* argv[]) {
char* iFile;
bool binary = false;
bool symmetric = false;
intT startPos = 0;
if(argc > 1) iFile = argv[1];
if(argc > 2) startPos = atoi(argv[2]);
if(argc > 3) if((string) argv[3] == (string) "-s") symmetric = true;
if(argc > 4) if((string) argv[4] == (string) "-b") binary = true;
if(symmetric) {
wghGraph<symmetricWghVertex> WG =
readWghGraph<symmetricWghVertex>(iFile,symmetric,binary);
BellmanFord((intT)startPos,WG);
WG.del();
} else {
wghGraph<asymmetricWghVertex> WG =
readWghGraph<asymmetricWghVertex>(iFile,symmetric,binary);
BellmanFord((intT)startPos,WG);
WG.del();
}
}