Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ebb488c

Browse files
updated pipeline
1 parent 4a39aee commit ebb488c

File tree

15 files changed

+1247
-29
lines changed

15 files changed

+1247
-29
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include "parallel_pipeline.hpp"
2+
#include <CLI11.hpp>
3+
4+
int main(int argc, char* argv[]) {
5+
6+
CLI::App app{"Parallel Pipeline"};
7+
8+
unsigned num_threads {1};
9+
app.add_option("-t,--num_threads", num_threads, "number of threads (default=1)");
10+
11+
unsigned num_rounds {1};
12+
app.add_option("-r,--num_rounds", num_rounds, "number of rounds (default=1)");
13+
14+
std::string model = "tf";
15+
app.add_option("-m,--model", model, "model name tbb|omp|tf (default=tf)")
16+
->check([] (const std::string& m) {
17+
if(m != "tbb" && m != "omp" && m != "tf") {
18+
return "model name should be \"tbb\", \"omp\", or \"tf\"";
19+
}
20+
return "";
21+
});
22+
23+
unsigned num_lines {8};
24+
app.add_option("-l,--num_lines", num_lines, "num of lines (default=8)");
25+
26+
std::string pipes = "ssssssss";
27+
app.add_option("-p,--pipes", pipes, "the chain of pipes (default=ssssssss)")
28+
->check([pipes] (const std::string& p) {
29+
if (p[0] == 'p') {
30+
return "the first pipe should be \"s\" (serial)";
31+
}
32+
else if (pipes.size() > 10) {
33+
return "no more than 10 pipes";
34+
}
35+
else if (pipes.size() == 0) {
36+
return "at least one pipe is required";
37+
}
38+
return "";
39+
});
40+
41+
CLI11_PARSE(app, argc, argv);
42+
43+
std::cout << "model=" << model << ' '
44+
<< "num_threads=" << num_threads << ' '
45+
<< "num_rounds=" << num_rounds << ' '
46+
<< "num_lines=" << num_lines << ' '
47+
<< "pipes=" << pipes << ' '
48+
<< std::endl;
49+
50+
std::cout << std::setw(12) << "size"
51+
<< std::setw(12) << "Runtime"
52+
<< '\n';
53+
54+
size_t log_length = 23;
55+
56+
for(size_t i = 1; i <= log_length; ++i) {
57+
58+
size_t L = 1 << i;
59+
60+
double runtime {0.0};
61+
62+
for(unsigned j = 0; j < num_rounds; ++j) {
63+
if(model == "tf") {
64+
runtime += measure_time_taskflow(pipes, num_lines, num_threads, L).count();
65+
}
66+
else if(model == "tbb") {
67+
runtime += measure_time_tbb(pipes, num_lines, num_threads, L).count();
68+
}
69+
else if(model == "omp") {
70+
runtime += measure_time_omp(pipes, num_lines, num_threads, L).count();
71+
}
72+
}
73+
74+
std::cout << std::setw(12) << L
75+
<< std::setw(12) << runtime / num_rounds / 1e3
76+
<< std::endl;
77+
}
78+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#include "parallel_pipeline.hpp"
2+
#include <omp.h>
3+
4+
// linear_chain_omp
5+
void linear_chain_omp(size_t length, unsigned num_threads) {
6+
7+
size_t counter = 0;
8+
size_t *D = new size_t [length];
9+
10+
#pragma omp parallel num_threads(num_threads)
11+
{
12+
#pragma omp single
13+
{
14+
for(size_t i=0; i<length; ++i) {
15+
16+
if(i==0) {
17+
#pragma omp task firstprivate(i) depend(out:D[i])
18+
{
19+
++counter;
20+
}
21+
}
22+
else {
23+
#pragma omp task firstprivate(i) depend(out:D[i]) depend(in:D[i-1])
24+
{
25+
++counter;
26+
}
27+
}
28+
}
29+
}
30+
}
31+
32+
assert(counter == length);
33+
34+
delete [] D;
35+
}
36+
37+
std::chrono::microseconds measure_time_omp(
38+
std::string pipes,
39+
unsigned length,
40+
unsigned num_threads,
41+
size_t size
42+
) {
43+
auto beg = std::chrono::high_resolution_clock::now();
44+
//linear_chain_omp(length, num_threads);
45+
auto end = std::chrono::high_resolution_clock::now();
46+
return std::chrono::duration_cast<std::chrono::microseconds>(end - beg);
47+
}
48+
49+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <chrono>
2+
#include <string>
3+
#include <cassert>
4+
5+
std::chrono::microseconds measure_time_taskflow(std::string, unsigned, unsigned, size_t);
6+
std::chrono::microseconds measure_time_tbb(std::string, unsigned, unsigned, size_t);
7+
std::chrono::microseconds measure_time_omp(std::string, unsigned, unsigned, size_t);
8+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <iostream>
2+
#include <chrono>
3+
4+
#include "levelgraph.hpp"
5+
6+
std::chrono::microseconds measure_time_seq(LevelGraph& graph){
7+
auto beg = std::chrono::high_resolution_clock::now();
8+
for(size_t l=0; l<graph.level(); l++){
9+
for(size_t i=0; i<graph.length(); i++){
10+
Node& n = graph.node_at(l, i);
11+
n.mark();
12+
}
13+
}
14+
auto end = std::chrono::high_resolution_clock::now();
15+
return std::chrono::duration_cast<std::chrono::microseconds>(end - beg);
16+
}

0 commit comments

Comments
 (0)