diff --git a/modules/task/include/task.hpp b/modules/task/include/task.hpp index b6eaf59f0..976e1451a 100644 --- a/modules/task/include/task.hpp +++ b/modules/task/include/task.hpp @@ -203,7 +203,11 @@ template /// @tparam OutType Output data type. class Task { public: + using InputType = InType; + using OutputType = OutType; + Task() = default; + explicit Task(InType input, TypeOfTask type_of_task) : input_(std::move(input)), type_of_task_(type_of_task) {} Task(const Task &) = delete; Task(Task &&) = delete; Task &operator=(const Task &) = delete; @@ -263,16 +267,14 @@ class Task { return PostProcessingImpl(); } - /// @brief Returns the current testing mode. - /// @return Reference to the current StateOfTesting. - StateOfTesting &GetStateOfTesting() { - return state_of_testing_; + /// @brief Sets the current testing mode. + void SetStateOfTesting(StateOfTesting state_of_testing) { + state_of_testing_ = state_of_testing; } - /// @brief Sets the dynamic task type. - /// @param type_of_task Task type to set. - void SetTypeOfTask(TypeOfTask type_of_task) { - type_of_task_ = type_of_task; + /// @brief Returns the current testing mode. + [[nodiscard]] StateOfTesting GetStateOfTesting() const { + return state_of_testing_; } /// @brief Returns the dynamic task type. @@ -281,12 +283,6 @@ class Task { return type_of_task_; } - /// @brief Returns the current task status. - /// @return Task status (enabled or disabled). - [[nodiscard]] StatusOfTask GetStatusOfTask() const { - return status_of_task_; - } - /// @brief Returns the static task type. /// @return Static task type (default: kUnknown). static constexpr TypeOfTask GetStaticTypeOfTask() { @@ -295,13 +291,13 @@ class Task { /// @brief Returns a reference to the input data. /// @return Reference to the task's input data. - InType &GetInput() { + [[nodiscard]] const InType &GetInput() const { return input_; } /// @brief Returns a reference to the output data. /// @return Reference to the task's output data. - OutType &GetOutput() { + [[nodiscard]] const OutType &GetOutput() const { return output_; } @@ -317,6 +313,16 @@ class Task { } protected: + /// @brief Returns mutable access to the input for task implementations. + InType &GetMutableInput() { + return input_; + } + + /// @brief Returns mutable access to the output for task implementations. + OutType &GetMutableOutput() { + return output_; + } + /// @brief Measures execution time between preprocessing and postprocessing steps. /// @throws std::runtime_error If execution exceeds the allowed time limit. virtual void InternalTimeTest() final { @@ -364,7 +370,6 @@ class Task { OutType output_{}; StateOfTesting state_of_testing_ = StateOfTesting::kFunc; TypeOfTask type_of_task_ = TypeOfTask::kUnknown; - StatusOfTask status_of_task_ = StatusOfTask::kEnabled; std::chrono::high_resolution_clock::time_point tmp_time_point_; enum class PipelineStage : uint8_t { kNone, @@ -388,8 +393,8 @@ using TaskPtr = std::unique_ptr>; /// @param in Input to pass to the task constructor. /// @return Unique pointer to the newly created task. template -std::unique_ptr TaskGetter(const InType &in) { - return std::make_unique(in); +std::unique_ptr TaskGetter(InType &&in) { + return std::make_unique(std::forward(in)); } } // namespace ppc::task diff --git a/modules/task/tests/task_tests.cpp b/modules/task/tests/task_tests.cpp index a2755468c..6c9a9e2c1 100644 --- a/modules/task/tests/task_tests.cpp +++ b/modules/task/tests/task_tests.cpp @@ -46,9 +46,7 @@ namespace ppc::test { template class TestTask : public ppc::task::Task { public: - explicit TestTask(const InType &in) { - this->GetInput() = in; - } + explicit TestTask(InType in) : ppc::task::Task(std::move(in), TypeOfTask::kUnknown) {} protected: bool ValidationImpl() override { @@ -56,13 +54,13 @@ class TestTask : public ppc::task::Task { } bool PreProcessingImpl() override { - this->GetOutput() = 0; + this->GetMutableOutput() = 0; return true; } bool RunImpl() override { for (const auto &value : this->GetInput()) { - this->GetOutput() += value; + this->GetMutableOutput() += value; } return true; } @@ -287,9 +285,8 @@ TEST(TaskTest, TaskDestructorThrowsIfStageIncomplete) { std::vector in(20, 1); struct LocalTask : Task, int32_t> { public: - explicit LocalTask(const std::vector &in) { - this->GetInput() = in; - } + explicit LocalTask(std::vector in) + : Task, int32_t>(std::move(in), TypeOfTask::kUnknown) {} protected: bool ValidationImpl() override { @@ -316,9 +313,8 @@ TEST(TaskTest, TaskDestructorThrowsIfEmpty) { std::vector in(20, 1); struct LocalTask : Task, int32_t> { public: - explicit LocalTask(const std::vector &in) { - this->GetInput() = in; - } + explicit LocalTask(std::vector in) + : Task, int32_t>(std::move(in), TypeOfTask::kUnknown) {} protected: bool ValidationImpl() override { @@ -345,9 +341,8 @@ TEST(TaskTest, InternalTimeTestThrowsIfTimeoutExceeded) { #endif struct SlowTask : Task, int32_t> { public: - explicit SlowTask(const std::vector &in) { - this->GetInput() = in; - } + explicit SlowTask(std::vector in) + : Task, int32_t>(std::move(in), TypeOfTask::kUnknown) {} protected: bool ValidationImpl() override { @@ -367,7 +362,7 @@ TEST(TaskTest, InternalTimeTestThrowsIfTimeoutExceeded) { std::vector in(20, 1); SlowTask task(in); - task.GetStateOfTesting() = StateOfTesting::kFunc; + task.SetStateOfTesting(StateOfTesting::kFunc); task.Validation(); EXPECT_NO_THROW(task.PreProcessing()); task.Run(); @@ -394,8 +389,7 @@ class DummyTask : public Task { }; TEST(TaskTest, GetDynamicTypeReturnsCorrectEnum) { - DummyTask task; - task.SetTypeOfTask(TypeOfTask::kOMP); + DummyTask task(0, TypeOfTask::kOMP); task.Validation(); task.PreProcessing(); task.Run(); diff --git a/modules/util/include/func_test_util.hpp b/modules/util/include/func_test_util.hpp index b1e4d44bd..eebd214ec 100644 --- a/modules/util/include/func_test_util.hpp +++ b/modules/util/include/func_test_util.hpp @@ -19,8 +19,14 @@ namespace ppc::util { template -using FuncTestParam = std::tuple(InType)>, std::string, TestType, - ppc::task::TaskDescriptor>; +struct FuncTestCase { + std::function(InType)> task_getter; + TestType test_param; + ppc::task::TaskDescriptor descriptor; +}; + +template +using FuncTestParam = FuncTestCase; template using GTestFuncParam = ::testing::TestParamInfo>; @@ -49,12 +55,11 @@ class BaseRunFuncTests : public ::testing::TestWithParam static std::string PrintFuncTestName(const GTestFuncParam &info) { RequireStaticInterface(); - TestType test_param = std::get(ppc::util::GTestParamIndex::kTestParams)>(info.param); - return GetTaskDescriptor(info.param).display_name + "_" + Derived::PrintTestParam(test_param); + return info.param.descriptor.display_name + "_" + Derived::PrintTestParam(info.param.test_param); } protected: - virtual bool CheckTestOutputData(OutType &output_data) = 0; + virtual bool CheckTestOutputData(const OutType &output_data) = 0; /// @brief Provides input data for the task. /// @return Initialized input data. virtual InType GetTestInputData() = 0; @@ -70,7 +75,7 @@ class BaseRunFuncTests : public ::testing::TestWithParam &test_param) { - const auto &descriptor = GetTaskDescriptor(test_param); + const auto &descriptor = test_param.descriptor; ValidateTaskDescriptor(descriptor); @@ -101,13 +106,13 @@ class BaseRunFuncTests : public ::testing::TestWithParam &test_param) { - const auto &descriptor = GetTaskDescriptor(test_param); + const auto &descriptor = test_param.descriptor; return IsTestDisabled(descriptor) || ShouldSkipNonMpiTask(descriptor); } /// @brief Initializes task instance and runs it through the full pipeline. void InitializeAndRunTask(const FuncTestParam &test_param) { - task_ = std::get(GTestParamIndex::kTaskGetter)>(test_param)(GetTestInputData()); + task_ = test_param.task_getter(GetTestInputData()); ExecuteTaskPipeline(); } @@ -161,7 +166,7 @@ void RunTestCasesWithTag(const TestTasksList &test_tasks_list, std::string_view bool has_matching_task = false; std::apply([&](const auto &...test_params) { auto run_if_tagged = [&](const auto &test_param) { - const auto &descriptor = GetTaskDescriptor(test_param); + const auto &descriptor = test_param.descriptor; if (descriptor.type == task_type) { has_matching_task = true; std::invoke(run_test_case, test_param); @@ -186,10 +191,10 @@ auto ExpandToValues(const Tuple &t) { template auto GenTaskTuplesImpl(const SizesContainer &sizes, const std::string &settings_path, std::string_view settings_task_path, std::index_sequence /*unused*/) { - const auto descriptor = - MakeTaskDescriptor(GetNamespace(), Task::GetStaticTypeOfTask(), settings_path, settings_task_path); - return std::make_tuple(std::make_tuple(ppc::task::TaskGetter, descriptor.display_name, - std::get(sizes), descriptor)...); + const auto descriptor = MakeTaskDescriptor(ResolveTaskIdentifier(settings_path), Task::GetStaticTypeOfTask(), + settings_path, settings_task_path); + return std::make_tuple(FuncTestCase(sizes))>>{ + ppc::task::TaskGetter, std::get(sizes), descriptor}...); } template diff --git a/modules/util/include/perf_test_util.hpp b/modules/util/include/perf_test_util.hpp index e4c4b29d7..5e555b844 100644 --- a/modules/util/include/perf_test_util.hpp +++ b/modules/util/include/perf_test_util.hpp @@ -114,7 +114,7 @@ template double RunTaskForBenchmark(const ppc::task::TaskPtr &task) { const auto task_type = task->GetDynamicTypeOfTask(); const auto timer = MakeTechnologyTimer(task_type); - task->GetStateOfTesting() = ppc::task::StateOfTesting::kPerf; + task->SetStateOfTesting(ppc::task::StateOfTesting::kPerf); task->Validation(); task->PreProcessing(); @@ -137,7 +137,8 @@ void RunBenchmarkBody(const TaskGetter &task_getter, const InType &input_data, c auto task = task_getter(input_data); const double elapsed = RunTaskForBenchmark(task); state.SetIterationTime(elapsed); - benchmark::DoNotOptimize(task->GetOutput()); + auto output = task->GetOutput(); + benchmark::DoNotOptimize(output); } } catch (const std::exception &e) { PerformanceFailureFlag::Set(); @@ -169,8 +170,13 @@ class BenchmarkTaskBody final { } // namespace detail template -using PerfTestParam = std::tuple(InType)>, std::string, - ppc::task::TaskCategory, ppc::task::TaskDescriptor>; +struct PerfTestCase { + std::function(InType)> task_getter; + ppc::task::TaskDescriptor descriptor; +}; + +template +using PerfTestParam = PerfTestCase; template /// @brief Base class for performance testing of parallel tasks. @@ -180,11 +186,11 @@ class BaseRunPerfTests : public ::testing::TestWithParam> &info) { - return GetTaskDescriptor(info.param).display_name; + return info.param.descriptor.display_name; } protected: - virtual bool CheckTestOutputData(OutType &output_data) = 0; + virtual bool CheckTestOutputData(const OutType &output_data) = 0; /// @brief Supplies input data for performance testing. virtual InType GetTestInputData() = 0; @@ -193,8 +199,8 @@ class BaseRunPerfTests : public ::testing::TestWithParam &perf_test_param) { - auto task_getter = std::get(GTestParamIndex::kTaskGetter)>(perf_test_param); - const auto &descriptor = GetTaskDescriptor(perf_test_param); + auto task_getter = perf_test_param.task_getter; + const auto &descriptor = perf_test_param.descriptor; ASSERT_NE(descriptor.type, ppc::task::TypeOfTask::kUnknown); if (descriptor.status == ppc::task::StatusOfTask::kDisabled) { @@ -209,12 +215,11 @@ class BaseRunPerfTests : public ::testing::TestWithParamGetStateOfTesting() = ppc::task::StateOfTesting::kPerf; + task_->SetStateOfTesting(ppc::task::StateOfTesting::kPerf); SynchronizeMpiRanks(); detail::RunTaskForValidation(task_); - OutType output_data = task_->GetOutput(); - ASSERT_TRUE(CheckTestOutputData(output_data)); + ASSERT_TRUE(CheckTestOutputData(task_->GetOutput())); PerfAttr perf_attr; SetPerfAttributes(perf_attr); @@ -236,11 +241,11 @@ class BaseRunPerfTests : public ::testing::TestWithParam auto MakePerfTaskTuples(const std::string &settings_path, std::string_view settings_task_path = {}) { - const auto descriptor = - MakeTaskDescriptor(GetNamespace(), TaskType::GetStaticTypeOfTask(), settings_path, settings_task_path); + const auto descriptor = MakeTaskDescriptor(ResolveTaskIdentifier(settings_path), + TaskType::GetStaticTypeOfTask(), settings_path, settings_task_path); - return std::make_tuple(std::make_tuple(ppc::task::TaskGetter, descriptor.display_name, - descriptor.category, descriptor)); + return std::make_tuple( + PerfTestCase{ppc::task::TaskGetter, descriptor}); } template diff --git a/modules/util/include/task_descriptor_util.hpp b/modules/util/include/task_descriptor_util.hpp index 63131c698..72888adcd 100644 --- a/modules/util/include/task_descriptor_util.hpp +++ b/modules/util/include/task_descriptor_util.hpp @@ -1,14 +1,26 @@ #pragma once -#include +#include +#include #include #include #include "task/include/task.hpp" -#include "util/include/util.hpp" namespace ppc::util { +template +std::string ResolveTaskIdentifier(const std::string &settings_path) { + if constexpr (requires { + { Task::GetTaskIdentifier() } -> std::convertible_to; + }) { + return std::string(Task::GetTaskIdentifier()); + } else { + const std::filesystem::path path(settings_path); + return path.has_parent_path() ? path.parent_path().filename().string() : path.stem().string(); + } +} + inline ppc::task::TaskDescriptor MakeTaskDescriptor(std::string_view task_namespace, ppc::task::TypeOfTask task_type, const std::string &settings_path, std::string_view settings_task_path = {}) { @@ -23,11 +35,6 @@ inline ppc::task::TaskDescriptor MakeTaskDescriptor(std::string_view task_namesp .display_name = std::string(task_namespace) + "_" + task_name}; } -template -const ppc::task::TaskDescriptor &GetTaskDescriptor(const TestParam &test_param) { - return std::get(GTestParamIndex::kTaskDescriptor)>(test_param); -} - inline bool IsMpiTaskType(ppc::task::TypeOfTask type) { return type == ppc::task::TypeOfTask::kMPI || type == ppc::task::TypeOfTask::kALL; } diff --git a/modules/util/include/util.hpp b/modules/util/include/util.hpp index 0c223f19c..e2d4ea92c 100644 --- a/modules/util/include/util.hpp +++ b/modules/util/include/util.hpp @@ -4,18 +4,12 @@ #include #include #include -#include -#include #include #include #include #include #include #include -#include -#ifdef __GNUG__ -# include -#endif #include "nlohmann/json_fwd.hpp" @@ -82,13 +76,6 @@ class PerformanceFailureFlag { inline static std::atomic failure_flag{false}; }; -enum class GTestParamIndex : uint8_t { - kTaskGetter, - kNameTest, - kTestParams, - kTaskDescriptor, -}; - std::string GetAbsoluteTaskPath(const std::string &id_path, const std::string &relative_path); int GetNumThreads(); int GetNumProc(); @@ -99,29 +86,6 @@ int GetMPIRank(); void ConfigureMpiEnvironment(); void SynchronizeMpiRanks(); -template -std::string GetNamespace() { - std::string name = typeid(T).name(); -#ifdef __GNUC__ - int status = 0; - std::unique_ptr demangled{abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status), - std::free}; - name = (status == 0) ? demangled.get() : name; -#endif -#ifdef _MSC_VER - const std::string prefixes[] = {"class ", "struct ", "enum ", "union "}; - for (const auto &prefix : prefixes) { - if (name.starts_with(prefix)) { - name = name.substr(prefix.size()); - break; - } - } - name.erase(0, name.find_first_not_of(' ')); -#endif - auto pos = name.rfind("::"); - return (pos != std::string::npos) ? name.substr(0, pos) : std::string{}; -} - inline std::shared_ptr InitJSONPtr() { return std::make_shared(); } diff --git a/modules/util/tests/util.cpp b/modules/util/tests/util.cpp index 1b7644a99..a4e6ee816 100644 --- a/modules/util/tests/util.cpp +++ b/modules/util/tests/util.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -15,75 +14,12 @@ #include "task/include/task.hpp" #include "util/include/func_test_util.hpp" -namespace my::nested { -struct Type {}; -} // namespace my::nested - -TEST(UtilTests, ExtractsCorrectNamespace) { - std::string k_ns = ppc::util::GetNamespace(); - EXPECT_EQ(k_ns, "my::nested"); -} - TEST(UtilTests, ThreadsControlCheckOpenmpDisabledValgrind) { const auto num_threads_env_var = env::get("PPC_NUM_THREADS"); EXPECT_EQ(ppc::util::GetNumThreads(), omp_get_max_threads()); } -namespace test_ns { -struct TypeInNamespace {}; -} // namespace test_ns - -struct PlainType {}; - -TEST(GetNamespaceTest, ReturnsExpectedNamespace) { - std::string k_ns = ppc::util::GetNamespace(); - EXPECT_EQ(k_ns, "test_ns"); -} - -TEST(GetNamespaceTest, ReturnsEmptyIfNoNamespacePrimitiveType) { - std::string k_ns = ppc::util::GetNamespace(); - EXPECT_EQ(k_ns, ""); -} - -TEST(GetNamespaceTest, ReturnsEmptyIfNoNamespacePlainStruct) { - std::string k_ns = ppc::util::GetNamespace(); - EXPECT_EQ(k_ns, ""); -} - -namespace test_ns { -struct Nested {}; -} // namespace test_ns - -TEST(GetNamespaceTest, ReturnsNamespaceCorrectly) { - std::string k_ns = ppc::util::GetNamespace(); - EXPECT_EQ(k_ns, "test_ns"); -} - -struct NoNamespaceType {}; - -TEST(GetNamespaceTest, NoNamespaceInType) { - std::string k_ns = ppc::util::GetNamespace(); - EXPECT_EQ(k_ns, ""); -} - -template -struct NotATemplate {}; - -TEST(GetNamespaceTest, NoKeyInPrettyFunction) { - std::string k_ns = ppc::util::GetNamespace>(); - EXPECT_EQ(k_ns, ""); -} - -namespace crazy { -struct VeryLongTypeNameWithOnlyLettersAndUnderscores {}; -} // namespace crazy - -TEST(GetNamespaceTest, NoTerminatorCharactersInPrettyFunction) { - std::string k_ns = ppc::util::GetNamespace(); - EXPECT_EQ(k_ns, "crazy"); -} - TEST(GetTaskMaxTime, ReturnsDefaultWhenUnset) { const auto old = env::get("PPC_TASK_MAX_TIME"); if (old.has_value()) { @@ -136,13 +72,37 @@ namespace { using FuncTestUtilParam = ppc::util::FuncTestParam; +class DocumentedTask : public ppc::task::Task { + public: + explicit DocumentedTask(int input) : ppc::task::Task(input, ppc::task::TypeOfTask::kSEQ) {} + + static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() { + return ppc::task::TypeOfTask::kSEQ; + } + + protected: + bool ValidationImpl() override { + return true; + } + bool PreProcessingImpl() override { + return true; + } + bool RunImpl() override { + return true; + } + bool PostProcessingImpl() override { + return true; + } +}; + FuncTestUtilParam MakeFuncTestUtilParam(const std::string &test_name, ppc::task::TypeOfTask task_type, ppc::task::StatusOfTask task_status, int value) { - return FuncTestUtilParam{[](int) -> ppc::task::TaskPtr { return {}; }, test_name, value, - ppc::task::TaskDescriptor{.type = task_type, - .status = task_status, - .category = ppc::task::TaskCategory::kThreads, - .display_name = test_name}}; + return FuncTestUtilParam{.task_getter = [](int) -> ppc::task::TaskPtr { return {}; }, + .test_param = value, + .descriptor = ppc::task::TaskDescriptor{.type = task_type, + .status = task_status, + .category = ppc::task::TaskCategory::kThreads, + .display_name = test_name}}; } void ExpectSingleNonFatalFailureContains(const ::testing::TestPartResultArray &failures, std::string_view message) { @@ -154,6 +114,14 @@ void ExpectSingleNonFatalFailureContains(const ::testing::TestPartResultArray &f } // namespace +TEST(FuncTestUtil, SupportsDocumentedTaskWithoutExplicitIdentifier) { + const auto test_params = std::make_tuple(1); + const std::string settings_path = "tasks/example/settings.json"; + const auto test_cases = ppc::util::AddFuncTask(test_params, settings_path, "threads"); + + EXPECT_EQ(std::get<0>(test_cases).descriptor.display_name, "example_seq_enabled"); +} + TEST(FuncTestUtil, RunTestCasesWithTagAcceptsBareTags) { const auto test_tasks = std::make_tuple(MakeFuncTestUtilParam("example_threads_contains_tbb_seq_enabled", ppc::task::TypeOfTask::kSEQ, @@ -164,9 +132,8 @@ TEST(FuncTestUtil, RunTestCasesWithTagAcceptsBareTags) { ppc::task::StatusOfTask::kDisabled, 3)); std::vector visited_params; - ppc::util::RunTestCasesWithTag(test_tasks, "tbb", [&](const auto &test_param) { - visited_params.push_back(std::get(ppc::util::GTestParamIndex::kTestParams)>(test_param)); - }); + ppc::util::RunTestCasesWithTag(test_tasks, "tbb", + [&](const auto &test_param) { visited_params.push_back(test_param.test_param); }); const std::vector expected_params{2, 3}; EXPECT_EQ(visited_params, expected_params); diff --git a/tasks/example/common/include/common.hpp b/tasks/example/common/include/common.hpp index 54c9cd713..c903f0026 100644 --- a/tasks/example/common/include/common.hpp +++ b/tasks/example/common/include/common.hpp @@ -1,7 +1,8 @@ #pragma once #include -#include +#include +#include #include "task/include/task.hpp" @@ -9,11 +10,18 @@ namespace example_common { using InType = int; using OutType = int; -using TestType = std::tuple; +struct TestCase { + int value; + std::string name; +}; + +using TestType = TestCase; template class BaseTask : public ppc::task::Task { public: + explicit BaseTask(InType input) : ppc::task::Task(std::move(input), kTaskType) {} + static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() { return kTaskType; } @@ -23,36 +31,72 @@ class BaseTask : public ppc::task::Task { namespace example_threads { -using example_common::BaseTask; using example_common::InType; using example_common::OutType; using example_common::TestType; +template +class BaseTask : public example_common::BaseTask { + public: + using example_common::BaseTask::BaseTask; + + static constexpr std::string_view GetTaskIdentifier() { + return "example_threads"; + } +}; + } // namespace example_threads namespace example_processes_t1 { -using example_common::BaseTask; using example_common::InType; using example_common::OutType; using example_common::TestType; +template +class BaseTask : public example_common::BaseTask { + public: + using example_common::BaseTask::BaseTask; + + static constexpr std::string_view GetTaskIdentifier() { + return "example_processes_t1"; + } +}; + } // namespace example_processes_t1 namespace example_processes_t2 { -using example_common::BaseTask; using example_common::InType; using example_common::OutType; using example_common::TestType; +template +class BaseTask : public example_common::BaseTask { + public: + using example_common::BaseTask::BaseTask; + + static constexpr std::string_view GetTaskIdentifier() { + return "example_processes_t2"; + } +}; + } // namespace example_processes_t2 namespace example_processes_t3 { -using example_common::BaseTask; using example_common::InType; using example_common::OutType; using example_common::TestType; +template +class BaseTask : public example_common::BaseTask { + public: + using example_common::BaseTask::BaseTask; + + static constexpr std::string_view GetTaskIdentifier() { + return "example_processes_t3"; + } +}; + } // namespace example_processes_t3 diff --git a/tasks/example/processes/t1/mpi/src/ops_mpi.cpp b/tasks/example/processes/t1/mpi/src/ops_mpi.cpp index 32f79bbe6..e4cfe2778 100644 --- a/tasks/example/processes/t1/mpi/src/ops_mpi.cpp +++ b/tasks/example/processes/t1/mpi/src/ops_mpi.cpp @@ -10,19 +10,15 @@ namespace example_processes_t1 { -NesterovATestTaskMPI::NesterovATestTaskMPI(const InType &in) { - SetTypeOfTask(GetStaticTypeOfTask()); - GetInput() = in; - GetOutput() = 0; -} +NesterovATestTaskMPI::NesterovATestTaskMPI(const InType &in) : BaseTask(in) {} bool NesterovATestTaskMPI::ValidationImpl() { - return (GetInput() > 0) && (GetOutput() == 0); + return (GetInput() > 0) && (GetMutableOutput() == 0); } bool NesterovATestTaskMPI::PreProcessingImpl() { - GetOutput() = 2 * GetInput(); - return GetOutput() > 0; + GetMutableOutput() = 2 * GetInput(); + return GetMutableOutput() > 0; } bool NesterovATestTaskMPI::RunImpl() { @@ -35,20 +31,20 @@ bool NesterovATestTaskMPI::RunImpl() { for (InType j = 0; j < GetInput(); j++) { for (InType k = 0; k < GetInput(); k++) { std::vector tmp(i + j + k, 1); - GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); - GetOutput() -= i + j + k; + GetMutableOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); + GetMutableOutput() -= i + j + k; } } } const int num_threads = ppc::util::GetNumThreads(); - GetOutput() *= num_threads; + GetMutableOutput() *= num_threads; int rank = 0; MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (rank == 0) { - GetOutput() /= num_threads; + GetMutableOutput() /= num_threads; } else { int counter = 0; for (int i = 0; i < num_threads; i++) { @@ -56,17 +52,17 @@ bool NesterovATestTaskMPI::RunImpl() { } if (counter != 0) { - GetOutput() /= counter; + GetMutableOutput() /= counter; } } MPI_Barrier(MPI_COMM_WORLD); - return GetOutput() > 0; + return GetMutableOutput() > 0; } bool NesterovATestTaskMPI::PostProcessingImpl() { - GetOutput() -= GetInput(); - return GetOutput() > 0; + GetMutableOutput() -= GetInput(); + return GetMutableOutput() > 0; } } // namespace example_processes_t1 diff --git a/tasks/example/processes/t1/seq/src/ops_seq.cpp b/tasks/example/processes/t1/seq/src/ops_seq.cpp index 01d753109..0962c0541 100644 --- a/tasks/example/processes/t1/seq/src/ops_seq.cpp +++ b/tasks/example/processes/t1/seq/src/ops_seq.cpp @@ -8,19 +8,15 @@ namespace example_processes_t1 { -NesterovATestTaskSEQ::NesterovATestTaskSEQ(const InType &in) { - SetTypeOfTask(GetStaticTypeOfTask()); - GetInput() = in; - GetOutput() = 0; -} +NesterovATestTaskSEQ::NesterovATestTaskSEQ(const InType &in) : BaseTask(in) {} bool NesterovATestTaskSEQ::ValidationImpl() { - return (GetInput() > 0) && (GetOutput() == 0); + return (GetInput() > 0) && (GetMutableOutput() == 0); } bool NesterovATestTaskSEQ::PreProcessingImpl() { - GetOutput() = 2 * GetInput(); - return GetOutput() > 0; + GetMutableOutput() = 2 * GetInput(); + return GetMutableOutput() > 0; } bool NesterovATestTaskSEQ::RunImpl() { @@ -32,14 +28,14 @@ bool NesterovATestTaskSEQ::RunImpl() { for (InType j = 0; j < GetInput(); j++) { for (InType k = 0; k < GetInput(); k++) { std::vector tmp(i + j + k, 1); - GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); - GetOutput() -= i + j + k; + GetMutableOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); + GetMutableOutput() -= i + j + k; } } } const int num_threads = ppc::util::GetNumThreads(); - GetOutput() *= num_threads; + GetMutableOutput() *= num_threads; int counter = 0; for (int i = 0; i < num_threads; i++) { @@ -47,14 +43,14 @@ bool NesterovATestTaskSEQ::RunImpl() { } if (counter != 0) { - GetOutput() /= counter; + GetMutableOutput() /= counter; } - return GetOutput() > 0; + return GetMutableOutput() > 0; } bool NesterovATestTaskSEQ::PostProcessingImpl() { - GetOutput() -= GetInput(); - return GetOutput() > 0; + GetMutableOutput() -= GetInput(); + return GetMutableOutput() > 0; } } // namespace example_processes_t1 diff --git a/tasks/example/processes/t1/tests/functional/main.cpp b/tasks/example/processes/t1/tests/functional/main.cpp index e955971a8..bc02f2977 100644 --- a/tasks/example/processes/t1/tests/functional/main.cpp +++ b/tasks/example/processes/t1/tests/functional/main.cpp @@ -24,7 +24,7 @@ namespace example_processes_t1 { class NesterovARunFuncTestsProcesses : public ppc::util::BaseRunFuncTests { public: static std::string PrintTestParam(const TestType &test_param) { - return std::to_string(std::get<0>(test_param)) + "_" + std::get<1>(test_param); + return std::to_string(test_param.value) + "_" + test_param.name; } protected: @@ -60,7 +60,7 @@ class NesterovARunFuncTestsProcesses : public ppc::util::BaseRunFuncTests kTestParam = {std::make_tuple(3, "3"), std::make_tuple(5, "5"), std::make_tuple(7, "7")}; +const std::array kTestParam = { + {{.value = 3, .name = "3"}, {.value = 5, .name = "5"}, {.value = 7, .name = "7"}}}; const auto kTestTasksList = std::tuple_cat( ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_example, "processes.t1"), diff --git a/tasks/example/processes/t1/tests/performance/main.cpp b/tasks/example/processes/t1/tests/performance/main.cpp index f628496c8..874752ede 100644 --- a/tasks/example/processes/t1/tests/performance/main.cpp +++ b/tasks/example/processes/t1/tests/performance/main.cpp @@ -15,7 +15,7 @@ class ExampleRunPerfTestProcesses : public ppc::util::BaseRunPerfTests 0) && (GetOutput() == 0); + return (GetInput() > 0) && (GetMutableOutput() == 0); } bool NesterovATestTaskMPI::PreProcessingImpl() { - GetOutput() = 2 * GetInput(); - return GetOutput() > 0; + GetMutableOutput() = 2 * GetInput(); + return GetMutableOutput() > 0; } bool NesterovATestTaskMPI::RunImpl() { @@ -35,20 +31,20 @@ bool NesterovATestTaskMPI::RunImpl() { for (InType j = 0; j < GetInput(); j++) { for (InType k = 0; k < GetInput(); k++) { std::vector tmp(i + j + k, 1); - GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); - GetOutput() -= i + j + k; + GetMutableOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); + GetMutableOutput() -= i + j + k; } } } const int num_threads = ppc::util::GetNumThreads(); - GetOutput() *= num_threads; + GetMutableOutput() *= num_threads; int rank = 0; MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (rank == 0) { - GetOutput() /= num_threads; + GetMutableOutput() /= num_threads; } else { int counter = 0; for (int i = 0; i < num_threads; i++) { @@ -56,17 +52,17 @@ bool NesterovATestTaskMPI::RunImpl() { } if (counter != 0) { - GetOutput() /= counter; + GetMutableOutput() /= counter; } } MPI_Barrier(MPI_COMM_WORLD); - return GetOutput() > 0; + return GetMutableOutput() > 0; } bool NesterovATestTaskMPI::PostProcessingImpl() { - GetOutput() -= GetInput(); - return GetOutput() > 0; + GetMutableOutput() -= GetInput(); + return GetMutableOutput() > 0; } } // namespace example_processes_t2 diff --git a/tasks/example/processes/t2/seq/src/ops_seq.cpp b/tasks/example/processes/t2/seq/src/ops_seq.cpp index 60d962f28..065388c30 100644 --- a/tasks/example/processes/t2/seq/src/ops_seq.cpp +++ b/tasks/example/processes/t2/seq/src/ops_seq.cpp @@ -8,19 +8,15 @@ namespace example_processes_t2 { -NesterovATestTaskSEQ::NesterovATestTaskSEQ(const InType &in) { - SetTypeOfTask(GetStaticTypeOfTask()); - GetInput() = in; - GetOutput() = 0; -} +NesterovATestTaskSEQ::NesterovATestTaskSEQ(const InType &in) : BaseTask(in) {} bool NesterovATestTaskSEQ::ValidationImpl() { - return (GetInput() > 0) && (GetOutput() == 0); + return (GetInput() > 0) && (GetMutableOutput() == 0); } bool NesterovATestTaskSEQ::PreProcessingImpl() { - GetOutput() = 2 * GetInput(); - return GetOutput() > 0; + GetMutableOutput() = 2 * GetInput(); + return GetMutableOutput() > 0; } bool NesterovATestTaskSEQ::RunImpl() { @@ -32,14 +28,14 @@ bool NesterovATestTaskSEQ::RunImpl() { for (InType j = 0; j < GetInput(); j++) { for (InType k = 0; k < GetInput(); k++) { std::vector tmp(i + j + k, 1); - GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); - GetOutput() -= i + j + k; + GetMutableOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); + GetMutableOutput() -= i + j + k; } } } const int num_threads = ppc::util::GetNumThreads(); - GetOutput() *= num_threads; + GetMutableOutput() *= num_threads; int counter = 0; for (int i = 0; i < num_threads; i++) { @@ -47,14 +43,14 @@ bool NesterovATestTaskSEQ::RunImpl() { } if (counter != 0) { - GetOutput() /= counter; + GetMutableOutput() /= counter; } - return GetOutput() > 0; + return GetMutableOutput() > 0; } bool NesterovATestTaskSEQ::PostProcessingImpl() { - GetOutput() -= GetInput(); - return GetOutput() > 0; + GetMutableOutput() -= GetInput(); + return GetMutableOutput() > 0; } } // namespace example_processes_t2 diff --git a/tasks/example/processes/t2/tests/functional/main.cpp b/tasks/example/processes/t2/tests/functional/main.cpp index 084ca9896..cb6caf9db 100644 --- a/tasks/example/processes/t2/tests/functional/main.cpp +++ b/tasks/example/processes/t2/tests/functional/main.cpp @@ -24,7 +24,7 @@ namespace example_processes_t2 { class NesterovARunFuncTestsProcesses2 : public ppc::util::BaseRunFuncTests { public: static std::string PrintTestParam(const TestType &test_param) { - return std::to_string(std::get<0>(test_param)) + "_" + std::get<1>(test_param); + return std::to_string(test_param.value) + "_" + test_param.name; } protected: @@ -60,7 +60,7 @@ class NesterovARunFuncTestsProcesses2 : public ppc::util::BaseRunFuncTests kTestParam = {std::make_tuple(3, "3"), std::make_tuple(5, "5"), std::make_tuple(7, "7")}; +const std::array kTestParam = { + {{.value = 3, .name = "3"}, {.value = 5, .name = "5"}, {.value = 7, .name = "7"}}}; const auto kTestTasksList = std::tuple_cat( ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_example, "processes.t2"), diff --git a/tasks/example/processes/t2/tests/performance/main.cpp b/tasks/example/processes/t2/tests/performance/main.cpp index 0d991ca40..251f782c5 100644 --- a/tasks/example/processes/t2/tests/performance/main.cpp +++ b/tasks/example/processes/t2/tests/performance/main.cpp @@ -15,7 +15,7 @@ class ExampleRunPerfTestProcesses2 : public ppc::util::BaseRunPerfTests 0) && (GetOutput() == 0); + return (GetInput() > 0) && (GetMutableOutput() == 0); } bool NesterovATestTaskMPI::PreProcessingImpl() { - GetOutput() = 2 * GetInput(); - return GetOutput() > 0; + GetMutableOutput() = 2 * GetInput(); + return GetMutableOutput() > 0; } bool NesterovATestTaskMPI::RunImpl() { @@ -35,20 +31,20 @@ bool NesterovATestTaskMPI::RunImpl() { for (InType j = 0; j < GetInput(); j++) { for (InType k = 0; k < GetInput(); k++) { std::vector tmp(i + j + k, 1); - GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); - GetOutput() -= i + j + k; + GetMutableOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); + GetMutableOutput() -= i + j + k; } } } const int num_threads = ppc::util::GetNumThreads(); - GetOutput() *= num_threads; + GetMutableOutput() *= num_threads; int rank = 0; MPI_Comm_rank(MPI_COMM_WORLD, &rank); if (rank == 0) { - GetOutput() /= num_threads; + GetMutableOutput() /= num_threads; } else { int counter = 0; for (int i = 0; i < num_threads; i++) { @@ -56,17 +52,17 @@ bool NesterovATestTaskMPI::RunImpl() { } if (counter != 0) { - GetOutput() /= counter; + GetMutableOutput() /= counter; } } MPI_Barrier(MPI_COMM_WORLD); - return GetOutput() > 0; + return GetMutableOutput() > 0; } bool NesterovATestTaskMPI::PostProcessingImpl() { - GetOutput() -= GetInput(); - return GetOutput() > 0; + GetMutableOutput() -= GetInput(); + return GetMutableOutput() > 0; } } // namespace example_processes_t3 diff --git a/tasks/example/processes/t3/seq/src/ops_seq.cpp b/tasks/example/processes/t3/seq/src/ops_seq.cpp index 91b89b399..db19664f5 100644 --- a/tasks/example/processes/t3/seq/src/ops_seq.cpp +++ b/tasks/example/processes/t3/seq/src/ops_seq.cpp @@ -8,19 +8,15 @@ namespace example_processes_t3 { -NesterovATestTaskSEQ::NesterovATestTaskSEQ(const InType &in) { - SetTypeOfTask(GetStaticTypeOfTask()); - GetInput() = in; - GetOutput() = 0; -} +NesterovATestTaskSEQ::NesterovATestTaskSEQ(const InType &in) : BaseTask(in) {} bool NesterovATestTaskSEQ::ValidationImpl() { - return (GetInput() > 0) && (GetOutput() == 0); + return (GetInput() > 0) && (GetMutableOutput() == 0); } bool NesterovATestTaskSEQ::PreProcessingImpl() { - GetOutput() = 2 * GetInput(); - return GetOutput() > 0; + GetMutableOutput() = 2 * GetInput(); + return GetMutableOutput() > 0; } bool NesterovATestTaskSEQ::RunImpl() { @@ -32,14 +28,14 @@ bool NesterovATestTaskSEQ::RunImpl() { for (InType j = 0; j < GetInput(); j++) { for (InType k = 0; k < GetInput(); k++) { std::vector tmp(i + j + k, 1); - GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); - GetOutput() -= i + j + k; + GetMutableOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); + GetMutableOutput() -= i + j + k; } } } const int num_threads = ppc::util::GetNumThreads(); - GetOutput() *= num_threads; + GetMutableOutput() *= num_threads; int counter = 0; for (int i = 0; i < num_threads; i++) { @@ -47,14 +43,14 @@ bool NesterovATestTaskSEQ::RunImpl() { } if (counter != 0) { - GetOutput() /= counter; + GetMutableOutput() /= counter; } - return GetOutput() > 0; + return GetMutableOutput() > 0; } bool NesterovATestTaskSEQ::PostProcessingImpl() { - GetOutput() -= GetInput(); - return GetOutput() > 0; + GetMutableOutput() -= GetInput(); + return GetMutableOutput() > 0; } } // namespace example_processes_t3 diff --git a/tasks/example/processes/t3/tests/functional/main.cpp b/tasks/example/processes/t3/tests/functional/main.cpp index 4b0579780..5c78d416e 100644 --- a/tasks/example/processes/t3/tests/functional/main.cpp +++ b/tasks/example/processes/t3/tests/functional/main.cpp @@ -24,7 +24,7 @@ namespace example_processes_t3 { class NesterovARunFuncTestsProcesses3 : public ppc::util::BaseRunFuncTests { public: static std::string PrintTestParam(const TestType &test_param) { - return std::to_string(std::get<0>(test_param)) + "_" + std::get<1>(test_param); + return std::to_string(test_param.value) + "_" + test_param.name; } protected: @@ -60,7 +60,7 @@ class NesterovARunFuncTestsProcesses3 : public ppc::util::BaseRunFuncTests kTestParam = {std::make_tuple(3, "3"), std::make_tuple(5, "5"), std::make_tuple(7, "7")}; +const std::array kTestParam = { + {{.value = 3, .name = "3"}, {.value = 5, .name = "5"}, {.value = 7, .name = "7"}}}; const auto kTestTasksList = std::tuple_cat( ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_example, "processes.t3"), diff --git a/tasks/example/processes/t3/tests/performance/main.cpp b/tasks/example/processes/t3/tests/performance/main.cpp index cc4d2a63c..80ee80f19 100644 --- a/tasks/example/processes/t3/tests/performance/main.cpp +++ b/tasks/example/processes/t3/tests/performance/main.cpp @@ -15,7 +15,7 @@ class ExampleRunPerfTestProcesses3 : public ppc::util::BaseRunPerfTests 0) && (GetOutput() == 0); + return (GetInput() > 0) && (GetMutableOutput() == 0); } bool NesterovATestTaskALL::PreProcessingImpl() { - GetOutput() = 2 * GetInput(); - return GetOutput() > 0; + GetMutableOutput() = 2 * GetInput(); + return GetMutableOutput() > 0; } bool NesterovATestTaskALL::RunImpl() { @@ -33,15 +29,15 @@ bool NesterovATestTaskALL::RunImpl() { for (InType j = 0; j < GetInput(); j++) { for (InType k = 0; k < GetInput(); k++) { std::vector tmp(i + j + k, 1); - GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); - GetOutput() -= i + j + k; + GetMutableOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); + GetMutableOutput() -= i + j + k; } } } const int num_threads = ppc::util::GetNumThreads(); { - GetOutput() *= num_threads; + GetMutableOutput() *= num_threads; int rank = -1; MPI_Comm_rank(MPI_COMM_WORLD, &rank); @@ -50,36 +46,36 @@ bool NesterovATestTaskALL::RunImpl() { #pragma omp parallel default(none) shared(counter) num_threads(ppc::util::GetNumThreads()) counter++; - GetOutput() /= counter; + GetMutableOutput() /= counter; } else { - GetOutput() /= num_threads; + GetMutableOutput() /= num_threads; } } { - GetOutput() *= num_threads; + GetMutableOutput() *= num_threads; std::vector threads(num_threads); std::atomic counter(0); for (std::thread &thread : threads) { thread = std::thread([&counter]() -> void { counter++; }); thread.join(); } - GetOutput() /= counter; + GetMutableOutput() /= counter; } { - GetOutput() *= num_threads; + GetMutableOutput() *= num_threads; std::atomic counter(0); tbb::parallel_for(0, ppc::util::GetNumThreads(), [&](int /*i*/) -> void { counter++; }); - GetOutput() /= counter; + GetMutableOutput() /= counter; } MPI_Barrier(MPI_COMM_WORLD); - return GetOutput() > 0; + return GetMutableOutput() > 0; } bool NesterovATestTaskALL::PostProcessingImpl() { - GetOutput() -= GetInput(); - return GetOutput() > 0; + GetMutableOutput() -= GetInput(); + return GetMutableOutput() > 0; } } // namespace example_threads diff --git a/tasks/example/threads/omp/src/ops_omp.cpp b/tasks/example/threads/omp/src/ops_omp.cpp index c06c01a22..e7206adfc 100644 --- a/tasks/example/threads/omp/src/ops_omp.cpp +++ b/tasks/example/threads/omp/src/ops_omp.cpp @@ -9,19 +9,15 @@ namespace example_threads { -NesterovATestTaskOMP::NesterovATestTaskOMP(const InType &in) { - SetTypeOfTask(GetStaticTypeOfTask()); - GetInput() = in; - GetOutput() = 0; -} +NesterovATestTaskOMP::NesterovATestTaskOMP(const InType &in) : BaseTask(in) {} bool NesterovATestTaskOMP::ValidationImpl() { - return (GetInput() > 0) && (GetOutput() == 0); + return (GetInput() > 0) && (GetMutableOutput() == 0); } bool NesterovATestTaskOMP::PreProcessingImpl() { - GetOutput() = 2 * GetInput(); - return GetOutput() > 0; + GetMutableOutput() = 2 * GetInput(); + return GetMutableOutput() > 0; } bool NesterovATestTaskOMP::RunImpl() { @@ -29,26 +25,26 @@ bool NesterovATestTaskOMP::RunImpl() { for (InType j = 0; j < GetInput(); j++) { for (InType k = 0; k < GetInput(); k++) { std::vector tmp(i + j + k, 1); - GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); - GetOutput() -= i + j + k; + GetMutableOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); + GetMutableOutput() -= i + j + k; } } } const int num_threads = ppc::util::GetNumThreads(); - GetOutput() *= num_threads; + GetMutableOutput() *= num_threads; std::atomic counter(0); #pragma omp parallel default(none) shared(counter) num_threads(ppc::util::GetNumThreads()) counter++; - GetOutput() /= counter; - return GetOutput() > 0; + GetMutableOutput() /= counter; + return GetMutableOutput() > 0; } bool NesterovATestTaskOMP::PostProcessingImpl() { - GetOutput() -= GetInput(); - return GetOutput() > 0; + GetMutableOutput() -= GetInput(); + return GetMutableOutput() > 0; } } // namespace example_threads diff --git a/tasks/example/threads/seq/src/ops_seq.cpp b/tasks/example/threads/seq/src/ops_seq.cpp index 7198ba1ae..0bae2acf1 100644 --- a/tasks/example/threads/seq/src/ops_seq.cpp +++ b/tasks/example/threads/seq/src/ops_seq.cpp @@ -8,19 +8,15 @@ namespace example_threads { -NesterovATestTaskSEQ::NesterovATestTaskSEQ(const InType &in) { - SetTypeOfTask(GetStaticTypeOfTask()); - GetInput() = in; - GetOutput() = 0; -} +NesterovATestTaskSEQ::NesterovATestTaskSEQ(const InType &in) : BaseTask(in) {} bool NesterovATestTaskSEQ::ValidationImpl() { - return (GetInput() > 0) && (GetOutput() == 0); + return (GetInput() > 0) && (GetMutableOutput() == 0); } bool NesterovATestTaskSEQ::PreProcessingImpl() { - GetOutput() = 2 * GetInput(); - return GetOutput() > 0; + GetMutableOutput() = 2 * GetInput(); + return GetMutableOutput() > 0; } bool NesterovATestTaskSEQ::RunImpl() { @@ -32,14 +28,14 @@ bool NesterovATestTaskSEQ::RunImpl() { for (InType j = 0; j < GetInput(); j++) { for (InType k = 0; k < GetInput(); k++) { std::vector tmp(i + j + k, 1); - GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); - GetOutput() -= i + j + k; + GetMutableOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); + GetMutableOutput() -= i + j + k; } } } const int num_threads = ppc::util::GetNumThreads(); - GetOutput() *= num_threads; + GetMutableOutput() *= num_threads; int counter = 0; for (int i = 0; i < num_threads; i++) { @@ -47,14 +43,14 @@ bool NesterovATestTaskSEQ::RunImpl() { } if (counter != 0) { - GetOutput() /= counter; + GetMutableOutput() /= counter; } - return GetOutput() > 0; + return GetMutableOutput() > 0; } bool NesterovATestTaskSEQ::PostProcessingImpl() { - GetOutput() -= GetInput(); - return GetOutput() > 0; + GetMutableOutput() -= GetInput(); + return GetMutableOutput() > 0; } } // namespace example_threads diff --git a/tasks/example/threads/stl/src/ops_stl.cpp b/tasks/example/threads/stl/src/ops_stl.cpp index 9465031ea..152455bbf 100644 --- a/tasks/example/threads/stl/src/ops_stl.cpp +++ b/tasks/example/threads/stl/src/ops_stl.cpp @@ -10,19 +10,15 @@ namespace example_threads { -NesterovATestTaskSTL::NesterovATestTaskSTL(const InType &in) { - SetTypeOfTask(GetStaticTypeOfTask()); - GetInput() = in; - GetOutput() = 0; -} +NesterovATestTaskSTL::NesterovATestTaskSTL(const InType &in) : BaseTask(in) {} bool NesterovATestTaskSTL::ValidationImpl() { - return (GetInput() > 0) && (GetOutput() == 0); + return (GetInput() > 0) && (GetMutableOutput() == 0); } bool NesterovATestTaskSTL::PreProcessingImpl() { - GetOutput() = 2 * GetInput(); - return GetOutput() > 0; + GetMutableOutput() = 2 * GetInput(); + return GetMutableOutput() > 0; } bool NesterovATestTaskSTL::RunImpl() { @@ -30,15 +26,15 @@ bool NesterovATestTaskSTL::RunImpl() { for (InType j = 0; j < GetInput(); j++) { for (InType k = 0; k < GetInput(); k++) { std::vector tmp(i + j + k, 1); - GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); - GetOutput() -= i + j + k; + GetMutableOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); + GetMutableOutput() -= i + j + k; } } } const int num_threads = ppc::util::GetNumThreads(); std::vector threads(num_threads); - GetOutput() *= num_threads; + GetMutableOutput() *= num_threads; std::atomic counter(0); for (std::thread &thread : threads) { @@ -46,13 +42,13 @@ bool NesterovATestTaskSTL::RunImpl() { thread.join(); } - GetOutput() /= counter; - return GetOutput() > 0; + GetMutableOutput() /= counter; + return GetMutableOutput() > 0; } bool NesterovATestTaskSTL::PostProcessingImpl() { - GetOutput() -= GetInput(); - return GetOutput() > 0; + GetMutableOutput() -= GetInput(); + return GetMutableOutput() > 0; } } // namespace example_threads diff --git a/tasks/example/threads/tbb/src/ops_tbb.cpp b/tasks/example/threads/tbb/src/ops_tbb.cpp index 7d7f0787f..58b246f9f 100644 --- a/tasks/example/threads/tbb/src/ops_tbb.cpp +++ b/tasks/example/threads/tbb/src/ops_tbb.cpp @@ -12,19 +12,15 @@ namespace example_threads { -NesterovATestTaskTBB::NesterovATestTaskTBB(const InType &in) { - SetTypeOfTask(GetStaticTypeOfTask()); - GetInput() = in; - GetOutput() = 0; -} +NesterovATestTaskTBB::NesterovATestTaskTBB(const InType &in) : BaseTask(in) {} bool NesterovATestTaskTBB::ValidationImpl() { - return (GetInput() > 0) && (GetOutput() == 0); + return (GetInput() > 0) && (GetMutableOutput() == 0); } bool NesterovATestTaskTBB::PreProcessingImpl() { - GetOutput() = 2 * GetInput(); - return GetOutput() > 0; + GetMutableOutput() = 2 * GetInput(); + return GetMutableOutput() > 0; } bool NesterovATestTaskTBB::RunImpl() { @@ -32,25 +28,25 @@ bool NesterovATestTaskTBB::RunImpl() { for (InType j = 0; j < GetInput(); j++) { for (InType k = 0; k < GetInput(); k++) { std::vector tmp(i + j + k, 1); - GetOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); - GetOutput() -= i + j + k; + GetMutableOutput() += std::accumulate(tmp.begin(), tmp.end(), 0); + GetMutableOutput() -= i + j + k; } } } const int num_threads = ppc::util::GetNumThreads(); - GetOutput() *= num_threads; + GetMutableOutput() *= num_threads; std::atomic counter(0); tbb::parallel_for(0, ppc::util::GetNumThreads(), [&](int /*i*/) -> void { counter++; }); - GetOutput() /= counter; - return GetOutput() > 0; + GetMutableOutput() /= counter; + return GetMutableOutput() > 0; } bool NesterovATestTaskTBB::PostProcessingImpl() { - GetOutput() -= GetInput(); - return GetOutput() > 0; + GetMutableOutput() -= GetInput(); + return GetMutableOutput() > 0; } } // namespace example_threads diff --git a/tasks/example/threads/tests/functional/main.cpp b/tasks/example/threads/tests/functional/main.cpp index 68cfd7201..d4beec12b 100644 --- a/tasks/example/threads/tests/functional/main.cpp +++ b/tasks/example/threads/tests/functional/main.cpp @@ -27,7 +27,7 @@ namespace example_threads { class NesterovARunFuncTestsThreads : public ppc::util::BaseRunFuncTests { public: static std::string PrintTestParam(const TestType &test_param) { - return std::to_string(std::get<0>(test_param)) + "_" + std::get<1>(test_param); + return std::to_string(test_param.value) + "_" + test_param.name; } protected: @@ -63,7 +63,7 @@ class NesterovARunFuncTestsThreads : public ppc::util::BaseRunFuncTests kTestParam = {std::make_tuple(3, "3"), std::make_tuple(5, "5"), std::make_tuple(7, "7")}; +const std::array kTestParam = { + {{.value = 3, .name = "3"}, {.value = 5, .name = "5"}, {.value = 7, .name = "7"}}}; const auto kTestTasksList = std::tuple_cat(ppc::util::AddFuncTask(kTestParam, PPC_SETTINGS_example, "threads"), diff --git a/tasks/example/threads/tests/performance/main.cpp b/tasks/example/threads/tests/performance/main.cpp index 939305f75..0c3b4e347 100644 --- a/tasks/example/threads/tests/performance/main.cpp +++ b/tasks/example/threads/tests/performance/main.cpp @@ -18,7 +18,7 @@ class ExampleRunPerfTestThreads : public ppc::util::BaseRunPerfTests