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
16 changes: 16 additions & 0 deletions tasks/shakirova_e_shells_sort_simple/common/include/common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

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

#include "task/include/task.hpp"

namespace shakirova_e_shells_sort_simple {

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

} // namespace shakirova_e_shells_sort_simple
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#include <vector>

namespace shakirova_e_shells_sort_simple {

inline void ShellSortImpl(std::vector<int> &vec, int left, int right) {
int n = right - left + 1;
if (n <= 1) {
return;
}

for (int gap = n / 2; gap > 0; gap /= 2) {
for (int i = left + gap; i <= right; i++) {
int temp = vec[i];
int j = i;

while (j >= left + gap && vec[j - gap] > temp) {
vec[j] = vec[j - gap];
j -= gap;
}
vec[j] = temp;
}
}
}

} // namespace shakirova_e_shells_sort_simple
2 changes: 2 additions & 0 deletions tasks/shakirova_e_shells_sort_simple/data/test_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-20 15 -10 25 0 -5 30
-20 -10 -5 0 15 25 30
2 changes: 2 additions & 0 deletions tasks/shakirova_e_shells_sort_simple/data/test_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
45 23 87 12 65 34 90 21 56 78
12 21 23 34 45 56 65 78 87 90
2 changes: 2 additions & 0 deletions tasks/shakirova_e_shells_sort_simple/data/test_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
847 -234 567 -89 923 156 -456 734 289 512 678 -123 934 145 867 423 -678 756 290 601 834 -345 467 912 345 778 -567 601 234 889 467 -234 712 356 945 178 -890 623 890 456 723 -456 267 934 501 -234 867 234 756 489 -678 912 345 678 823 -345 456 734 267 -789 901 534 867 290 -456 745 412 889 356 -567 712 245 934 567 -234 801 434 767 312 -678 889 456 723 290 -345 867 434 756 289 -456 912 545 778 323 -234 867 490 734 267 -567 901 534 767 312 -345 889 456 723 290 -678 867 434 756 289 -456 912 545 778 323 -234 867 490 734 267 -567 901 534 767 312 -345 889 456 723 290 -678 867 434 756 289 -456 912 545 778 323 -234 867 490 734 267 -567 901 534 767 312 -345 889 456 723 290 -678 867 434 756 289 -456 912 545 778 323 -234 867 490 734 267 -567 901 534 767 312 -345 889 456 723 290 -678 867 434 756 289 -456 912 545 778 323 -234 867
-890 -789 -678 -678 -678 -678 -678 -678 -567 -567 -567 -567 -567 -567 -456 -456 -456 -456 -456 -456 -456 -456 -456 -456 -456 -456 -345 -345 -345 -345 -345 -345 -345 -345 -234 -234 -234 -234 -234 -234 -234 -234 -234 -234 -234 -234 -123 -89 145 156 178 234 234 234 245 267 267 267 267 267 267 289 289 289 289 289 290 290 290 290 290 290 312 312 312 312 312 323 323 323 323 323 345 345 345 356 356 412 423 434 434 434 434 434 434 456 456 456 456 456 456 467 467 489 490 490 490 490 490 501 512 534 534 534 534 534 545 545 545 545 545 567 567 567 601 601 623 678 678 712 712 723 723 723 723 723 734 734 734 734 734 745 756 756 756 756 756 767 767 767 767 778 778 778 778 778 801 823 834 847 867 867 867 867 867 867 867 867 867 867 867 867 889 889 889 889 889 889 890 901 901 901 901 901 912 912 912 912 912 912 923 934 934 934 945
2 changes: 2 additions & 0 deletions tasks/shakirova_e_shells_sort_simple/data/test_4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
847 923 156 734 289 512 678 934 145 867 423 756 290 601 834 467 912 345 778 601 234 889 467 712 356 945 178 623 890 456 723 267 934 501 867 234 756 489 912 345 678 823 456 734 267 901 534 867 290 745 412 889 356 712 245 934 567 801 434 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778 323 867 490 734 267 901 534 767 312 889 456 723 290 867 434 756 289 912 545 778
145 156 178 234 234 245 267 267 267 267 267 267 267 267 267 267 267 267 267 267 267 267 267 267 267 267 267 267 267 267 267 267 267 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 289 290 290 290 290 290 290 290 290 290 290 290 290 290 290 290 290 290 290 290 290 290 290 290 290 290 290 290 290 290 290 290 290 312 312 312 312 312 312 312 312 312 312 312 312 312 312 312 312 312 312 312 312 312 312 312 312 312 312 312 312 312 312 312 312 323 323 323 323 323 323 323 323 323 323 323 323 323 323 323 323 323 323 323 323 323 323 323 323 323 323 323 323 323 323 323 323 345 345 356 356 356 412 423 434 434 434 434 434 434 434 434 434 434 434 434 434 434 434 434 434 434 434 434 434 434 434 434 434 434 434 434 434 434 434 456 456 456 456 456 456 456 456 456 456 456 456 456 456 456 456 456 456 456 456 456 456 456 456 456 456 456 456 456 456 456 456 467 467 489 490 490 490 490 490 490 490 490 490 490 490 490 490 490 490 490 490 490 490 490 490 490 490 490 490 490 490 490 490 490 490 501 512 534 534 534 534 534 534 534 534 534 534 534 534 534 534 534 534 534 534 534 534 534 534 534 534 534 534 534 534 534 534 534 534 545 545 545 545 545 545 545 545 545 545 545 545 545 545 545 545 545 545 545 545 545 545 545 545 545 545 545 545 545 545 545 545 567 601 601 623 678 678 712 712 723 723 723 723 723 723 723 723 723 723 723 723 723 723 723 723 723 723 723 723 723 723 723 723 723 723 723 723 723 723 723 723 723 723 734 734 734 734 734 734 734 734 734 734 734 734 734 734 734 734 734 734 734 734 734 734 734 734 734 734 734 734 734 734 734 734 745 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 756 767 767 767 767 767 767 767 767 767 767 767 767 767 767 767 767 767 767 767 767 767 767 767 767 767 767 767 767 767 767 767 767 778 778 778 778 778 778 778 778 778 778 778 778 778 778 778 778 778 778 778 778 778 778 778 778 778 778 778 778 778 778 778 778 801 823 834 847 867 867 867 867 867 867 867 867 867 867 867 867 867 867 867 867 867 867 867 867 867 867 867 867 867 867 867 867 867 867 867 867 889 889 889 889 889 889 889 889 889 889 889 889 889 889 889 889 889 889 889 889 889 889 889 889 889 889 889 889 889 889 889 889 890 901 901 901 901 901 901 901 901 901 901 901 901 901 901 901 901 901 901 901 901 901 901 901 901 901 901 901 901 901 901 901 901 912 912 912 912 912 912 912 912 912 912 912 912 912 912 912 912 912 912 912 912 912 912 912 912 912 912 912 912 912 912 912 912 923 934 934 934 934 945
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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/shakirova_e_shells_sort_simple/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ПР2",
"task_number": "3"
}
}
22 changes: 22 additions & 0 deletions tasks/shakirova_e_shells_sort_simple/mpi/include/ops_mpi.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

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

