Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions tasks/konovalov_s_sympson_method2/common/include/common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <functional>
#include <string>
#include <tuple>
#include <vector>

#include "task/include/task.hpp"

namespace konovalov_s_sympson_method2 {

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

} // namespace konovalov_s_sympson_method2
Binary file added tasks/konovalov_s_sympson_method2/data/pic.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions tasks/konovalov_s_sympson_method2/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"student": {
"first_name": "first_name_p",
"last_name": "last_name_p",
"middle_name": "middle_name_p",
"group_number": "2222222_p",
"task_number": "3"
}
}
35 changes: 35 additions & 0 deletions tasks/konovalov_s_sympson_method2/mpi/include/ops_mpi.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include <functional>
#include <vector>

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

namespace konovalov_s_sympson_method2 {

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

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

double ComputePartialIntegral(int start_idx, int end_idx);

std::vector<double> lower_bounds_;
std::vector<double> upper_bounds_;
int num_steps_{};
std::function<double(const std::vector<double> &)> func_;
double result_{};
int start_idx_{};
int end_idx_{};
};

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

#include <mpi.h>

#include <cstddef>
#include <vector>

#include "konovalov_s_sympson_method2/common/include/common.hpp"

namespace konovalov_s_sympson_method2 {

KonovalovSSympsonMethodMPI::KonovalovSSympsonMethodMPI(const InType &in) {
SetTypeOfTask(GetStaticTypeOfTask());
GetInput() = in;
GetOutput() = 0.0;
}

bool KonovalovSSympsonMethodMPI::ValidationImpl() {
// int rank = 0;
// MPI_Comm_rank(MPI_COMM_WORLD, &rank);

// if (rank == 0) {
// const auto &input = GetInput();

// if (input.lower_bounds.empty() || input.upper_bounds.empty()) {
// return false;
// }

// if (input.lower_bounds.size() != input.upper_bounds.size()) {
// return false;
// }

// if (input.num_steps <= 0) {
// return false;
// }

// if (!input.func) {
// return false;
// }

// for (std::size_t idx = 0; idx < input.lower_bounds.size(); ++idx) {
// if (input.lower_bounds[idx] > input.upper_bounds[idx]) {
// return false;
// }
// }
// }

return true;
}

bool KonovalovSSympsonMethodMPI::PreProcessingImpl() {
// int rank = 0;
// int size = 0;
// MPI_Comm_rank(MPI_COMM_WORLD, &rank);
// MPI_Comm_size(MPI_COMM_WORLD, &size);

// int dimensions = 0;
// if (rank == 0) {
// const auto &input = GetInput();
// lower_bounds_ = input.lower_bounds;
// upper_bounds_ = input.upper_bounds;
// num_steps_ = input.num_steps;
// func_ = input.func;
// dimensions = static_cast<int>(lower_bounds_.size());
// }

// MPI_Bcast(&dimensions, 1, MPI_INT, 0, MPI_COMM_WORLD);
// MPI_Bcast(&num_steps_, 1, MPI_INT, 0, MPI_COMM_WORLD);

// if (rank != 0) {
// lower_bounds_.resize(dimensions);
// upper_bounds_.resize(dimensions);
// func_ = GetInput().func;
// }

// MPI_Bcast(lower_bounds_.data(), dimensions, MPI_DOUBLE, 0, MPI_COMM_WORLD);
// MPI_Bcast(upper_bounds_.data(), dimensions, MPI_DOUBLE, 0, MPI_COMM_WORLD);

// int total_points = 1;
// for (int idx = 0; idx < dimensions; ++idx) {
// total_points *= (num_steps_ + 1);
// }

// int base_points_per_proc = total_points / size;
// int remainder = total_points % size;

// std::vector<int> counts(size);
// std::vector<int> displs(size);
// int offset = 0;
// for (int idx = 0; idx < size; ++idx) {
// counts[idx] = base_points_per_proc + (idx < remainder ? 1 : 0);
// displs[idx] = offset;
// offset += counts[idx];
// }

// if (rank == 0) {
// for (int dest = 1; dest < size; ++dest) {
// MPI_Send(&counts[dest], 1, MPI_INT, dest, 0, MPI_COMM_WORLD);
// MPI_Send(&displs[dest], 1, MPI_INT, dest, 1, MPI_COMM_WORLD);
// }
// start_idx_ = displs[0];
// end_idx_ = displs[0] + counts[0];
// } else {
// int local_count = 0;
// int local_displ = 0;
// MPI_Recv(&local_count, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
// MPI_Recv(&local_displ, 1, MPI_INT, 0, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
// start_idx_ = local_displ;
// end_idx_ = local_displ + local_count;
// }

// result_ = 0.0;
return true;
}

// double KonovalovSSympsonMethodMPI::ComputePartialIntegral(int start_idx, int end_idx) {
// std::size_t dimensions = lower_bounds_.size();
// std::vector<double> step_sizes(dimensions);
// for (std::size_t idx = 0; idx < dimensions; ++idx) {
// step_sizes[idx] = (upper_bounds_[idx] - lower_bounds_[idx]) / num_steps_;
// }

// double sum = 0.0;
// std::vector<double> point(dimensions);

// for (int idx = start_idx; idx < end_idx; ++idx) {
// int temp = idx;
// double weight = 1.0;

// for (std::size_t dim = 0; dim < dimensions; ++dim) {
// int grid_idx = temp % (num_steps_ + 1);
// temp /= (num_steps_ + 1);
// point[dim] = lower_bounds_[dim] + (grid_idx * step_sizes[dim]);

// if (grid_idx == 0 || grid_idx == num_steps_) {
// weight *= 0.5;
// }
// }

// sum += weight * func_(point);
// }

// double volume = 1.0;
// for (std::size_t idx = 0; idx < dimensions; ++idx) {
// volume *= step_sizes[idx];
// }

// return sum * volume;
// }

bool KonovalovSSympsonMethodMPI::RunImpl() {
// double local_result = ComputePartialIntegral(start_idx_, end_idx_);

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

// int rank = 0;
// MPI_Comm_rank(MPI_COMM_WORLD, &rank);
// if (rank == 0) {
// result_ = global_result;
// }

return true;
}

bool KonovalovSSympsonMethodMPI::PostProcessingImpl() {
// MPI_Bcast(&result_, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
// GetOutput() = result_;
return true;
}

} // namespace konovalov_s_sympson_method2
Empty file.
27 changes: 27 additions & 0 deletions tasks/konovalov_s_sympson_method2/seq/include/ops_seq.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include <functional>
#include <vector>

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

