Skip to content

Commit 0da828b

Browse files
committed
Remove PPC_ASAN_RUN logic and simplify build/test configurations
Eliminated `PPC_ASAN_RUN` handling across the codebase and adjusted macros, CMake configurations, and test files accordingly. Simplified thread environment handling, replaced `std::println` with `fmt` library calls, and refactored redundant code in utils and runners.
1 parent ba8011a commit 0da828b

17 files changed

Lines changed: 79 additions & 150 deletions

File tree

cmake/configure.cmake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ if (APPLE)
66
set(CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG TRUE)
77
endif(APPLE)
88

9-
if(DEFINED ENV{PPC_ASAN_RUN} AND "$ENV{PPC_ASAN_RUN}" STREQUAL "1")
10-
add_compile_definitions(USE_ASAN)
11-
endif()
12-
139
if (NOT CMAKE_BUILD_TYPE)
1410
set(CMAKE_BUILD_TYPE "Release")
1511
endif(NOT CMAKE_BUILD_TYPE)

cmake/json.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ExternalProject_Add(ppc_json
66
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/ppc_json/build"
77
INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/ppc_json/install"
88
CONFIGURE_COMMAND "${CMAKE_COMMAND}" -S "${CMAKE_SOURCE_DIR}/3rdparty/json/" -B "${CMAKE_CURRENT_BINARY_DIR}/ppc_json/build/"
9-
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -G${CMAKE_GENERATOR} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
9+
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -G${CMAKE_GENERATOR} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
1010
-D CMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER} -D CMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
1111
BUILD_COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_CURRENT_BINARY_DIR}/ppc_json/build" --config ${CMAKE_BUILD_TYPE} --parallel
1212
INSTALL_COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_CURRENT_BINARY_DIR}/ppc_json/build" --prefix "${CMAKE_CURRENT_BINARY_DIR}/ppc_json/install")

cmake/libenvpp.cmake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
include_directories(${CMAKE_SOURCE_DIR}/3rdparty/libenvpp/include)
2-
include_directories(${CMAKE_SOURCE_DIR}/3rdparty/libenvpp/external/fmt/include)
2+
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/3rdparty/libenvpp/external/fmt/include)
33

44
include(ExternalProject)
55
ExternalProject_Add(ppc_libenvpp
@@ -8,7 +8,7 @@ ExternalProject_Add(ppc_libenvpp
88
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/ppc_libenvpp/build"
99
INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/ppc_libenvpp/install"
1010
CONFIGURE_COMMAND "${CMAKE_COMMAND}" -S "${CMAKE_SOURCE_DIR}/3rdparty/libenvpp/" -B "${CMAKE_CURRENT_BINARY_DIR}/ppc_libenvpp/build/"
11-
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -G${CMAKE_GENERATOR} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
12-
-D CMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER} -D CMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
11+
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -G${CMAKE_GENERATOR} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
12+
-D CMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER} -D CMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} -DCMAKE_CXX_FLAGS=-Wno-error=switch-enum
1313
BUILD_COMMAND "${CMAKE_COMMAND}" --build "${CMAKE_CURRENT_BINARY_DIR}/ppc_libenvpp/build" --config ${CMAKE_BUILD_TYPE} --parallel
1414
INSTALL_COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_CURRENT_BINARY_DIR}/ppc_libenvpp/build" --prefix "${CMAKE_CURRENT_BINARY_DIR}/ppc_libenvpp/install")

modules/core/task/include/task.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ class Task {
108108
void SetTypeOfTask(TypeOfTask type_of_task) { type_of_task_ = type_of_task; }
109109

110110
// get a dynamic type of task
111-
TypeOfTask GetDynamicTypeOfTask() { return type_of_task_; }
111+
[[nodiscard]] TypeOfTask GetDynamicTypeOfTask() const { return type_of_task_; }
112112

113113
// get a dynamic type of task
114-
StatusOfTask GetStatusOfTask() { return status_of_task_; }
114+
[[nodiscard]] StatusOfTask GetStatusOfTask() const { return status_of_task_; }
115115

116116
// get a static type of task
117117
static constexpr TypeOfTask GetStaticTypeOfTask() { return TypeOfTask::kUnknown; }

modules/core/util/include/func_test_util.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ class BaseRunFuncTests : public ::testing::TestWithParam<FuncTestParam<InType, O
5151
GTEST_SKIP();
5252
}
5353

