| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <mpi.h> | ||
| 4 | |||
| 5 | #include "task/include/task.hpp" | ||
| 6 | #include "zagryadskov_m_allreduce/common/include/common.hpp" | ||
| 7 | |||
| 8 | namespace zagryadskov_m_allreduce { | ||
| 9 | |||
| 10 | class ZagryadskovMAllreduceMPI : public BaseTask { | ||
| 11 | public: | ||
| 12 | static constexpr ppc::task::TypeOfTask GetStaticTypeOfTask() { | ||
| 13 | return ppc::task::TypeOfTask::kMPI; | ||
| 14 | } | ||
| 15 | explicit ZagryadskovMAllreduceMPI(const InType &in); | ||
| 16 | |||
| 17 | private: | ||
| 18 | OutType temp_vec_; | ||
| 19 | bool ValidationImpl() override; | ||
| 20 | bool PreProcessingImpl() override; | ||
| 21 | bool RunImpl() override; | ||
| 22 | bool PostProcessingImpl() override; | ||
| 23 | static void ApplyOp(void *recvbuf, const void *tempbuf, int count, MPI_Datatype type, MPI_Op op, MPI_Comm comm); | ||
| 24 | template <typename T> | ||
| 25 | 12 | static void ApplyOp(void *recvbuf, const void *tempbuf, int count, MPI_Op op, MPI_Comm comm) { | |
| 26 | T *r = reinterpret_cast<T *>(recvbuf); | ||
| 27 | const T *t = reinterpret_cast<const T *>(tempbuf); | ||
| 28 |
2/2✓ Branch 0 taken 6000150 times.
✓ Branch 1 taken 6 times.
|
12000312 | for (int i = 0; i < count; i++) { |
| 29 |
2/2✓ Branch 0 taken 4000050 times.
✓ Branch 1 taken 2000100 times.
|
12000300 | if (op == MPI_SUM) { |
| 30 | 8000100 | r[i] += t[i]; | |
| 31 |
2/2✓ Branch 0 taken 50 times.
✓ Branch 1 taken 2000050 times.
|
4000200 | } else if (op == MPI_MAX) { |
| 32 |
2/2✓ Branch 0 taken 25 times.
✓ Branch 1 taken 25 times.
|
150 | r[i] = std::max(r[i], t[i]); |
| 33 |
1/2✓ Branch 0 taken 2000050 times.
✗ Branch 1 not taken.
|
4000100 | } else if (op == MPI_MIN) { |
| 34 |
2/2✓ Branch 0 taken 995002 times.
✓ Branch 1 taken 1005048 times.
|
5990104 | r[i] = std::min(r[i], t[i]); |
| 35 | } else { | ||
| 36 | ✗ | MPI_Abort(comm, 1); | |
| 37 | } | ||
| 38 | } | ||
| 39 | 12 | } | |
| 40 | static int MyAllreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, | ||
| 41 | MPI_Comm comm); | ||
| 42 | }; | ||
| 43 | |||
| 44 | } // namespace zagryadskov_m_allreduce | ||
| 45 |