Skip to content

Commit ff1b8bf

Browse files
committed
Add dynamic parallel for and benchmarks
1 parent 272fea3 commit ff1b8bf

File tree

17 files changed

+2039
-0
lines changed

17 files changed

+2039
-0
lines changed

CMakeLists.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ include(${TBB_ROOT}/cmake/TBBBuild.cmake)
320320
tbb_build(TBB_ROOT ${TBB_ROOT} CONFIG_DIR TBB_DIR MAKE_ARGS tbb_cpf=1)
321321
find_package(TBB REQUIRED tbb_preview)
322322

323+
323324
## benchmark 1: wavefront computing
324325
message(STATUS "benchmark 1: wavefront")
325326
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${TF_BENCHMARK_DIR}/wavefront)
@@ -536,6 +537,51 @@ target_link_libraries(
536537
)
537538
set_target_properties(strassen PROPERTIES COMPILE_FLAGS ${OpenMP_CXX_FLAGS})
538539

540+
### benchmark 11: imbalance for-loop
541+
#message(STATUS "benchmark 11: imbalance for-loop")
542+
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${TF_BENCHMARK_DIR}/imbalance_for)
543+
#add_executable(
544+
# imbalance_for
545+
# ${TF_BENCHMARK_DIR}/imbalance_for/main.cpp
546+
# ${TF_BENCHMARK_DIR}/imbalance_for/omp.cpp
547+
# ${TF_BENCHMARK_DIR}/imbalance_for/tbb.cpp
548+
# ${TF_BENCHMARK_DIR}/imbalance_for/taskflow.cpp
549+
# ${TF_BENCHMARK_DIR}/imbalance_for/mmio.cpp
550+
#)
551+
#target_include_directories(imbalance_for PRIVATE ${PROJECT_SOURCE_DIR}/3rd-party/CLI11)
552+
#target_link_libraries(
553+
# imbalance_for
554+
# ${PROJECT_NAME}
555+
# Threads::Threads
556+
# ${TBB_IMPORTED_TARGETS}
557+
# ${OpenMP_CXX_LIBRARIES}
558+
# tf::default_settings
559+
#)
560+
#set_target_properties(imbalance_for PROPERTIES COMPILE_FLAGS ${OpenMP_CXX_FLAGS})
561+
#
562+
### benchmark 12: LavaMD
563+
#message(STATUS "benchmark 12: LavaMD")
564+
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${TF_BENCHMARK_DIR}/lavamd)
565+
#add_executable(
566+
# lavamd
567+
# ${TF_BENCHMARK_DIR}/lavamd/main.cpp
568+
# ${TF_BENCHMARK_DIR}/lavamd/omp.cpp
569+
# ${TF_BENCHMARK_DIR}/lavamd/tbb.cpp
570+
# ${TF_BENCHMARK_DIR}/lavamd/taskflow.cpp
571+
#)
572+
#target_include_directories(lavamd PRIVATE ${PROJECT_SOURCE_DIR}/3rd-party/CLI11)
573+
#target_link_libraries(
574+
# lavamd
575+
# ${PROJECT_NAME}
576+
# Threads::Threads
577+
# ${TBB_IMPORTED_TARGETS}
578+
# ${OpenMP_CXX_LIBRARIES}
579+
# tf::default_settings
580+
#)
581+
#set_target_properties(lavamd PROPERTIES COMPILE_FLAGS ${OpenMP_CXX_FLAGS})
582+
583+
584+
539585
endif()
540586

541587
# -----------------------------------------------------------------------------
15.2 MB
Binary file not shown.

benchmark/imbalance_for/main.cpp

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include <CLI11.hpp>
2+
#include "sparse.hpp"
3+
4+
void imbalance(
5+
const std::string& model,
6+
const unsigned num_threads,
7+
const unsigned num_rounds
8+
) {
9+
10+
double runtime {0.0};
11+
12+
std::string fname {"TF19.mtx"};
13+
read_matrix(fname.data());
14+
toCSR();
15+
16+
for(unsigned j=0; j<num_rounds; ++j) {
17+
if(model == "tf") {
18+
runtime += measure_time_taskflow(num_threads).count();
19+
}
20+
else if(model == "tbb") {
21+
runtime += measure_time_tbb(num_threads).count();
22+
}
23+
else if(model == "omp") {
24+
runtime += measure_time_omp(num_threads).count();
25+
}
26+
else assert(false);
27+
}
28+
29+
clear();
30+
31+
std::cout << std::setw(12) << runtime / num_rounds / 1e3
32+
<< std::endl;
33+
}
34+
35+
int main(int argc, char* argv[]) {
36+
37+
CLI::App app{"Imbalance workload using number of non-zeros in sparse matrix"};
38+
39+
unsigned num_threads {1};
40+
app.add_option("-t,--num_threads", num_threads, "number of threads (default=1)");
41+
42+
unsigned num_rounds {1};
43+
app.add_option("-r,--num_rounds", num_rounds, "number of rounds (default=1)");
44+
45+
std::string model = "tf";
46+
app.add_option("-m,--model", model, "model name tbb|omp|tf (default=tf)")
47+
->check([] (const std::string& m) {
48+
if(m != "tbb" && m != "tf" && m != "omp") {
49+
return "model name should be \"tbb\", \"omp\", or \"tf\"";
50+
}
51+
return "";
52+
});
53+
54+
CLI11_PARSE(app, argc, argv);
55+
56+
std::cout << "model=" << model << ' '
57+
<< "num_threads=" << num_threads << ' '
58+
<< "num_rounds=" << num_rounds << ' '
59+
<< std::endl;
60+
61+
if(std::ifstream input("./TF19.mtx"); !input.good()) {
62+
std::cout << "Please unzip the file TF19.mtx.zip first!\n";
63+
return 0;
64+
}
65+
66+
imbalance(model, num_threads, num_rounds);
67+
}

0 commit comments

Comments
 (0)