namespace shakirova_e_shells_sort_simple {

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

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

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

#include <mpi.h>

#include <algorithm>
#include <vector>

#include "shakirova_e_shells_sort_simple/common/include/common.hpp"
#include "shakirova_e_shells_sort_simple/common/include/shell_sort.hpp"

namespace shakirova_e_shells_sort_simple {

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

bool ShakirovaEShellsSortSimpleMPI::ValidationImpl() {
return true;
}

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

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

int total_elements = 0;
if (rank == 0) {
total_elements = static_cast<int>(GetInput().size());
}
MPI_Bcast(&total_elements, 1, MPI_INT, 0, MPI_COMM_WORLD);

if (total_elements == 0) {
return true;
}

std::vector<int> send_counts(size);
std::vector<int> displs(size);
int base_count = total_elements / size;
int remainder = total_elements % size;
int current_displ = 0;

for (int i = 0; i < size; ++i) {
send_counts[i] = base_count + (i < remainder ? 1 : 0);
displs[i] = current_displ;
current_displ += send_counts[i];
}

std::vector<int> local_vec(send_counts[rank]);
MPI_Scatterv(rank == 0 ? GetInput().data() : nullptr, send_counts.data(), displs.data(), MPI_INT, local_vec.data(),
send_counts[rank], MPI_INT, 0, MPI_COMM_WORLD);

if (!local_vec.empty()) {
ShellSortImpl(local_vec, 0, static_cast<int>(local_vec.size()) - 1);
}

if (rank == 0) {
GetOutput().resize(total_elements);
}

MPI_Gatherv(local_vec.data(), send_counts[rank], MPI_INT, rank == 0 ? GetOutput().data() : nullptr,
send_counts.data(), displs.data(), MPI_INT, 0, MPI_COMM_WORLD);

if (rank == 0) {
auto current_end = GetOutput().begin() + send_counts[0];

for (int i = 1; i < size; ++i) {
if (send_counts[i] > 0) {
auto next_end = current_end + send_counts[i];
std::inplace_merge(GetOutput().begin(), current_end, next_end);
current_end = next_end;
}
}
}

return true;
}

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

} // namespace shakirova_e_shells_sort_simple
Loading
Loading