Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
66e9238
patch 1.21.0.0.0.1.0.0.0.0.0
Leontin16 Feb 18, 2026
4b25c97
patch 1.21.0.0.0.1.0.0.0.0.0
Leontin16 Feb 18, 2026
4c8b709
patch 1.21.0.0.0.1.0.0.0.0.1
Leontin16 Feb 18, 2026
1248131
patch 1.21.1.0.0.2.0.0.0.0.2
Leontin16 Feb 18, 2026
9ab071b
patch 1.21.1.0.0.2.0.0.0.0.3
Leontin16 Feb 18, 2026
a6effa3
patch 1.21.1.0.0.2.0.0.0.0.4
Leontin16 Feb 18, 2026
b20f71b
patch 1.21.1.0.0.2.0.0.0.0.5
Leontin16 Feb 18, 2026
a7368a9
patch 1.21.1.0.0.2.0.0.0.0.6
Leontin16 Feb 18, 2026
c905738
patch 1.21.2.0.0.2.0.0.0.0.6
Leontin16 Feb 19, 2026
2427c24
patch 1.21.2.0.0.2.0.0.0.0.7
Leontin16 Feb 19, 2026
292fede
patch 1.21.2.0.0.2.0.0.0.0.8
Leontin16 Feb 19, 2026
7ac4054
patch 1.21.2.0.0.2.0.0.0.0.9
Leontin16 Feb 19, 2026
30213b7
patch 1.21.2.0.0.2.0.0.0.0.10
Leontin16 Feb 21, 2026
c65eafd
patch 1.21.0.1.0.0.0
Leontin16 Mar 2, 2026
ea40a10
patch 1.21.0.1.0.0.1
Leontin16 Mar 2, 2026
f5d84d5
patch 1.21.0.1.0.0.2
Leontin16 Mar 2, 2026
4c2f609
patch 1.21.0.1.0.0.3
Leontin16 Mar 2, 2026
60d8178
patch 1.21.0.1.0.0.4
Leontin16 Mar 2, 2026
13fbcc3
patch 1.21.0.1.0.0.5
Leontin16 Mar 2, 2026
fa50b3e
patch 1.21.0.1.0.0.5
Leontin16 Mar 2, 2026
672ab6a
patch 1.21.0.1.0.0.5
Leontin16 Mar 2, 2026
4df3372
patch 1.21.1.1.0.0.5
Leontin16 Mar 2, 2026
6d153ad
patch 1.21.1.1.0.0.6
Leontin16 Mar 3, 2026
c8fefbe
patch 1.21.2.1.0.0.6
Leontin16 Mar 3, 2026
de706c6
patch 1.21.3.1.0.0.6
Leontin16 Mar 3, 2026
5846a32
patch 1.21.3.1.0.0.7
Leontin16 Mar 3, 2026
05f61cf
patch 1.21.3.1.0.0.8
Leontin16 Mar 3, 2026
486c5f6
patch 1.21.3.1.0.0.9
Leontin16 Mar 3, 2026
717bd10
patch 1.21.3.1.0.0.10
Leontin16 Mar 3, 2026
c9535a5
patch 1.21.3.1.0.0.11
Leontin16 Mar 3, 2026
ba96a9c
patch 1.21.3.1.0.0.11
Leontin16 Mar 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tasks/gasenin_l_djstra_omp/common/include/common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include <string>
#include <tuple>

#include "task/include/task.hpp"

namespace gasenin_l_djstra {

using InType = int;
using OutType = int;
using TestType = std::tuple<int, std::string>;
using BaseTask = ppc::task::Task<InType, OutType>;

} // namespace gasenin_l_djstra
9 changes: 9 additions & 0 deletions tasks/gasenin_l_djstra_omp/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"student": {
"first_name": "Леонид",
"group_number": "3823Б1ФИ3",
"last_name": "Гасенин",
"middle_name": "Вячеславович",
"task_number": "1"
}
}
27 changes: 27 additions & 0 deletions tasks/gasenin_l_djstra_omp/omp/include/ops_omp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include <vector>