54+
auto which_task = [&](const std::string& substring) {
55+
return std::get<GTestParamIndex::kNameTest>(test_param).find(substring) != std::string::npos;
56+
};
57+
58+
if (!ppc::util::IsUnderMpirun() && (which_task("_all") || which_task("_mpi"))) {
59+
std::cerr << "kALL and kMPI tasks are not under mpirun" << '\n';
60+
GTEST_SKIP();
61+
}
62+
5463
task_ = std::get<GTestParamIndex::kTaskGetter>(test_param)(GetTestInputData());
5564
ASSERT_TRUE(task_->Validation());
5665
ASSERT_TRUE(task_->PreProcessing());
@@ -91,7 +100,7 @@ auto ExpandToValues(const Tuple& t) {
91100

92101
#define ADD_FUNC_TASK_THREADS(TASK) TaskListGenerator<TASK>()
93102

94-
#ifndef PPC_ASAN_RUN
103+
#if 1
95104
#define ADD_FUNC_TASK_PROCESS(TASK) TaskListGenerator<TASK>()
96105
#else
97106
#define ADD_FUNC_TASK_PROCESS(TASK) std::tuple<>()

modules/core/util/include/perf_test_util.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,11 @@ class BaseRunPerfTests : public ::testing::TestWithParam<PerfTestParam<InType, O
7979
throw std::runtime_error(err_msg.str().c_str());
8080
}
8181

82-
#ifndef PPC_ASAN_RUN
8382
int rank = -1;
8483
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
8584
if (rank == 0) {
8685
perf.PrintPerfStatistic(test_name);
8786
}
88-
#else
89-
perf.PrintPerfStatistic(test_name);
90-
#endif
9187

9288
OutType output_data = task_->GetOutput();
9389
ASSERT_TRUE(CheckTestOutputData(output_data));
@@ -118,7 +114,7 @@ auto TupleToGTestValues(Tuple&& tup) {
118114
return TupleToGTestValuesImpl(std::forward<Tuple>(tup), std::make_index_sequence<size>{});
119115
}
120116

121-
#ifndef PPC_ASAN_RUN
117+
#if 1
122118
#define ADD_PERF_TASK_PROCESS(TaskType, InputTypeParam, SettingsPath) \
123119
std::tuple(std::make_tuple(ppc::core::TaskGetter<TaskType, InputTypeParam>, \
124120
std::string(ppc::util::GetNamespace<TaskType>()) + "_" + \

modules/core/util/include/util.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#pragma once
2+
#include <stdbool.h>
3+
#include <stdlib.h>
4+
25
#include <cstdint>
36
#include <string>
47
#include <string_view>
@@ -61,9 +64,6 @@ static_assert(false, "Unsupported compiler");
6164
return kFunc.substr(start, end - start);
6265
}
6366

64-
#include <stdbool.h>
65-
#include <stdlib.h>
66-
6767
bool IsUnderMpirun();
6868

6969
} // namespace ppc::util

modules/core/util/src/util.cpp

Lines changed: 14 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,31 @@
11
#include "core/util/include/util.hpp"
22

3-
#include <cstdlib>
4-
#include <cstdint>
5-
#include <iostream>
6-
#include <memory>
7-
#include <vector>
83
#include <algorithm>
94
#include <array>
105
#include <filesystem>
11-
#include <ranges>
12-
#include <string>
13-
#include <iostream>
146
#include <libenvpp/env.hpp>
15-
16-
//namespace {
17-
//
18-
//struct MpiEnvVar {
19-
// std::string_view name;
20-
// const char* description;
21-
//};
22-
//
23-
//} // namespace
7+
#include <string>
248

259
std::string ppc::util::GetAbsolutePath(const std::string& relative_path) {
2610
const std::filesystem::path path = std::string(PPC_PATH_TO_PROJECT) + "/tasks/" + relative_path;
2711
return path.string();
2812
}
2913

