Skip to content

Commit 276601b

Browse files
committed
unite binaries
1 parent 7d671e0 commit 276601b

5 files changed

Lines changed: 162 additions & 65 deletions

File tree

tasks/CMakeLists.txt

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,65 @@
11
message(STATUS "Student's tasks")
22

3-
set(list_of_reverts "")
3+
project("parallel_programming_course")
4+
set(exec_func_tests "ppc_func_tests")
5+
set(exec_perf_tests "ppc_perf_tests")
6+
7+
# Init func tests executable files
8+
set(list_of_exec_tests "")
9+
if (USE_FUNC_TESTS)
10+
add_executable(${exec_func_tests} "${CMAKE_CURRENT_SOURCE_DIR}/func_runner/runner.cpp")
11+
list(APPEND list_of_exec_tests ${exec_func_tests})
12+
endif (USE_FUNC_TESTS)
13+
14+
# Init perf tests executable files
15+
if (USE_PERF_TESTS)
16+
add_executable(${exec_perf_tests} "${CMAKE_CURRENT_SOURCE_DIR}/perf_runner/runner.cpp")
17+
list(APPEND list_of_exec_tests ${exec_perf_tests})
18+
endif (USE_PERF_TESTS)
419

520
SUBDIRLIST(subdirs ${CMAKE_CURRENT_LIST_DIR})
621
foreach(subd ${subdirs})
22+
if ((subd STREQUAL "func_runner") OR (subd STREQUAL "perf_runner"))
23+
continue()
24+
endif ()
725
add_subdirectory(${subd})
8-
foreach (dir_type "all" "mpi" "omp" "seq" "stl" "tbb")
9-
set(base_dir "${CMAKE_CURRENT_SOURCE_DIR}/${subd}/${dir_type}_disabled")
10-
if (NOT EXISTS "${base_dir}")
11-
continue()
12-
else ()
13-
list(APPEND list_of_reverts "${subd}_${dir_type}")
14-
endif ()
15-
endforeach ()
1626
endforeach()
1727

