Skip to content
Merged
22 changes: 22 additions & 0 deletions tasks/telnov_a_integral_rectangle/tbb/include/ops_tbb.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "../../modules/task/include/task.hpp"
#include "telnov_a_integral_rectangle/common/include/common.hpp"

namespace telnov_a_integral_rectangle {

class TelnovAIntegralRectangleTBB : public BaseTask {
public:
static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() {
return ppc::task::TypeOfTask::kTBB;
}
explicit TelnovAIntegralRectangleTBB(const InType &in);

private:
bool ValidationImpl() override;
bool PreProcessingImpl() override;
bool RunImpl() override;
bool PostProcessingImpl() override;
};

} // namespace telnov_a_integral_rectangle
65 changes: 65 additions & 0 deletions tasks/telnov_a_integral_rectangle/tbb/src/ops_tbb.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "telnov_a_integral_rectangle/tbb/include/ops_tbb.hpp"

#include <cmath>
#include <cstdint>

#include "oneapi/tbb/blocked_range.h"
#include "oneapi/tbb/parallel_reduce.h"
#include "telnov_a_integral_rectangle/common/include/common.hpp"

namespace telnov_a_integral_rectangle {

TelnovAIntegralRectangleTBB::TelnovAIntegralRectangleTBB(const InType &in) {
SetTypeOfTask(GetStaticTypeOfTask());
GetInput() = in;
GetOutput() = 0;
}

bool TelnovAIntegralRectangleTBB::ValidationImpl() {
return GetInput().first > 0 && GetInput().second > 0;
}

bool TelnovAIntegralRectangleTBB::PreProcessingImpl() {
GetOutput() = 0.0;
return true;
}

bool TelnovAIntegralRectangleTBB::RunImpl() {
const int n = GetInput().first;
const int d = GetInput().second;

const double a = 0.0;
const double b = 1.0;
const double h = (b - a) / static_cast<double>(n);

const auto total_points = static_cast<int64_t>(std::pow(n, d));

const double result =
oneapi::tbb::parallel_reduce(oneapi::tbb::blocked_range<int64_t>(0, total_points), 0.0,
[n, d, a, h](const oneapi::tbb::blocked_range<int64_t> &range, double local_sum) {
for (int64_t idx = range.begin(); idx != range.end(); ++idx) {
int64_t tmp = idx;
double f_value = 0.0;

for (int dim = 0; dim < d; ++dim) {
const int coord_index = static_cast<int>(tmp % n);
tmp /= n;

const double x = a + ((static_cast<double>(coord_index) + 0.5) * h);
f_value += x;
}

local_sum += f_value;
}
return local_sum;
}, [](double lhs, double rhs) { return lhs + rhs; });

GetOutput() = result * std::pow(h, d);
return true;
}

bool TelnovAIntegralRectangleTBB::PostProcessingImpl() {
return true;
}

} // namespace telnov_a_integral_rectangle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "telnov_a_integral_rectangle/common/include/common.hpp"
#include "telnov_a_integral_rectangle/omp/include/ops_omp.hpp"
#include "telnov_a_integral_rectangle/seq/include/ops_seq.hpp"
#include "telnov_a_integral_rectangle/tbb/include/ops_tbb.hpp"
#include "util/include/func_test_util.hpp"
#include "util/include/util.hpp"

Expand Down Expand Up @@ -62,7 +63,8 @@ const std::array<TestType, 8> kTestParam = {

const auto kTestTasksList = std::tuple_cat(
ppc::util::AddFuncTask<TelnovAIntegralRectangleSEQ, InType>(kTestParam, PPC_SETTINGS_telnov_a_integral_rectangle),
ppc::util::AddFuncTask<TelnovAIntegralRectangleOMP, InType>(kTestParam, PPC_SETTINGS_telnov_a_integral_rectangle));
ppc::util::AddFuncTask<TelnovAIntegralRectangleOMP, InType>(kTestParam, PPC_SETTINGS_telnov_a_integral_rectangle),
ppc::util::AddFuncTask<TelnovAIntegralRectangleTBB, InType>(kTestParam, PPC_SETTINGS_telnov_a_integral_rectangle));

const auto kGtestValues = ppc::util::ExpandToValues(kTestTasksList);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "telnov_a_integral_rectangle/common/include/common.hpp"
#include "telnov_a_integral_rectangle/omp/include/ops_omp.hpp"
#include "telnov_a_integral_rectangle/seq/include/ops_seq.hpp"
#include "telnov_a_integral_rectangle/tbb/include/ops_tbb.hpp"
#include "util/include/perf_test_util.hpp"

namespace telnov_a_integral_rectangle {
Expand Down Expand Up @@ -41,7 +42,10 @@ const auto kSeqPerfTasks =
const auto kOmpPerfTasks =
ppc::util::MakeAllPerfTasks<InType, TelnovAIntegralRectangleOMP>(PPC_SETTINGS_telnov_a_integral_rectangle);

const auto kAllPerfTasks = std::tuple_cat(kSeqPerfTasks, kOmpPerfTasks);
const auto kTbbPerfTasks =
ppc::util::MakeAllPerfTasks<InType, TelnovAIntegralRectangleTBB>(PPC_SETTINGS_telnov_a_integral_rectangle);

const auto kAllPerfTasks = std::tuple_cat(kSeqPerfTasks, kOmpPerfTasks, kTbbPerfTasks);

const auto kGtestValues = ppc::util::TupleToGTestValues(kAllPerfTasks);

Expand Down
Loading