namespace konovalov_s_sympson_method2 {

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

private:
bool ValidationImpl() override;
bool PreProcessingImpl() override;
bool RunImpl() override;
bool PostProcessingImpl() override;
double GetFunc(double x, double y);
double SimpsonMethod(double a, double b, double c, double d, int n);
};

} // namespace konovalov_s_sympson_method2
59 changes: 59 additions & 0 deletions tasks/konovalov_s_sympson_method2/seq/src/ops_seq.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "konovalov_s_sympson_method2/seq/include/ops_seq.hpp"

#include <cstddef>
#include <vector>

#include "konovalov_s_sympson_method2/common/include/common.hpp"

namespace konovalov_s_sympson_method2 {

KonovalovSSympsonMethodSEQ::KonovalovSSympsonMethodSEQ(const InType &in) {
SetTypeOfTask(GetStaticTypeOfTask());
GetInput() = in;
GetOutput() = 0.0;
}

bool KonovalovSSympsonMethodSEQ::ValidationImpl() {
return GetInput() != std::make_tuple(0.0, 0.0, 0.0, 0.0, 0) && std::get<4>(GetInput()) % 2 == 0;
}

bool KonovalovSSympsonMethodSEQ::PreProcessingImpl() {
return true;
}

double KonovalovSSympsonMethodSEQ::GetFunc(double x, double y) {
return (double)(rand())/RAND_MAX*(10) + std::max(x, y);
}

double KonovalovSSympsonMethodSEQ::SimpsonMethod(double a, double b, double c, double d, int n) {

double h = (b - a) / n;
double k = (d - c) / n;

double x, y, sum = 0;

for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
x = a + i * h;
y = c + j * k;

int coeff = (i == 0 || i == n) ? 1 : (i % 2 == 1 ? 4 : 2);

sum += coeff * GetFunc(x, y);
}
}

return (h * k / 9.0) * sum;
}

bool KonovalovSSympsonMethodSEQ::RunImpl() {
GetOutput() = SimpsonMethod(std::get<0>(GetInput()), std::get<1>(GetInput()), std::get<2>(GetInput()),
std::get<3>(GetInput()), std::get<4>(GetInput()));
return true;
}

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

} // namespace konovalov_s_sympson_method2
7 changes: 7 additions & 0 deletions tasks/konovalov_s_sympson_method2/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"tasks_type": "processes",
"tasks": {
"mpi": "enabled",
"seq": "enabled"
}
}
13 changes: 13 additions & 0 deletions tasks/konovalov_s_sympson_method2/tests/.clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
InheritParentConfig: true

Checks: >
-modernize-loop-convert,
-cppcoreguidelines-avoid-goto,
-cppcoreguidelines-avoid-non-const-global-variables,
-misc-use-anonymous-namespace,
-modernize-use-std-print,
-modernize-type-traits

CheckOptions:
- key: readability-function-cognitive-complexity.Threshold
value: 50 # Relaxed for tests
Loading
Loading