18-
set(output_file "${CMAKE_BINARY_DIR}/revert-list.txt")
19-
file(WRITE ${output_file} "${CONTENT}")
20-
message(STATUS "Revert list")
21-
foreach (dir_name ${list_of_reverts})
22-
message(STATUS "-- ${dir_name}")
23-
file(APPEND ${output_file} "${dir_name}\n")
24-
endforeach()
28+
# Link 3rdparty libraries
29+
add_library(stb_image INTERFACE)
30+
31+
foreach (exec_func ${list_of_exec_tests})
32+
target_link_libraries(${exec_func} PUBLIC Threads::Threads)
33+
target_link_libraries(${exec_func} PUBLIC ${OpenMP_libomp_LIBRARY})
34+
if( MPI_COMPILE_FLAGS )
35+
set_target_properties(${exec_func} PROPERTIES COMPILE_FLAGS "${MPI_COMPILE_FLAGS}")
36+
endif( MPI_COMPILE_FLAGS )
37+
38+
if( MPI_LINK_FLAGS )
39+
set_target_properties(${exec_func} PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
40+
endif( MPI_LINK_FLAGS )
41+
target_link_libraries(${exec_func} PUBLIC ${MPI_LIBRARIES})
42+
43+
add_dependencies(${exec_func} ppc_onetbb)
44+
target_link_directories(${exec_func} PUBLIC ${CMAKE_BINARY_DIR}/ppc_onetbb/install/lib)
45+
if(NOT MSVC)
46+
target_link_libraries(${exec_func} PUBLIC tbb)
47+
endif()
48+
49+
target_link_directories(stb_image INTERFACE ${CMAKE_SOURCE_DIR}/3rdparty/stb)
50+
target_link_libraries(${exec_func} PUBLIC stb_image)
51+
52+
add_dependencies(${exec_func} ppc_googletest)
53+
target_link_directories(${exec_func} PUBLIC "${CMAKE_BINARY_DIR}/ppc_googletest/install/lib")
54+
target_link_libraries(${exec_func} PUBLIC gtest gtest_main)
55+
enable_testing()
56+
add_test(NAME ${exec_func} COMMAND ${exec_func})
57+
58+
# Install the executable
59+
install(TARGETS ${exec_func} RUNTIME DESTINATION bin)
60+
endforeach ()
61+
62+
# Install the library
63+
install(TARGETS ${name_lib} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib)
2564

2665
add_compile_definitions(PATH_TO_PPC_PROJECT="${CMAKE_SOURCE_DIR}")

tasks/example/CMakeLists.txt

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
# Print student task name
2-
get_filename_component(TASK_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
3-
message(STATUS "-- ${TASK_NAME}")
4-
51
# Init project
6-
project(${TASK_NAME})
7-
set(exec_func_tests "${TASK_NAME}_func_tests")
8-
set(exec_perf_tests "${TASK_NAME}_perf_tests")
2+
project("parallel_programming_course")
3+
set(exec_func_tests "ppc_func_tests")
4+
set(exec_perf_tests "ppc_perf_tests")
95
set(test_base_dir "${CMAKE_CURRENT_SOURCE_DIR}/tests")
106

117
# Init func tests executable files
128
set(list_of_exec_tests "")
139
if (USE_FUNC_TESTS)
1410
file(GLOB_RECURSE func_tests_source_files "${test_base_dir}/func_tests/*")
15-
add_executable(${exec_func_tests} ${func_tests_source_files} "${test_base_dir}/runner.cpp")
11+
target_sources(${exec_func_tests} PRIVATE ${func_tests_source_files})
1612
list(APPEND list_of_exec_tests ${exec_func_tests})
1713
endif (USE_FUNC_TESTS)
1814

1915
# Init perf tests executable files
2016
if (USE_PERF_TESTS)
2117
file(GLOB_RECURSE perf_tests_source_files "${test_base_dir}/perf_tests/*")
22-
add_executable(${exec_perf_tests} ${perf_tests_source_files} "${test_base_dir}/runner.cpp")
18+
target_sources(${exec_perf_tests} PRIVATE ${perf_tests_source_files})
2319
list(APPEND list_of_exec_tests ${exec_perf_tests})
2420
endif (USE_PERF_TESTS)
2521

22+
# Print student task name
23+
get_filename_component(TASK_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
24+
message(STATUS "-- ${TASK_NAME}")
25+
2626
# Create lib
2727
foreach (dir_type "all" "mpi" "omp" "seq" "stl" "tbb")
2828
# Check directory existing
@@ -46,45 +46,10 @@ foreach (dir_type "all" "mpi" "omp" "seq" "stl" "tbb")
4646
add_library(${name_lib} STATIC ${lib_source_files})
4747
endif()
4848
set_target_properties(${name_lib} PROPERTIES LINKER_LANGUAGE CXX)
49+
target_link_libraries(${name_lib} PUBLIC core_module_lib)
4950

5051
# Link core library
51-
target_link_libraries(${exec_func_tests} PUBLIC ${name_lib} core_module_lib)
52-
target_link_libraries(${exec_perf_tests} PUBLIC ${name_lib} core_module_lib)
53-
endforeach ()
54-
55-
# Link 3rdparty libraries
56-
add_library(stb_image INTERFACE)
57-
58-
foreach (exec_func ${list_of_exec_tests})
59-
target_link_libraries(${exec_func} PUBLIC Threads::Threads)
60-
target_link_libraries(${exec_func} PUBLIC ${OpenMP_libomp_LIBRARY})
61-
if( MPI_COMPILE_FLAGS )
62-
set_target_properties(${exec_func} PROPERTIES COMPILE_FLAGS "${MPI_COMPILE_FLAGS}")
63-
endif( MPI_COMPILE_FLAGS )
64-
65-
if( MPI_LINK_FLAGS )
66-
set_target_properties(${exec_func} PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}")
67-
endif( MPI_LINK_FLAGS )
68-
target_link_libraries(${exec_func} PUBLIC ${MPI_LIBRARIES})
69-
70-
add_dependencies(${exec_func} ppc_onetbb)
71-
target_link_directories(${exec_func} PUBLIC ${CMAKE_BINARY_DIR}/ppc_onetbb/install/lib)
72-
if(NOT MSVC)
73-
target_link_libraries(${exec_func} PUBLIC tbb)
74-
endif()
75-
76-
target_link_directories(stb_image INTERFACE ${CMAKE_SOURCE_DIR}/3rdparty/stb)
77-
target_link_libraries(${exec_func} PUBLIC stb_image)
78-
79-
add_dependencies(${exec_func} ppc_googletest)
80-
target_link_directories(${exec_func} PUBLIC "${CMAKE_BINARY_DIR}/ppc_googletest/install/lib")
81-
target_link_libraries(${exec_func} PUBLIC gtest gtest_main)
82-
enable_testing()
83-
add_test(NAME ${exec_func} COMMAND ${exec_func})
84-
85-
# Install the executable
86-
install(TARGETS ${exec_func} RUNTIME DESTINATION bin)
52+
foreach (exec_func ${list_of_exec_tests})
53+
target_link_libraries(${exec_func} PUBLIC ${name_lib})
54+
endforeach ()
8755
endforeach ()
88-
89-
# Install the library
90-
install(TARGETS ${name_lib} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib)

tasks/example/tests/func_tests/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class NesterovARunFuncTests : public ::testing::TestWithParam<TestParam> {
2222
protected:
2323
void SetUp() override {
2424
// Read image
25-
std::string abs_path = ppc::util::GetAbsolutePath("all/example/data/pic_all.jpg");
25+
std::string abs_path = ppc::util::GetAbsolutePath("example/tests/data/pic_all.jpg");
2626
data = stbi_load(abs_path.c_str(), &width, &height, &channels, 0);
2727
ASSERT_TRUE(data != nullptr) << "Failed to load image: " << stbi_failure_reason();
2828
img = std::vector<uint8_t>(data, data + (width * height * channels));

tasks/perf_runner/runner.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#include <gtest/gtest.h>
2+
#include <mpi.h>
3+
4+
#include <cstdio>
5+
#include <cstdlib>
6+
#include <memory>
7+
#include <string>
8+
#include <utility>
9+
10+
#include "core/util/include/util.hpp"
11+
#include "oneapi/tbb/global_control.h"
12+
13+
class UnreadMessagesDetector : public ::testing::EmptyTestEventListener {
14+
public:
15+
UnreadMessagesDetector() = default;
16+
17+
void OnTestEnd(const ::testing::TestInfo& /*test_info*/) override {
18+
int rank = -1;
19+
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
20+
21+
MPI_Barrier(MPI_COMM_WORLD);
22+
23+
int flag = -1;
24+
MPI_Status status;
25+
26+
MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, &status);
27+
28+
if (flag != 0) {
29+
fprintf(
30+
stderr,
31+
"[ PROCESS %d ] [ FAILED ] %s.%s: MPI message queue has an unread message from process %d with tag %d\n",
32+
rank, "test_suite_name", "test_name", status.MPI_SOURCE, status.MPI_TAG);
33+
MPI_Finalize();
34+
exit(2);
35+
}
36+
37+
MPI_Barrier(MPI_COMM_WORLD);
38+
}
39+
40+
private:
41+
};
42+
43+
class WorkerTestFailurePrinter : public ::testing::EmptyTestEventListener {
44+
public:
45+
explicit WorkerTestFailurePrinter(std::shared_ptr<::testing::TestEventListener> base) : base_(std::move(base)) {}
46+
47+
void OnTestEnd(const ::testing::TestInfo& test_info) override {
48+
if (test_info.result()->Passed()) {
49+
return;
50+
}
51+
PrintProcessRank();
52+
base_->OnTestEnd(test_info);
53+
}
54+
55+
void OnTestPartResult(const ::testing::TestPartResult& test_part_result) override {
56+
if (test_part_result.passed() || test_part_result.skipped()) {
57+
return;
58+
}
59+
PrintProcessRank();
60+
base_->OnTestPartResult(test_part_result);
61+
}
62+
63+
private:
64+
static void PrintProcessRank() {
65+
int rank = -1;
66+
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
67+
printf(" [ PROCESS %d ] ", rank);
68+
}
69+
70+
std::shared_ptr<::testing::TestEventListener> base_;
71+
};
72+
73+
int main(int argc, char** argv) {
74+
MPI_Init(&argc, &argv);
75+
76+
// Limit the number of threads in TBB
77+
tbb::global_control control(tbb::global_control::max_allowed_parallelism, ppc::util::GetPPCNumThreads());
78+
79+
::testing::InitGoogleTest(&argc, argv);
80+
81+
auto& listeners = ::testing::UnitTest::GetInstance()->listeners();
82+
int rank = -1;
83+
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
84+
if (rank != 0 && (argc < 2 || argv[1] != std::string("--print-workers"))) {
85+
auto* listener = listeners.Release(listeners.default_result_printer());
86+
listeners.Append(new WorkerTestFailurePrinter(std::shared_ptr<::testing::TestEventListener>(listener)));
87+
}
88+
listeners.Append(new UnreadMessagesDetector());
89+
auto status = RUN_ALL_TESTS();
90+
91+
MPI_Finalize();
92+
return status;
93+
}

0 commit comments

Comments
 (0)