Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b400b72
Add test build by Timur
Tsinev Dec 24, 2025
304ad3d
Fix tests Timur Sinev
Tsinev Dec 24, 2025
2064183
Fix tests Timur Sinev
Tsinev Dec 24, 2025
64537b7
Update report.md
Tsinev Dec 24, 2025
04bc90c
Update report.md
Tsinev Dec 24, 2025
046f00d
Update report.md
Tsinev Dec 24, 2025
664ae0c
Update info.json
Tsinev Dec 24, 2025
af31c23
3add
Tsinev Dec 24, 2025
5acf7ca
fix pre commit1
Tsinev Dec 24, 2025
ac1ea74
fix pre commit1
Tsinev Dec 24, 2025
6c04953
fix pre commit2
Tsinev Dec 24, 2025
365f709
fix pre commit3
Tsinev Dec 24, 2025
bb7c8ff
fasfsadasd
Tsinev Dec 24, 2025
5e0ea13
Laba2
Tsinev Dec 24, 2025
441fbda
Pre-commit-plssssssintegral
Tsinev Dec 25, 2025
30b9d5b
Pre-commit-plssssssintegral4
Tsinev Dec 25, 2025
0963f09
Pre-commit-plssssssintegral4
Tsinev Dec 25, 2025
b4c7508
can you work pls???
Tsinev Dec 25, 2025
4cd8660
can you work pls???
Tsinev Dec 25, 2025
622fc67
can you work pls???
Tsinev Dec 25, 2025
18bd4c7
can you work pls1
Tsinev Dec 25, 2025
4d248cb
can you work pls???
Tsinev Dec 25, 2025
3002d16
can you work pls???
Tsinev Dec 25, 2025
93d960f
can you work pls???
Tsinev Dec 25, 2025
ffbb61c
can you work pls???
Tsinev Dec 25, 2025
8c21ca0
can you work pls???
Tsinev Dec 25, 2025
af29998
can you work pls???
Tsinev Dec 25, 2025
c95b6b6
can you work pls? yje ystal
Tsinev Dec 25, 2025
acacc28
can you work pls? yje ystal
Tsinev Dec 25, 2025
e9ecd7e
can you work pls? yje ystal
Tsinev Dec 25, 2025
9f6e979
idk why
Tsinev Dec 25, 2025
a4688fa
update
Tsinev Dec 25, 2025
a4fb313
update1
Tsinev Dec 25, 2025
e44bc29
update1
Tsinev Dec 25, 2025
061e3cc
update1
Tsinev Dec 25, 2025
c035a1f
new
Tsinev Dec 25, 2025
0b7f140
new1
Tsinev Dec 25, 2025
1c9a93c
new2
Tsinev Dec 25, 2025
97fefe7
new3
Tsinev Dec 25, 2025
4c35494
LAST TRY IDK WHO CAN HELP ME???????????
Tsinev Dec 25, 2025
56e018d
gg
Tsinev Dec 25, 2025
15dd1da
gg1
Tsinev Dec 25, 2025
1bdcbb2
gg2
Tsinev Dec 25, 2025
14b7491
gg3
Tsinev Dec 25, 2025
4affe65
Last dance(
Tsinev Dec 25, 2025
af9765e
Update info.json
Tsinev Dec 27, 2025
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
70 changes: 70 additions & 0 deletions tasks/timur_a_integral/common/include/common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#pragma once

#include <cmath>
#include <functional>
#include <string>
#include <tuple>

#include "task/include/task.hpp"

namespace timur_a_integral {

struct TaskData {
int n_steps;
int func_id;
double x1, x2;
double y1, y2;

bool operator==(const TaskData &other) const {
return n_steps == other.n_steps && func_id == other.func_id && std::abs(x1 - other.x1) < 1e-9 &&
std::abs(x2 - other.x2) < 1e-9 && std::abs(y1 - other.y1) < 1e-9 && std::abs(y2 - other.y2) < 1e-9;
}
};

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

inline std::function<double(double, double)> GetFunction(int id) {
switch (id) {
case 0:
return [](double x, double y) { return x + y; };
case 1:
return [](double x, double y) { return (x * x) + (y * y); };
case 2:
return [](double x, double y) { return std::sin(x) * std::cos(y); };
case 3:
return [](double x, double y) { return std::exp(x + y); };
case 4:
return [](double x, double y) { return std::sqrt((x * x) + (y * y)); };
default:
return [](double x, double y) {
(void)x;
(void)y;
return 1.0;
};
}
}

inline double GetExactIntegral(const TaskData &data) {
switch (data.func_id) {
case 0:
return (0.5 * ((data.x2 * data.x2) - (data.x1 * data.x1)) * (data.y2 - data.y1)) +
(0.5 * ((data.y2 * data.y2) - (data.y1 * data.y1)) * (data.x2 - data.x1));
case 1:
return ((1.0 / 3.0) * ((data.x2 * data.x2 * data.x2) - (data.x1 * data.x1 * data.x1)) * (data.y2 - data.y1)) +
((1.0 / 3.0) * ((data.y2 * data.y2 * data.y2) - (data.y1 * data.y1 * data.y1)) * (data.x2 - data.x1));
case 2:
return (std::cos(data.x1) - std::cos(data.x2)) * (std::sin(data.y2) - std::sin(data.y1));
case 3: {
return (std::exp(data.x2) - std::exp(data.x1)) * (std::exp(data.y2) - std::exp(data.y1));
}
case 5: {
return (data.x2 - data.x1) * (data.y2 - data.y1);
}
default:
return 0.0;
}
}
} // namespace timur_a_integral
9 changes: 9 additions & 0 deletions tasks/timur_a_integral/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"student": {
"first_name": "Тимур",
"last_name": "Синев",
"middle_name": "Викторович",
"group_number": "3823Б1ПР5",
"task_number": "3"
}
}
22 changes: 22 additions & 0 deletions tasks/timur_a_integral/mpi/include/ops_mpi.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

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

