Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Towards Large Meshes #59

Merged
merged 8 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions src/input/NetCDFMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ class NetCDFMesh : public MeshInput {
checkNcError(nc_inq_dimlen(ncFile, ncDimPart, &nPartitions));

// Local partitions
unsigned int nMaxLocalPart = (nPartitions + nProcs - 1) / nProcs;
unsigned int nLocalPart = nMaxLocalPart;
if (nPartitions < (rank + 1) * nMaxLocalPart) {
nLocalPart = std::max(0, static_cast<int>(nPartitions - rank * nMaxLocalPart));
const std::size_t nMaxLocalPart = (nPartitions + nProcs - 1) / nProcs;
std::size_t nLocalPart = nMaxLocalPart;
if (nPartitions < (rank + 1) * nMaxLocalPart && nPartitions >= rank * nMaxLocalPart) {
nLocalPart = static_cast<std::size_t>(nPartitions - rank * nMaxLocalPart);
}

MPI_Comm commIO;
Expand All @@ -73,8 +73,8 @@ class NetCDFMesh : public MeshInput {

PCU_Switch_Comm(commIO);

unsigned int nElements = 0;
unsigned int nVertices = 0;
std::size_t nElements = 0;
std::size_t nVertices = 0;
std::vector<ElementID> elements;
std::vector<double> vertices;
std::vector<int> boundaries;
Expand Down Expand Up @@ -115,8 +115,10 @@ class NetCDFMesh : public MeshInput {

// Read elements
logInfo(rank) << "Reading netCDF file";
for (unsigned int i = 0; i < nMaxLocalPart; i++) {
unsigned int j = i % nLocalPart;
for (std::size_t i = 0; i < nMaxLocalPart; i++) {
std::size_t j = i % nLocalPart;

// for now, each partition stays limited to about 2^31 maximum elements

size_t start[3] = {j + rank * nMaxLocalPart, 0, 0};

Expand Down Expand Up @@ -152,26 +154,26 @@ class NetCDFMesh : public MeshInput {

checkNcError(nc_close(ncFile));

for (unsigned int i = 0; i < nLocalPart; i++) {
for (std::size_t i = 0; i < nLocalPart; i++) {
nElements += partitions[i].nElements();
nVertices += partitions[i].nVertices();
}

// Copy to the buffer
std::vector<unsigned int> elementsLocal(nElements * 4);
std::vector<std::size_t> elementsLocal(nElements * 4);
elements.resize(nElements * 4);
vertices.resize(nVertices * 3);

boundaries.resize(nElements * 4);
groups.resize(nElements);

unsigned int elementOffset = 0;
unsigned int vertexOffset = 0;
for (unsigned int i = 0; i < nLocalPart; i++) {
std::size_t elementOffset = 0;
std::size_t vertexOffset = 0;
for (std::size_t i = 0; i < nLocalPart; i++) {
#ifdef _OPENMP
#pragma omp parallel
#pragma omp parallel schedule(static)
#endif
for (unsigned int j = 0; j < partitions[i].nElements() * 4; j++) {
for (std::size_t j = 0; j < partitions[i].nElements() * 4; j++) {
elementsLocal[elementOffset * 4 + j] = partitions[i].elements()[j] + vertexOffset;
}

Expand All @@ -190,7 +192,7 @@ class NetCDFMesh : public MeshInput {

logInfo(rank) << "Running vertex filter";
ParallelVertexFilter filter(commIO);
filter.filter(nVertices, vertices.data());
filter.filter(nVertices, vertices);

// Create filtered vertex list

Expand All @@ -202,7 +204,7 @@ class NetCDFMesh : public MeshInput {
#ifdef _OPENMP
#pragma omp parallel
#endif
for (unsigned int i = 0; i < nElements * 4; i++) {
for (std::size_t i = 0; i < nElements * 4; i++) {
elements[i] = filter.globalIds()[elementsLocal[i]];
}
}
Expand All @@ -220,12 +222,12 @@ class NetCDFMesh : public MeshInput {
// Set boundaries
apf::MeshTag* boundaryTag = m_mesh->createIntTag("boundary condition", 1);
apf::MeshIterator* it = m_mesh->begin(3);
unsigned int i = 0;
std::size_t i = 0;
while (apf::MeshEntity* element = m_mesh->iterate(it)) {
apf::Adjacent adjacent;
m_mesh->getAdjacent(element, 2, adjacent);

for (unsigned int j = 0; j < 4; j++) {
for (int j = 0; j < 4; j++) {
if (!boundaries[i * 4 + j])
continue;

Expand Down
12 changes: 6 additions & 6 deletions src/input/NetCDFPartition.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
*/
class Partition {
private:
unsigned int m_nElements;
unsigned int m_nVertices;
std::size_t m_nElements;
std::size_t m_nVertices;

int* m_elements;
double* m_vertices;
Expand All @@ -40,7 +40,7 @@ class Partition {
delete[] m_groups;
}

void setElemSize(unsigned int nElements) {
void setElemSize(std::size_t nElements) {
if (m_nElements != 0)
return;

Expand All @@ -53,7 +53,7 @@ class Partition {
memset(m_groups, 0, nElements * sizeof(int));
}

void setVrtxSize(unsigned int nVertices) {
void setVrtxSize(std::size_t nVertices) {
if (m_nVertices != 0)
return;

Expand All @@ -72,9 +72,9 @@ class Partition {
}
}

unsigned int nElements() const { return m_nElements; }
std::size_t nElements() const { return m_nElements; }

unsigned int nVertices() const { return m_nVertices; }
std::size_t nVertices() const { return m_nVertices; }

int* elements() { return m_elements; }

Expand Down
Loading