forked from SGpp/DisCoTec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_task.cpp
107 lines (81 loc) · 2.86 KB
/
test_task.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#define BOOST_TEST_DYN_LINK
// to resolve https://github.com/open-mpi/ompi/issues/5157
#define OMPI_SKIP_MPICXX 1
#include <mpi.h>
#include <boost/test/unit_test.hpp>
#include <complex>
#include <cstdarg>
#include <iostream>
#include <vector>
#include <boost/serialization/export.hpp>
#include "loadmodel/LinearLoadModel.hpp"
#include "task/Task.hpp"
#include "utils/Config.hpp"
#include "test_helper.hpp"
using namespace combigrid;
class TaskTest : public combigrid::Task {
public:
int test;
TaskTest(DimType dim, const LevelVector& l, const std::vector<BoundaryType>& boundary, real coeff,
LoadModel* loadModel, int t)
: Task(l, boundary, coeff, loadModel), test(t) {}
void init(CommunicatorType lcomm,
const std::vector<IndexVector>& decomposition = std::vector<IndexVector>()) override {
// create dummy dfg
std::vector<int> p(getDim(), 1);
dfg_ = new OwningDistributedFullGrid<CombiDataType>(getDim(), getLevelVector(), lcomm,
getBoundary(), p);
}
void run(CommunicatorType lcomm) override {}
void getFullGrid(FullGrid<CombiDataType>& fg, RankType r, CommunicatorType lcomm, int n = 0) override {
dfg_->gatherFullGrid(fg, r);
}
DistributedFullGrid<CombiDataType>& getDistributedFullGrid(size_t n = 0) override { return *dfg_; }
void setZero() override {}
~TaskTest() {
if (dfg_ != NULL) delete dfg_;
}
protected:
TaskTest() : dfg_(NULL) {}
private:
friend class boost::serialization::access;
OwningDistributedFullGrid<CombiDataType>* dfg_;
template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& boost::serialization::base_object<Task>(*this);
ar& test;
}
};
BOOST_CLASS_EXPORT(TaskTest)
BOOST_FIXTURE_TEST_SUITE(task, TestHelper::BarrierAtEnd, *boost::unit_test::timeout(60))
BOOST_AUTO_TEST_CASE(test) {
int size = 8;
BOOST_REQUIRE(TestHelper::checkNumMPIProcsAvailable(size));
CommunicatorType comm = TestHelper::getComm(size);
if (comm == MPI_COMM_NULL) return;
DimType dim = 3;
LevelVector l(dim, 2);
std::vector<BoundaryType> boundary(dim, 2);
std::unique_ptr<LoadModel> loadmodel = std::unique_ptr<LinearLoadModel>(new LinearLoadModel());
Task* t;
if (TestHelper::getRank(comm) == 0) {
t = new TaskTest(dim, l, boundary, 1, loadmodel.get(), 42);
}
// test broadcast
Task::broadcast(&t, 0, comm);
BOOST_CHECK(static_cast<TaskTest*>(t)->test == 42);
// test send / receive
static_cast<TaskTest*>(t)->test += TestHelper::getRank(comm);
if (TestHelper::getRank(comm) != 0) {
Task::send(t, 0, comm);
} else {
for (int i = 1; i < size; ++i) {
Task::receive(&t, i, comm);
BOOST_CHECK(static_cast<TaskTest*>(t)->test == 42 + i);
}
}
assert(loadmodel);
LevelVector test_l = t->getLevelVector();
loadmodel->eval(test_l);
}
BOOST_AUTO_TEST_SUITE_END()