3014
int ppc::util::GetNumThreads() {
31-
env::prefix pre("PPC");
32-
33-
const auto num_threads_id = pre.register_variable<unsigned>("NUM_THREADS");
34-
35-
auto validated = std::move(pre).parse_and_validate();
36-
37-
if (!validated.ok()) {
38-
std::cerr << validated.warning_message() << "\n";
39-
// throw validated.error_message();
15+
const auto num_threads = env::get<int>("PPC_NUM_THREADS");
16+
if (num_threads.has_value()) {
17+
return num_threads.value();
4018
}
41-
42-
const auto num_threads = validated.get(num_threads_id);
43-
return num_threads ? static_cast<int>(*num_threads) : 1;
19+
return 1;
4420
}
4521

46-
//const std::array<MpiEnvVar, 13> kMpiEnvVars = {{{.name = "OMPI_COMM_WORLD_SIZE", .description = "OpenMPI"},
47-
// {.name = "OMPI_UNIVERSE_SIZE", .description = "OpenMPI"},
48-
// {.name = "PMI_SIZE", .description = "MPICH/Intel MPI"},
49-
// {.name = "PMI_RANK", .description = "MPICH/Intel MPI"},
50-
// {.name = "PMI_FD", .description = "MPICH/Intel MPI"},
51-
// {.name = "HYDRA_CONTROL_FD", .description = "Hydra"},
52-
// {.name = "PMIX_RANK", .description = "Cray PMI/PMIx"},
53-
// {.name = "PMIX_NAMESPACE", .description = "Cray PMI/PMIx"},
54-
// {.name = "SLURM_PROCID", .description = "SLURM"},
55-
// {.name = "MPI_LOCALRANKID", .description = "IBM Spectrum MPI"},
56-
// {.name = "MSMPI_RANK", .description = "Microsoft MPI"},
57-
// {.name = "MSMPI_NODE_ID", .description = "Microsoft MPI"},
58-
// {.name = "MSMPI_LOCALRANK", .description = "Microsoft MPI"}}};
22+
constexpr std::array<std::string_view, 13> kMpiEnvVars = {
23+
"OMPI_COMM_WORLD_SIZE", "OMPI_UNIVERSE_SIZE", "PMI_SIZE", "PMI_RANK", "PMI_FD",
24+
"HYDRA_CONTROL_FD", "PMIX_RANK", "SLURM_PROCID", "MSMPI_RANK", "MSMPI_LOCALRANK"};
5925

60-
//bool ppc::util::IsUnderMpirun() {
61-
// auto pre = env::prefix("");
62-
// const auto parsed_and_validated_pre = pre.parse_and_validate();
63-
// return std::ranges::any_of(kMpiEnvVars, [&](const auto& env_var) {
64-
// const auto mpi_env_id = pre.register_variable<std::string>(env_var.name);
65-
//
66-
// if (!parsed_and_validated_pre.ok()) {
67-
// std::cerr << parsed_and_validated_pre.warning_message();
68-
// throw parsed_and_validated_pre.error_message();
69-
// }
70-
//
71-
// if (parsed_and_validated_pre.get(mpi_env_id)) {
72-
// return true;
73-
// } else {
74-
// return false;
75-
// }
76-
// });
77-
//}
26+
bool ppc::util::IsUnderMpirun() {
27+
return std::ranges::any_of(kMpiEnvVars, [&](const auto& env_var) {
28+
const auto mpi_env = env::get<int>(env_var);
29+
return static_cast<bool>(mpi_env.has_value());
30+
});
31+
}

tasks/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ if (USE_PERF_TESTS)
1818
list(APPEND list_of_exec_tests ${exec_perf_tests})
1919
endif (USE_PERF_TESTS)
2020

21-
if((DEFINED ENV{PPC_ASAN_RUN}) AND ("$ENV{PPC_ASAN_RUN}" STREQUAL "1"))
22-
add_compile_definitions(PPC_ASAN_RUN)
23-
endif()
24-
2521
SUBDIRLIST(subdirs ${CMAKE_CURRENT_LIST_DIR})
2622
foreach(subd ${subdirs})
2723
if (subd STREQUAL "common")

tasks/common/runners/functional.cpp

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
#include <fmt/core.h>
12
#include <gtest/gtest.h>
23
#include <mpi.h>
34
#include <omp.h>
45

56
#include <cstdio>
67
#include <memory>
7-
#include <print>
88
#include <string>
99
#include <utility>
1010

@@ -27,7 +27,7 @@ class UnreadMessagesDetector : public ::testing::EmptyTestEventListener {
2727
MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, &status);
2828

2929
if (flag != 0) {
30-
std::println(
30+
fmt::println(
3131
stderr,
3232
"[ PROCESS {} ] [ FAILED ] {}.{}: MPI message queue has an unread message from process {} with tag {}",
3333
rank, "test_suite_name", "test_name", status.MPI_SOURCE, status.MPI_TAG);
@@ -64,48 +64,42 @@ class WorkerTestFailurePrinter : public ::testing::EmptyTestEventListener {
6464
static void PrintProcessRank() {
6565
int rank = -1;
6666
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
67-
std::print(" [ PROCESS {} ] ", rank);
67+
fmt::print(" [ PROCESS {} ] ", rank);
6868
}
6969

7070
std::shared_ptr<::testing::TestEventListener> base_;
7171
};
7272

7373
int main(int argc, char** argv) {
74-
#ifndef PPC_ASAN_RUN
75-
MPI_Init(&argc, &argv);
74+
if (ppc::util::IsUnderMpirun()) {
75+
MPI_Init(&argc, &argv);
7676

77-
// Limit the number of threads in TBB
78-
tbb::global_control control(tbb::global_control::max_allowed_parallelism, ppc::util::GetNumThreads());
79-
// Limit the number of threads in OMP
80-
omp_set_num_threads(3);
77+
// Limit the number of threads in TBB
78+
tbb::global_control control(tbb::global_control::max_allowed_parallelism, ppc::util::GetNumThreads());
79+
// Limit the number of threads in OMP
80+
omp_set_num_threads(ppc::util::GetNumThreads());
8181

82+
::testing::InitGoogleTest(&argc, argv);
8283

83-
#pragma omp parallel
84-
{
85-
std::cout << "Thread: " << omp_get_thread_num() << "\n";
86-
}
87-
88-
::testing::InitGoogleTest(&argc, argv);
84+
auto& listeners = ::testing::UnitTest::GetInstance()->listeners();
85+
int rank = -1;
86+
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
87+
if (rank != 0 && (argc < 2 || argv[1] != std::string("--print-workers"))) {
88+
auto* listener = listeners.Release(listeners.default_result_printer());
89+
listeners.Append(new WorkerTestFailurePrinter(std::shared_ptr<::testing::TestEventListener>(listener)));
90+
}
91+
listeners.Append(new UnreadMessagesDetector());
92+
auto status = RUN_ALL_TESTS();
8993

90-
auto& listeners = ::testing::UnitTest::GetInstance()->listeners();
91-
int rank = -1;
92-
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
93-
if (rank != 0 && (argc < 2 || argv[1] != std::string("--print-workers"))) {
94-
auto* listener = listeners.Release(listeners.default_result_printer());
95-
listeners.Append(new WorkerTestFailurePrinter(std::shared_ptr<::testing::TestEventListener>(listener)));
94+
MPI_Finalize();
95+
return status;
9696
}
97-
listeners.Append(new UnreadMessagesDetector());
98-
auto status = RUN_ALL_TESTS();
9997

100-
MPI_Finalize();
101-
return status;
102-
#else
10398
// Limit the number of threads in TBB
10499
tbb::global_control control(tbb::global_control::max_allowed_parallelism, ppc::util::GetNumThreads());
105100
// Limit the number of threads in OMP
106101
omp_set_num_threads(ppc::util::GetNumThreads());
107102

108103
::testing::InitGoogleTest(&argc, argv);
109104
return RUN_ALL_TESTS();
110-
#endif
111105
}

0 commit comments

Comments
 (0)