-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseq.cpp
More file actions
82 lines (72 loc) · 2.22 KB
/
seq.cpp
File metadata and controls
82 lines (72 loc) · 2.22 KB
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
#include <queue>
#include <fstream>
#include <sstream>
#include <iostream>
#include <semaphore.h>
#include "utils.cpp"
#include "utimer.cpp"
#include <unistd.h>
using namespace std;
int occurancesX = 0;
int s;
int X;
int num_nodes = 100;
int min_edges_per_node = 1;
int max_edges_per_node = 5;
int main(int argc, char** argv) {
s = atoi(argv[1]); // We get the source nodeID
X = atoi(argv[2]); // We get the value to compute the occurancesX of
if(argc == 6) {
num_nodes = atoi(argv[3]); // We get the number of nodes to be generated
min_edges_per_node = atoi(argv[4]); // We get the minimum number of edges per node
max_edges_per_node = atoi(argv[5]); // We get the maximum number of edges per node
}
auto filename = "data/graphs/" + to_string(num_nodes) + "_" + to_string(min_edges_per_node) + "_" + to_string(max_edges_per_node) + ".txt";
printf ("SEQCPP:%d:%d:%d\n", num_nodes, min_edges_per_node, max_edges_per_node);
Graph<int> g;
{ utimer tpg("Graph");
processGraph(&g, filename);
}
{ utimer tsbfs("SERIAL_TIME");
vector<bool> visited(num_nodes, false);
queue< Node<int> > q;
Node<int> current;
q.push(g.getNode(s));
visited[s] = true;
while (!q.empty())
{
#ifdef WITHTIME
{ utimer tpg("Time 1 while loop");
#endif
current = q.front();
q.pop();
#ifdef WAIT
usleep(5000);
#endif
#ifdef WITHTIME
{ utimer tpg("Time to check X update");
#endif
if (current.getVal() == X) {
occurancesX++;
}
#ifdef WITHTIME
}
#endif
vector<Edge> outboundEdges = current.getOutboundEdges();
#ifdef WITHTIME
{ utimer tpg("Time for edges");
#endif
for (long unsigned int i = 0; i < outboundEdges.size(); ++i) {
if (!visited[outboundEdges[i].getDestID()]) {
q.push(g.getNode(outboundEdges[i].getDestID()));
visited[outboundEdges[i].getDestID()] = true;
}
}
#ifdef WITHTIME
}
#endif
}
}
printf ("X = %d has %d instances \n", X, occurancesX);
return 0;
}