| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "boltenkov_s_broadcast/seq/include/ops_seq.hpp" | ||
| 2 | |||
| 3 | #include <mpi.h> | ||
| 4 | |||
| 5 | #include <cmath> | ||
| 6 | #include <cstddef> | ||
| 7 | #include <tuple> | ||
| 8 | #include <utility> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | #include "boltenkov_s_broadcast/common/include/common.hpp" | ||
| 12 | |||
| 13 | namespace boltenkov_s_broadcast { | ||
| 14 | |||
| 15 | ✗ | BoltenkovSBroadcastkSEQ::BoltenkovSBroadcastkSEQ(const InType &in) { | |
| 16 | SetTypeOfTask(GetStaticTypeOfTask()); | ||
| 17 | ✗ | int rank = 0; | |
| 18 | ✗ | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| 19 | ✗ | if (rank == std::get<0>(in)) { | |
| 20 | GetInput() = in; | ||
| 21 | } else { | ||
| 22 | int cnt_byte = 0; | ||
| 23 | ✗ | if (std::get<1>(in) == static_cast<size_t>(0)) { | |
| 24 | ✗ | cnt_byte = std::get<2>(in) * static_cast<int>(sizeof(int)); | |
| 25 | ✗ | } else if (std::get<1>(in) == static_cast<size_t>(1)) { | |
| 26 | ✗ | cnt_byte = std::get<2>(in) * static_cast<int>(sizeof(float)); | |
| 27 | ✗ | } else if (std::get<1>(in) == static_cast<size_t>(2)) { | |
| 28 | ✗ | cnt_byte = std::get<2>(in) * static_cast<int>(sizeof(double)); | |
| 29 | } | ||
| 30 | |||
| 31 | ✗ | std::vector<char> vec; | |
| 32 | ✗ | if (cnt_byte > 0) { | |
| 33 | ✗ | vec.resize(cnt_byte); | |
| 34 | } | ||
| 35 | |||
| 36 | ✗ | GetInput() = std::make_tuple(std::get<0>(in), std::get<1>(in), std::get<2>(in), std::move(vec)); | |
| 37 | } | ||
| 38 | ✗ | GetOutput() = std::make_tuple(-1, -1, std::vector<char>()); | |
| 39 | ✗ | mpi_type_ = MPI_DOUBLE; | |
| 40 | ✗ | } | |
| 41 | |||
| 42 | ✗ | MPI_Datatype BoltenkovSBroadcastkSEQ::GetTypeData(const int &ind_data_type) { | |
| 43 | ✗ | if (ind_data_type == 0) { | |
| 44 | return MPI_INT; | ||
| 45 | } | ||
| 46 | ✗ | if (ind_data_type == 1) { | |
| 47 | ✗ | return MPI_FLOAT; | |
| 48 | } | ||
| 49 | return MPI_DOUBLE; | ||
| 50 | } | ||
| 51 | |||
| 52 | ✗ | int BoltenkovSBroadcastkSEQ::GetIndTypeData(MPI_Datatype datatype) { | |
| 53 | ✗ | if (datatype == MPI_INT) { | |
| 54 | return 0; | ||
| 55 | } | ||
| 56 | ✗ | if (datatype == MPI_FLOAT) { | |
| 57 | return 1; | ||
| 58 | } | ||
| 59 | ✗ | if (datatype == MPI_DOUBLE) { | |
| 60 | ✗ | return 2; | |
| 61 | } | ||
| 62 | return -1; | ||
| 63 | } | ||
| 64 | |||
| 65 | ✗ | bool BoltenkovSBroadcastkSEQ::ValidationImpl() { | |
| 66 | ✗ | int rank = 0; | |
| 67 | ✗ | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| 68 | ✗ | if (rank == std::get<0>(GetInput())) { | |
| 69 | ✗ | int size = 0; | |
| 70 | ✗ | MPI_Comm_size(MPI_COMM_WORLD, &size); | |
| 71 | ✗ | return std::get<0>(GetInput()) >= 0 && std::get<0>(GetInput()) < size && std::get<2>(GetInput()) >= 0 && | |
| 72 | ✗ | !std::get<3>(GetInput()).empty() && std::get<1>(GetInput()) >= 0 && std::get<1>(GetInput()) < 3; | |
| 73 | } | ||
| 74 | return true; | ||
| 75 | } | ||
| 76 | |||
| 77 | ✗ | bool BoltenkovSBroadcastkSEQ::PreProcessingImpl() { | |
| 78 | ✗ | int rank = 0; | |
| 79 | ✗ | MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
| 80 | ✗ | if (rank == std::get<0>(GetInput())) { | |
| 81 | ✗ | int ind_data_type = std::get<1>(GetInput()); | |
| 82 | ✗ | mpi_type_ = GetTypeData(ind_data_type); | |
| 83 | } | ||
| 84 | ✗ | int type_int = GetIndTypeData(mpi_type_); | |
| 85 | ✗ | MPI_Bcast(&type_int, 1, MPI_INT, std::get<0>(GetInput()), MPI_COMM_WORLD); | |
| 86 | ✗ | mpi_type_ = GetTypeData(type_int); | |
| 87 | ✗ | return true; | |
| 88 | } | ||
| 89 | |||
| 90 | ✗ | bool BoltenkovSBroadcastkSEQ::RunImpl() { | |
| 91 | ✗ | int res_mpi = MPI_Bcast(static_cast<void *>(std::get<3>(GetInput()).data()), std::get<2>(GetInput()), mpi_type_, | |
| 92 | std::get<0>(GetInput()), MPI_COMM_WORLD); | ||
| 93 | ✗ | GetOutput() = std::make_tuple(GetIndTypeData(mpi_type_), std::get<2>(GetInput()), std::get<3>(GetInput())); | |
| 94 | ✗ | return res_mpi == MPI_SUCCESS; | |
| 95 | } | ||
| 96 | |||
| 97 | ✗ | bool BoltenkovSBroadcastkSEQ::PostProcessingImpl() { | |
| 98 | ✗ | return std::get<1>(GetOutput()) >= 0 && !std::get<2>(GetOutput()).empty() && std::get<0>(GetOutput()) >= 0 && | |
| 99 | ✗ | std::get<0>(GetOutput()) <= 2; | |
| 100 | } | ||
| 101 | |||
| 102 | } // namespace boltenkov_s_broadcast | ||
| 103 |