-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuts_shm.cpp
More file actions
103 lines (75 loc) · 2.43 KB
/
Copy pathuts_shm.cpp
File metadata and controls
103 lines (75 loc) · 2.43 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "uts.h"
#include <stack>
#include <iostream>
/*
* Generate all children of the parent
*/
template <typename datastructure>
static void genChildren(Node * parent, Node * child, datastructure &stack) {
int parentHeight = parent->height;
// can be called by multiple threads in parallel for different(!) nodes
int numChildren = uts_numChildren(parent);
// can be called by multiple threads in parallel for different(!) nodes
int childType = uts_childType(parent);
// record number of children in parent
parent->numChildren = numChildren;
// construct children and push in our data structure
if (numChildren > 0) {
child->type = childType;
child->height = parentHeight + 1;
for (int i = 0; i < numChildren; i++) {
for (int j = 0; j < getComputeGran(); j++) {
// can be called by multiple threads in parallel for different(!) nodes
rng_spawn(parent->state.state, child->state.state, i);
}
// store a copy auf *child in your data structure
stack.push(*child);
std::cout << "Added new child!" << std::endl;
}
}
}
/*
* parallel search of UTS trees using work stealing
*/
template <typename datastructure>
static void parTreeSearch(datastructure &stack) {
Node *parent;
Node child;
// init a child, we will reuse this again and again
initNode(&child);
/* local work */
while (!stack.empty()) {
// get an pointer to an element from our data structure
parent = &stack.top();
if (parent->numChildren < 0){
// first time visited, construct children and place on stack
genChildren(parent, &child, stack);
} else {
// remove the element from our data structure
stack.pop();
}
}
}
int main(int argc, char *argv[]) {
// parse parameter
uts_parseParams(argc, argv);
// show parameter
uts_printParams();
// init the root node of our work-tree
Node root;
uts_initRoot(&root);
// create our data structure
std::stack<Node> stack;
// add the root node to our data structure
stack.push(root);
// start our benchmark
parTreeSearch(stack);
// gather the following information during runtime and call this function
// nThreads = number of threads
// walltime = runtime of parTreeSearch
// nNodes = number of nodes of the tree
// nLeaves = number of leaves of the tree, that is number of children == 0
// maxDepth = maximal depth of the tree
// uts_showStats(int nThreads, double walltime, unsigned long nNodes, unsigned long nLeaves, unsigned long maxDepth)
return 0;
}