Skip to content

Commit 2f3b49e

Browse files
authored
Сизов Дмитрий. Технология SEQ-MPI. Алгоритм глобального поиска (Стронгина) для одномерных задач оптимизации. Распараллеливание по характеристикам. Вариант 11. (#149)
## Description - **Task**: Алгоритм глобального поиска (Стронгина) для одномерных задач оптимизации. Распараллеливание по характеристикам / Global Search Algorithm (Strongin) for One-Dimensional Optimization Problems. Parallelization by Characteristics. - **Variant**: 11 - **Technology**: SEQ+MPI - **Description:** - The solution is based on **Strongin’s global search algorithm**, a deterministic method for one-dimensional global optimization. The algorithm iteratively refines a closed interval by evaluating the objective function at selected points and choosing the most promising interval according to the Strongin characteristic. - In the sequential version, the algorithm maintains an ordered set of sampled points, computes an adaptive Lipschitz-like estimate, and selects the interval with the maximum characteristic for further refinement. The process continues until the required accuracy is reached or the iteration limit is exceeded. - The parallel MPI version applies **parallelization by interval characteristics**. At each iteration, the set of intervals is distributed among MPI processes, which compute characteristics locally. The globally best interval is selected using `MPI_Allreduce`, after which a new sampling point is generated and broadcast to all processes. This approach preserves the deterministic behavior of the algorithm while reducing execution time for computationally intensive cases. --- ## Checklist - [x] **CI Status**: All CI jobs (build, tests, report generation) are passing on my branch in my fork - [x] **Task Directory & Naming**: I have created a directory named `<lastName>_<firstInitial>_<short_task_name>` - [x] **Full Task Definition**: I have provided the complete task description in the pull request body. - [x] **clang-format**: My changes pass `clang-format` locally in my fork (no formatting errors) - [x] **clang-tidy**: My changes pass `clang-tidy` locally in my fork (no warnings/errors) - [x] **Functional Tests**: All functional tests are passing locally on my machine - [x] **Performance Tests**: All performance tests are passing locally on my machine - [x] **Branch**: I am working on a branch named exactly as my task directory (e.g., `nesterov_a_vector_sum`), not on `master`. - [x] **Truthful Content**: I confirm that every detail provided in this pull request is accurate and truthful to the best of my knowledge.
1 parent 3a63dfa commit 2f3b49e

11 files changed

Lines changed: 2187 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#pragma once
2+
3+
#include <functional>
4+
#include <string>
5+
6+
#include "task/include/task.hpp"
7+
8+
namespace sizov_d_global_search {
9+
10+
using Function = std::function<double(double)>;
11+
12+
struct Problem {
13+
Function func;
14+
double left = 0.0;
15+
double right = 0.0;
16+
double accuracy = 1e-4;
17+
double reliability = 3.0;
18+
int max_iterations = 300;
19+
bool enable_stable_heuristic = true;
20+
bool enable_point_limit = true;
21+
};
22+
23+
struct Solution {
24+
double argmin = 0.0;
25+
double value = 0.0;
26+
int iterations = 0;
27+
bool converged = false;
28+
};
29+
30+
struct TestCase {
31+
std::string name;
32+
Problem problem;
33+
};
34+
35+
static constexpr double kDefaultAccuracy = 1e-4;
36+
static constexpr double kDefaultReliability = 3.0;
37+
static constexpr int kDefaultMaxIterations = 300;
38+
39+
using InType = Problem;
40+
using OutType = Solution;
41+
using TestType = TestCase;
42+
using BaseTask = ppc::task::Task<InType, OutType>;
43+
44+
} // namespace sizov_d_global_search
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[
2+
{
3+
"name": "case_001_linear_inc",
4+
"function": { "expression": "x" },
5+
"problem": { "left": -5.0, "right": 5.0 },
6+
"expected": { "argmins": [-5.0], "value": -5.0 }
7+
},
8+
9+
{
10+
"name": "case_002_linear_dec",
11+
"function": { "expression": "-2*x + 3" },
12+
"problem": { "left": -5.0, "right": 5.0 },
13+
"expected": { "argmins": [5.0], "value": -7.0 }
14+
},
15+
16+
{
17+
"name": "case_003_quadratic",
18+
"function": { "expression": "(x - 2)^2 + 1" },
19+
"problem": { "left": 0.0, "right": 4.0 },
20+
"expected": { "argmins": [2.0], "value": 1.0 }
21+
},
22+
23+
{
24+
"name": "case_004_abs_shift",
25+
"function": { "expression": "abs(x - 1)" },
26+
"problem": { "left": -4.0, "right": 4.0 },
27+
"expected": { "argmins": [1.0], "value": 0.0 }
28+
},
29+
30+
{
31+
"name": "case_005_exp",
32+
"function": { "expression": "exp(x)" },
33+
"problem": { "left": 0.0, "right": 2.0 },
34+
"expected": { "argmins": [0.0], "value": 1.0 }
35+
},
36+
37+
{
38+
"name": "case_006_log_abs_shift",
39+
"function": { "expression": "log(abs(x - 1) + 2)" },
40+
"problem": { "left": -2.0, "right": 4.0 },
41+
"expected": { "argmins": [1.0], "value": 0.6931471805599453 }
42+
}
43+
44+
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"student": {
3+
"first_name": "Дмитрий",
4+
"last_name": "Сизов",
5+
"middle_name": "Игоревич",
6+
"group_number": "3823Б1ФИ2",
7+
"task_number": "3"
8+
}
9+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#pragma once
2+
3+
#include <cstddef>
4+
#include <vector>
5+
6+
#include "sizov_d_global_search/common/include/common.hpp"
7+
#include "task/include/task.hpp"
8+
9+
namespace sizov_d_global_search {
10+
11+
class SizovDGlobalSearchMPI : public BaseTask {
12+
public:
13+
static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() {
14+
return ppc::task::TypeOfTask::kMPI;
15+
}
16+
17+
explicit SizovDGlobalSearchMPI(const InType &in);
18+
19+
private:
20+
bool ValidationImpl() override;
21+
bool PreProcessingImpl() override;
22+
bool RunImpl() override;
23+
bool PostProcessingImpl() override;
24+
25+
struct IntervalChar {
26+
double characteristic = 0.0;
27+
int index = -1;
28+
};
29+
30+
struct InsertMsg {
31+
double x_new = 0.0;
32+
double y_new = 0.0;
33+
int idx = -1;
34+
};
35+
36+
static void GetChunk(std::size_t intervals, int rank, int size, std::size_t &begin, std::size_t &end);
37+
38+
[[nodiscard]] double EstimateM(double reliability, int rank, int size) const;
39+
[[nodiscard]] double Characteristic(std::size_t i, double m) const;
40+
[[nodiscard]] double NewPoint(std::size_t i, double m) const;
41+
42+
[[nodiscard]] IntervalChar ComputeLocalBestInterval(double m, int rank, int size) const;
43+
static int ReduceBestIntervalIndex(const IntervalChar &local, int n, int size);
44+
45+
[[nodiscard]] bool CheckStopByAccuracy(const Problem &p, int best_idx, int rank) const;
46+
47+
void BroadcastState(int rank);
48+
void BroadcastNewPoint(int best_idx, double m, const Problem &p, int rank);
49+
void BroadcastResult(int rank);
50+
51+
static void BroadcastInsertMsg(InsertMsg &msg, int rank);
52+
53+
std::vector<double> x_;
54+
std::vector<double> y_;
55+
56+
double best_x_ = 0.0;
57+
double best_y_ = 0.0;
58+
int iterations_ = 0;
59+
bool converged_ = false;
60+
};
61+
62+
} // namespace sizov_d_global_search

0 commit comments

Comments
 (0)