root/src/io/test/parallel_mpi_2/parallelmemorywritertest.h @ 151:d19e1fd8bfe7

Revision 151:d19e1fd8bfe7, 3.2 KB (checked in by Andreas Schaefer <gentryx@…>, 15 months ago)

added ParallelMemoryWriter?

Line 
1#include <boost/filesystem.hpp>
2#include <cxxtest/TestSuite.h>
3
4#include <libgeodecomp/io/testinitializer.h>
5#include <libgeodecomp/io/parallelmemorywriter.h>
6#include <libgeodecomp/misc/testcell.h>
7#include <libgeodecomp/misc/testhelper.h>
8
9using namespace LibGeoDecomp; 
10
11namespace LibGeoDecomp {
12
13class MockSim : public DistributedSimulator<TestCell<2> >
14{
15public:
16    typedef DistributedSimulator<TestCell<2> > ParentType;
17    typedef typename ParentType::GridType GridType;
18
19    MockSim(TestInitializer<2> *init) : 
20        DistributedSimulator<TestCell<2> >(init)
21    {}
22   
23    virtual void getGridFragment(
24        const GridType **grid, 
25        const Region<2> **validRegion) 
26    {
27        *grid = myGrid;
28        *validRegion = myRegion;
29    }
30
31    void setGridFragment(       
32        const GridType *newGrid, 
33        const Region<2> *newValidRegion) 
34    {
35        myGrid = newGrid;
36        myRegion = newValidRegion;
37    }
38
39    void setStep(const unsigned& step)
40    {
41        stepNum = step;
42    }
43
44    virtual void step() 
45    {}
46
47    virtual void run() 
48    {}
49
50    const GridType *myGrid;
51    const Region<2> *myRegion;
52};
53
54class ParallelMemoryWriterTest :  public CxxTest::TestSuite
55{
56public:
57    typedef DisplacedGrid<TestCell<2>, TestCell<2>::Topology> GridType; 
58
59    void setUp()
60    {
61        dim = Coord<2>(10, 13);
62        init = new TestInitializer<2>(dim);
63        sim.reset(new MockSim(init));
64        writer = new ParallelMemoryWriter<TestCell<2> >(&*sim);
65    }
66
67    void tearDown()
68    {
69        sim.reset();
70    }
71
72    void testBasic()
73    {
74        GridType grid(init->gridBox());
75        init->grid(&grid);
76        TS_ASSERT_TEST_GRID(GridType, grid, 0);
77
78        Region<2> stripes[4];
79        for (int i = 0; i < 4; ++i) {
80            int startY = dim.y() * i / 4;
81            int endY = dim.y() * (i + 1) / 4;
82
83            for (int y = startY; y < endY; ++y) {
84                stripes[i] << Streak<2>(Coord<2>(0, y), 10);
85            }
86        }
87
88        for (int i = 0; i < 2; ++i) {
89            int index = MPILayer().rank() * 2 + i;
90            sim->setGridFragment(&grid, &stripes[index]);
91            writer->stepFinished();       
92        }
93
94        TS_ASSERT_EQUALS(writer->getGrids()[  0].getDimensions(), dim);
95        TS_ASSERT_EQUALS(writer->getGrids()[123].getDimensions(), Coord<2>());
96
97        TS_ASSERT_TEST_GRID(
98            ParallelMemoryWriter<TestCell<2> >::GridType, 
99            writer->getGrids()[0], 
100            0);
101
102        sim->setStep(123);
103
104        for (int i = 0; i < 2; ++i) {
105            int index = MPILayer().rank() + i * 2;
106            sim->setGridFragment(&grid, &stripes[index]);
107            writer->stepFinished();       
108        }
109
110        TS_ASSERT_EQUALS(writer->getGrids()[  0].getDimensions(), dim);
111        TS_ASSERT_EQUALS(writer->getGrids()[123].getDimensions(), dim);
112
113        TS_ASSERT_TEST_GRID(
114            ParallelMemoryWriter<TestCell<2> >::GridType, 
115            writer->getGrids()[0], 
116            0);
117        TS_ASSERT_TEST_GRID(
118            ParallelMemoryWriter<TestCell<2> >::GridType, 
119            writer->getGrids()[123], 
120            0);
121    }
122
123private:
124    Coord<2> dim;
125    boost::shared_ptr<MockSim> sim;
126    ParallelMemoryWriter<TestCell<2> > *writer;
127    TestInitializer<2> *init;
128};
129
130}
Note: See TracBrowser for help on using the browser.