Skip to content

Commit

Permalink
feat: added metadata info on neighbours
Browse files Browse the repository at this point in the history
  • Loading branch information
TomMelt committed Nov 7, 2024
1 parent 2ae9723 commit a382d9f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
34 changes: 34 additions & 0 deletions core/src/ModelMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "include/IStructure.hpp"
#include "include/NextsimModule.hpp"
#include "include/gridNames.hpp"
#include <vector>

#ifdef USE_MPI
#include <ncDim.h>
Expand Down Expand Up @@ -53,11 +54,44 @@ void ModelMetadata::getPartitionMetadata(std::string partitionFile)
globalExtentX = ncFile.getDim("NX").getSize();
globalExtentY = ncFile.getDim("NY").getSize();
netCDF::NcGroup bboxGroup(ncFile.getGroup(bboxName));

std::vector<size_t> index(1, mpiMyRank);
bboxGroup.getVar("domain_x").getVar(index, &localCornerX);
bboxGroup.getVar("domain_y").getVar(index, &localCornerY);
bboxGroup.getVar("domain_extent_x").getVar(index, &localExtentX);
bboxGroup.getVar("domain_extent_y").getVar(index, &localExtentY);

netCDF::NcGroup neighbourGroup(ncFile.getGroup(neighbourName));
std::string tempName {};
for (auto edge : edges) {
size_t nStart {}; // start point in metadata arrays
size_t count {}; // number of elements to read from metadata arrays
std::vector<int> ranks;

tempName = edgeNames[edge] + "_start";
neighbourGroup.getVar(tempName).getVar(index, &nStart);
tempName = edgeNames[edge] + "_neighbors";
neighbourGroup.getVar(tempName).getVar(index, &count);
if (count) {
// initialize neighbour info to zero and correct size
neighbourRanks[edge].resize(count, 0);
neighbourExtents[edge].resize(count, 0);
neighbourStarts[edge].resize(count, 0);

tempName = edgeNames[edge] + "_neighbor_ids";
neighbourGroup.getVar(tempName).getVar({ nStart }, { count }, &neighbourRanks[edge][0]);

tempName = edgeNames[edge] + "_neighbor_halos";
neighbourGroup.getVar(tempName).getVar(
{ nStart }, { count }, &neighbourExtents[edge][0]);

tempName = edgeNames[edge] + "_neighbor_start";
neighbourGroup.getVar(tempName).getVar(
{ nStart }, { count }, &neighbourStarts[edge][0]);
}
}
printf("%d\n", neighbourRanks[BOTTOM][0]);

ncFile.close();
}

Expand Down
17 changes: 16 additions & 1 deletion core/src/include/ModelMetadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "include/Time.hpp"

#include <string>
#include <vector>

#ifdef USE_MPI
#include <mpi.h>
Expand Down Expand Up @@ -96,7 +97,15 @@ class ModelMetadata {
MPI_Comm mpiComm;
int mpiSize = 0;
int mpiMyRank = -1;
int localCornerX, localCornerY, localExtentX, localExtentY, globalExtentX, globalExtentY;
int localCornerX, localCornerY;
int localExtentX, localExtentY;
int globalExtentX, globalExtentY;
// mpi rank ID and exten for each edge direction
std::vector<int> neighbourRanks[4];
std::vector<int> neighbourExtents[4];
std::vector<int> neighbourStarts[4];
std::vector<int> rankExtentsX;
std::vector<int> rankExtentsY;
#endif

private:
Expand All @@ -116,6 +125,12 @@ class ModelMetadata {
bool hasParameters;
#ifdef USE_MPI
const std::string bboxName = "bounding_boxes";
const std::string neighbourName = "connectivity";

enum Edge { BOTTOM, RIGHT, TOP, LEFT, N_EDGE };
// An array to allow the edges to be accessed in the correct order.
static constexpr std::array<Edge, N_EDGE> edges = { BOTTOM, RIGHT, TOP, LEFT };
std::vector<std::string> edgeNames = { "bottom", "right", "top", "left" };
#endif
};

Expand Down

0 comments on commit a382d9f

Please sign in to comment.