Skip to content

Commit 3adf0d1

Browse files
committed
wip
1 parent 7c3adbb commit 3adf0d1

File tree

2 files changed

+113
-40
lines changed

2 files changed

+113
-40
lines changed

core/test/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,28 @@ if(ENABLE_MPI)
7777
)
7878
target_link_libraries(testModelMetadata_MPI3 PRIVATE nextsimlib doctest::doctest)
7979

80+
# set(ModelArrayStructure "discontinuousgalerkin")
81+
set(CoreDir "../../core/src/")
82+
83+
# set(MODEL_INCLUDE_DIR "./testmodelarraydetails")
84+
add_executable(testHaloExchange_MPI3
85+
"HaloExchange_test.cpp"
86+
"MainMPI.cpp"
87+
"../src/ModelArray.cpp"
88+
"../src/ModelArraySlice.cpp"
89+
"${MODEL_INCLUDE_DIR}/ModelArrayDetails.cpp"
90+
)
91+
target_compile_definitions(testHaloExchange_MPI3 PRIVATE USE_MPI)
92+
target_include_directories(
93+
testHaloExchange_MPI3 PRIVATE
94+
"../src"
95+
"../../dynamics/src"
96+
${MODEL_INCLUDE_DIR}
97+
)
98+
target_link_libraries(testHaloExchange_MPI3 PRIVATE doctest::doctest Eigen3::Eigen)
99+
100+
set(MODEL_INCLUDE_DIR "../../core/src/discontinuousgalerkin")
101+
80102
add_executable(testParaGrid_MPI2 "ParaGrid_test.cpp" "MainMPI.cpp")
81103
target_compile_definitions(
82104
testParaGrid_MPI2

core/test/HaloExchange_test.cpp

Lines changed: 91 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,113 @@
55
* @author Tom Meltzer <tdm39@cam.ac.uk>
66
*/
77

8+
#include <cstddef>
89
#include <doctest/extensions/doctest_mpi.h>
9-
#include <iostream>
1010

11+
#include "include/DGModelArray.hpp"
1112
#include "include/ModelArraySlice.hpp"
13+
#include "include/ParametricMesh.hpp"
14+
#include "mpi.h"
1215

1316
#include <array>
1417

15-
const auto nx = 23;
16-
const auto ny = 17;
17-
const auto nz = 5;
18+
using Slice = ArraySlicer::Slice;
19+
using SliceIter = ArraySlicer::SliceIter;
20+
21+
const auto nx = 9;
22+
const auto ny = 5;
23+
const auto nz = 3;
1824

1925
namespace Nextsim {
2026

21-
TEST_SUITE_BEGIN("ModelMetadata");
22-
MPI_TEST_CASE("Test getPartitionMetadata closed boundary", 3)
27+
TEST_SUITE_BEGIN("Halo exchange");
28+
MPI_TEST_CASE("test halo exchange", 3)
2329
{
2430

25-
ModelArray::setDimension(ModelArray::Dimension::X, nx, nx / 4, 0);
26-
ModelArray::setDimension(ModelArray::Dimension::Y, ny, ny / 4, 0);
27-
28-
// Test 1 dimensional slices into and out of common buffer types
29-
// std::vector
30-
OneDField oned(ModelArray::Type::ONED);
31-
oned.resize();
32-
const auto x0 = 3;
33-
const auto x1 = 11;
34-
auto oneSlice = oned[{ { { x0, x1 } } }];
35-
36-
// Check the functions throw when given too small a buffer
37-
std::vector<double> shortBuffer;
38-
shortBuffer.resize(x1 - x0 - 1);
39-
REQUIRE_THROWS(oneSlice = shortBuffer);
40-
REQUIRE_THROWS(oneSlice.copyToBuffer(shortBuffer));
41-
// Fill the array with index values
42-
for (auto i = 0; i < oned.size(); ++i) {
43-
oned[i] = i;
44-
}
31+
size_t localNx = nx / test_nb_procs;
32+
size_t offsetX = test_rank * localNx;
33+
ModelArray::setDimension(ModelArray::Dimension::X, nx, localNx, offsetX);
34+
ModelArray::setDimension(ModelArray::Dimension::Y, ny, ny, 0);
35+
36+
// create example 2D field of size 3x5 (x,y) on each process
37+
auto testfield = ModelArray::HField();
38+
testfield.resize();
4539

46-
std::vector<double> vectorBuffer;
47-
vectorBuffer.resize(x1 - x0);
48-
// Fill with index values
49-
for (auto i = 0; i < vectorBuffer.size(); ++i) {
50-
vectorBuffer[i] = i;
40+
// initialize with mock data
41+
for (size_t j = 0; j < ny; ++j) {
42+
for (size_t i = 0; i < localNx; ++i) {
43+
testfield(i, j) = test_rank * 100 + (i + offsetX) * 10 + j;
44+
}
5145
}
52-
// assign from the buffer
53-
oneSlice = vectorBuffer;
54-
REQUIRE(oned[x0 - 1] == x0 - 1);
55-
REQUIRE(oned[x1] == x1);
56-
REQUIRE(oned[x0 + 0] == 0);
57-
REQUIRE(oned[x1 - 1] == x1 - x0 - 1);
58-
// Refill with index values
59-
for (auto i = 0; i < oned.size(); ++i) {
60-
oned[i] = i;
46+
47+
// create example 2D field for dynamics code which needs +1 halo on all edges, leading to +2 in
48+
// x and y i.e., 5x7 on each process
49+
offsetX = test_rank * (localNx + 2);
50+
51+
// auto dynamicsfield = ModelArray::TwoDFieldHALO();
52+
// dynamicsfield.resize();
53+
static const int DG = 3;
54+
55+
// Create the ParametricMesh object
56+
auto CoordinateSystem = Nextsim::CARTESIAN;
57+
ParametricMesh smesh(CoordinateSystem);
58+
smesh.nx = nx + 2;
59+
smesh.ny = ny + 2;
60+
smesh.nnodes = smesh.nx * smesh.ny;
61+
smesh.nelements = smesh.nnodes;
62+
smesh.vertices.resize(smesh.nelements, Eigen::NoChange);
63+
for (size_t i = 0; i < nx; ++i) {
64+
for (size_t j = 0; j < ny; ++j) {
65+
smesh.vertices(i * ny + j, 0) = i;
66+
smesh.vertices(i * ny + j, 1) = j;
67+
}
6168
}
69+
// DGModelArray::ma2dg<DG>(testfield, dgvec);
70+
71+
DGVector<DG> dgvec(smesh);
72+
73+
ModelArraySlice source(testfield, { { {}, {} } });
74+
75+
source.copyToDataSlice(dgvec, { { { 1, localNx + 1 }, { 1, ny + 1 } } });
76+
77+
int ierr;
78+
enum Edge { BOTTOM, RIGHT, TOP, LEFT, N_EDGE };
79+
constexpr std::array<Edge, N_EDGE> edges = { BOTTOM, RIGHT, TOP, LEFT };
80+
std::map<Edge, std::vector<size_t>> neighbours, haloStarts;
81+
82+
neighbours.try_emplace(BOTTOM, std::vector<size_t>({ 0, 1, 2 }));
83+
neighbours.try_emplace(TOP, std::vector<size_t>({ 0, 1, 2 }));
84+
neighbours.try_emplace(RIGHT, std::vector<size_t>({ 1, 2, 0 }));
85+
neighbours.try_emplace(LEFT, std::vector<size_t>({ 2, 0, 1 }));
86+
87+
haloStarts.try_emplace(BOTTOM, std::vector<size_t>(3, 12));
88+
haloStarts.try_emplace(TOP, std::vector<size_t>(3, 0));
89+
haloStarts.try_emplace(LEFT, std::vector<size_t>(3, 2));
90+
haloStarts.try_emplace(RIGHT, std::vector<size_t>(3, 0));
91+
92+
const long int x0 = offsetX;
93+
const long int x1 = offsetX + localNx;
94+
auto slice = testfield[{ { { 0, localNx }, { { 0 } } } }];
95+
96+
std::vector<double> vectorBuffer = std::vector<double>(localNx, -1);
97+
98+
slice.copyToBuffer(vectorBuffer);
99+
100+
// ModelArray source(ModelArray::Type::H);
101+
// source.resize();
102+
// // Fill with data
103+
// for (size_t i = 0; i < nx; ++i) {
104+
// for (size_t j = 0; j < ny; j++) {
105+
// source(i, j) = j + mx * (i);
106+
// }
107+
// }
108+
109+
// CHECK(source(14, 12) == 12 + mx * (14));
110+
111+
// ierr = MPI_Scatterv()
62112

63113
if (test_rank == 0) {
114+
std::vector<int> neighbour_R = { 1, 2, 0 };
64115
} else if (test_rank == 1) {
65116
} else if (test_rank == 2) {
66117
} else {

0 commit comments

Comments
 (0)