#include "gasenin_l_djstra_omp/common/include/common.hpp"
#include "task/include/task.hpp"

namespace gasenin_l_djstra {

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

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

std::vector<InType> dist_;
std::vector<char> visited_;
};

} // namespace gasenin_l_djstra
155 changes: 155 additions & 0 deletions tasks/gasenin_l_djstra_omp/omp/src/ops_omp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
#include "gasenin_l_djstra_omp/omp/include/ops_omp.hpp"

#include <omp.h>

#include <algorithm>
#include <cstdint>
#include <cstdlib>
#include <limits>
#include <vector>

#include "gasenin_l_djstra_omp/common/include/common.hpp"

namespace gasenin_l_djstra {

namespace {

int GetNumThreads() {
int num_threads = 1;

#pragma omp parallel default(none) shared(num_threads)
{
#pragma omp single
num_threads = omp_get_num_threads();
}

return num_threads;
}

InType FindGlobalVertexOMP(const InType n, const InType inf, std::vector<InType> &dist, std::vector<char> &visited,
const int num_threads) {
std::vector<InType> local_min(num_threads, inf);
std::vector<InType> local_vertex(num_threads, -1);

InType global_vertex = -1;

#pragma omp parallel default(none) shared(n, inf, dist, visited, local_min, local_vertex, global_vertex, num_threads)
{
const int thread_id = omp_get_thread_num();

InType thread_min = inf;
InType thread_vertex = -1;

#pragma omp for nowait
for (int index = 0; index < n; ++index) {
if (visited[index] == 0 && dist[index] < thread_min) {
thread_min = dist[index];
thread_vertex = index;
}
}

local_min[thread_id] = thread_min;
local_vertex[thread_id] = thread_vertex;

#pragma omp barrier

#pragma omp single
{
InType global_min = inf;

for (int thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
if (local_min[thread_idx] < global_min) {
global_min = local_min[thread_idx];
global_vertex = local_vertex[thread_idx];
}
}

if (global_vertex != -1 && global_min != inf) {
visited[global_vertex] = 1;
} else {
global_vertex = -1;
}
}
}

return global_vertex;
}

void RelaxEdgesOMP(const InType n, const InType inf, const InType global_vertex, std::vector<InType> &dist,
std::vector<char> &visited) {
#pragma omp parallel for default(none) shared(n, inf, global_vertex, dist, visited)
for (int vertex = 0; vertex < n; ++vertex) {
if (visited[vertex] == 0 && vertex != global_vertex) {
const InType weight = std::abs(global_vertex - vertex);

if (dist[global_vertex] != inf) {
const InType new_dist = dist[global_vertex] + weight;
dist[vertex] = std::min(dist[vertex], new_dist);
}
}
}
}

int64_t CalculateTotalSumOMP(const InType n, const InType inf, std::vector<InType> &dist) {
int64_t total_sum = 0;

#pragma omp parallel for reduction(+ : total_sum) default(none) shared(n, inf, dist)
for (int i = 0; i < n; ++i) {
if (dist[i] != inf) {
total_sum += dist[i];
}
}

return total_sum;
}

} // namespace

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

bool GaseninLDjstraOMP::ValidationImpl() {
return GetInput() > 0;
}

bool GaseninLDjstraOMP::PreProcessingImpl() {
const InType n = GetInput();
const InType inf = std::numeric_limits<InType>::max();

dist_.assign(n, inf);
visited_.assign(n, 0);

dist_[0] = 0;
return true;
}

bool GaseninLDjstraOMP::RunImpl() {
const InType n = GetInput();
const InType inf = std::numeric_limits<InType>::max();

const int num_threads = GetNumThreads();

for (int iteration = 0; iteration < n; ++iteration) {
InType global_vertex = FindGlobalVertexOMP(n, inf, dist_, visited_, num_threads);

if (global_vertex == -1) {
break;
}

RelaxEdgesOMP(n, inf, global_vertex, dist_, visited_);
}

const int64_t total_sum = CalculateTotalSumOMP(n, inf, dist_);

GetOutput() = static_cast<OutType>(total_sum);
return true;
}

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

} // namespace gasenin_l_djstra
10 changes: 10 additions & 0 deletions tasks/gasenin_l_djstra_omp/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"tasks": {
"all": "enabled",
"omp": "enabled",
"seq": "enabled",
"stl": "enabled",
"tbb": "enabled"
},
"tasks_type": "threads"
}
59 changes: 59 additions & 0 deletions tasks/gasenin_l_djstra_omp/tests/functional/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <gtest/gtest.h>