namespace timur_a_integral {

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

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

} // namespace timur_a_integral
116 changes: 116 additions & 0 deletions tasks/timur_a_integral/mpi/src/ops_mpi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#include "timur_a_integral/mpi/include/ops_mpi.hpp"

#include <mpi.h>

#include <algorithm>
#include <cmath>

#include "timur_a_integral/common/include/common.hpp"

namespace timur_a_integral {

TimurAIntegralMPI::TimurAIntegralMPI(const InType &in) {
SetTypeOfTask(GetStaticTypeOfTask());
GetInput() = in;
}

bool TimurAIntegralMPI::ValidationImpl() {
return GetInput().n_steps > 0 && GetInput().x2 > GetInput().x1 && GetInput().y2 > GetInput().y1;
}

bool TimurAIntegralMPI::PreProcessingImpl() {
GetOutput() = 0.0;
return true;
}
namespace {
template <typename Func>
double RunKernel(const TaskData &data, int rank, int size, const Func &f) {
double hx = (data.x2 - data.x1) / data.n_steps;
double hy = (data.y2 - data.y1) / data.n_steps;

int total_nodes_x = data.n_steps + 1;

int count = total_nodes_x / size;
int remainder = total_nodes_x % size;

int start_i = (rank * count) + std::min(rank, remainder);
int end_i = start_i + count + (rank < remainder ? 1 : 0);

double local_sum = 0.0;

for (int i = start_i; i < end_i; ++i) {
double x = data.x1 + (i * hx);
double weight_x = (i == 0 || i == data.n_steps) ? 0.5 : 1.0;

for (int j = 0; j <= data.n_steps; ++j) {
double y = data.y1 + (j * hy);
double weight_y = (j == 0 || j == data.n_steps) ? 0.5 : 1.0;

local_sum += f(x, y) * weight_x * weight_y;
}
}

return local_sum * hx * hy;
}
} // namespace

bool TimurAIntegralMPI::RunImpl() {
int rank = 0;
int size = 0;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);

TaskData data{};
if (rank == 0) {
data = GetInput();
}

MPI_Bcast(&data.n_steps, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Bcast(&data.func_id, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Bcast(&data.x1, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
MPI_Bcast(&data.x2, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
MPI_Bcast(&data.y1, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
MPI_Bcast(&data.y2, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);

double local_result = 0.0;

switch (data.func_id) {
case 0:
local_result = RunKernel(data, rank, size, [](double x, double y) { return x + y; });
break;
case 1:
local_result = RunKernel(data, rank, size, [](double x, double y) { return (x * x) + (y * y); });
break;
case 2:
local_result = RunKernel(data, rank, size, [](double x, double y) { return std::sin(x) * std::cos(y); });
break;
case 3:
local_result = RunKernel(data, rank, size, [](double x, double y) { return std::exp(x + y); });
break;
case 4:
local_result = RunKernel(data, rank, size, [](double x, double y) { return std::sqrt((x * x) + (y * y)); });
break;
default:
local_result = RunKernel(data, rank, size, [](double x, double y) {
(void)x;
(void)y;
return 1.0;
});
break;
}

double global_result = 0.0;
MPI_Reduce(&local_result, &global_result, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);

MPI_Bcast(&global_result, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);

GetOutput() = global_result;

return true;
}

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

} // namespace timur_a_integral
Loading
Loading