#include <array>
#include <cstddef>
#include <string>
#include <tuple>

#include "gasenin_l_djstra_omp/common/include/common.hpp"
#include "gasenin_l_djstra_omp/omp/include/ops_omp.hpp"
#include "util/include/func_test_util.hpp"
#include "util/include/util.hpp"

namespace gasenin_l_djstra {

class GaseninLDjstraOmpFuncTests : public ppc::util::BaseRunFuncTests<InType, OutType, TestType> {
public:
static std::string PrintTestParam(const TestType &test_param) {
return std::to_string(std::get<0>(test_param)) + "_" + std::get<1>(test_param);
}

protected:
void SetUp() override {
TestType params = std::get<static_cast<std::size_t>(ppc::util::GTestParamIndex::kTestParams)>(GetParam());
input_data_ = std::get<0>(params);
expected_output_ = input_data_ * (input_data_ - 1) / 2;
}

bool CheckTestOutputData(OutType &output_data) final {
return expected_output_ == output_data;
}

InType GetTestInputData() final {
return input_data_;
}

private:
InType input_data_ = 0;
OutType expected_output_ = 0;
};

namespace {

TEST_P(GaseninLDjstraOmpFuncTests, DijkstraFromParams) {
ExecuteTest(GetParam());
}

const std::array<TestType, 3> kTestParam = {std::make_tuple(3, "3"), std::make_tuple(5, "5"), std::make_tuple(7, "7")};

const auto kTestTasksList =
std::tuple_cat(ppc::util::AddFuncTask<GaseninLDjstraOMP, InType>(kTestParam, PPC_SETTINGS_gasenin_l_djstra_omp));

const auto kGtestValues = ppc::util::ExpandToValues(kTestTasksList);
const auto kPerfTestName = GaseninLDjstraOmpFuncTests::PrintFuncTestName<GaseninLDjstraOmpFuncTests>;

INSTANTIATE_TEST_SUITE_P(DijkstraOmpTests, GaseninLDjstraOmpFuncTests, kGtestValues, kPerfTestName);

} // namespace

} // namespace gasenin_l_djstra
40 changes: 40 additions & 0 deletions tasks/gasenin_l_djstra_omp/tests/performance/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <gtest/gtest.h>

#include "gasenin_l_djstra_omp/common/include/common.hpp"
#include "gasenin_l_djstra_omp/omp/include/ops_omp.hpp"
#include "util/include/perf_test_util.hpp"

namespace gasenin_l_djstra {

class GaseninLDjstraOmpPerfTests : public ppc::util::BaseRunPerfTests<InType, OutType> {
InType input_data_{};
OutType expected_output_{};

void SetUp() override {
input_data_ = 200;
expected_output_ = input_data_ * (input_data_ - 1) / 2;
}

bool CheckTestOutputData(OutType &output_data) final {
return expected_output_ == output_data;
}

InType GetTestInputData() final {
return input_data_;
}
};

TEST_P(GaseninLDjstraOmpPerfTests, RunPerfModes) {
ExecuteTest(GetParam());
}

namespace {

const auto kAllPerfTasks = ppc::util::MakeAllPerfTasks<InType, GaseninLDjstraOMP>(PPC_SETTINGS_gasenin_l_djstra_omp);
const auto kGtestValues = ppc::util::TupleToGTestValues(kAllPerfTasks);
const auto kPerfTestName = GaseninLDjstraOmpPerfTests::CustomPerfTestName;

INSTANTIATE_TEST_SUITE_P(DjkstraOmpPerf, GaseninLDjstraOmpPerfTests, kGtestValues, kPerfTestName);

} // namespace
} // namespace gasenin_l_djstra
Loading