Skip to content

Commit

Permalink
patchkernel: initialize partitioning in the constructor
Browse files Browse the repository at this point in the history
If a valid communicator is passed to the constructor, a partitioned
patch will be created, otherwise the created patch will be serial.

Patches that are filled automatically (e.g. VolOctree) will initialize
the cells only on the process identified by the rank zero in the
communicator.
  • Loading branch information
andrea-iob committed Jan 19, 2021
1 parent c4e4fbf commit a6d686a
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 174 deletions.
58 changes: 25 additions & 33 deletions src/patchkernel/patch_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ PatchKernel::PatchKernel(bool expert)
/*!
Creates a partitioned patch.
Patches that are filled automatically (e.g. VolOctree) will initialize
the cells only on the process identified by the rank zero in the
communicator.
\param communicator is the communicator to be used for exchanging data
among the processes
\param haloSize is the size, expressed in number of layers, of the ghost
Expand Down Expand Up @@ -98,6 +102,10 @@ PatchKernel::PatchKernel(int dimension, bool expert)
/*!
Creates a partitioned patch.
Patches that are filled automatically (e.g. VolOctree) will initialize
the cells only on the process identified by the rank zero in the
communicator.
\param dimension is the dimension of the patch
\param communicator is the communicator to be used for exchanging data
among the processes
Expand Down Expand Up @@ -139,6 +147,10 @@ PatchKernel::PatchKernel(int id, int dimension, bool expert)
/*!
Creates a partitioned patch.
Patches that are filled automatically (e.g. VolOctree) will initialize
the cells only on the process identified by the rank zero in the
communicator.
\param id is the id that will be assigned to the patch
\param dimension is the dimension of the patch
\param communicator is the communicator to be used for exchanging data
Expand Down Expand Up @@ -220,7 +232,6 @@ PatchKernel::PatchKernel(const PatchKernel &other)
m_nProcessors(other.m_nProcessors)
#if BITPIT_ENABLE_MPI==1
, m_communicator(MPI_COMM_NULL),
m_partitioned(other.m_partitioned),
m_partitioningStatus(other.m_partitioningStatus),
m_owner(other.m_owner),
m_haloSize(other.m_haloSize),
Expand Down Expand Up @@ -361,24 +372,21 @@ void PatchKernel::initialize()
// Set halo size
initializeHaloSize(haloSize);

// Patch is not partitioned
setPartitioned(false);

// Set the partitioning as unsupported
//
// Specific implementation will set the appropriate status during their
// initialization.
setPartitioningStatus(PARTITIONING_UNSUPPORTED);

// Update patch owner
updateOwner();

// Mark partitioning information as up-to-date
setPartitioningInfoDirty(false);
// Mark patch as partioned
if (isCommunicatorSet()) {
setPartitioningStatus(PARTITIONING_CLEAN);
} else {
setPartitioningStatus(PARTITIONING_UNSUPPORTED);
}

// Initialize partitioning tags
m_partitioningCellsTag = -1;
m_partitioningVerticesTag = -1;

// Update partitioning information
if (isPartitioned()) {
updatePartitioningInfo(true);
}
#else
// Dummy parallel information
m_rank = 0;
Expand Down Expand Up @@ -714,14 +722,7 @@ void PatchKernel::finalizeAlterations(bool squeezeStorage)

#if BITPIT_ENABLE_MPI==1
// Update partitioning information
//
// If we are partitioning the patch, the partition flag is not set yet (it
// will be set after the call to this function).
bool partitioningInfoDirty = (getPartitioningStatus() == PARTITIONING_PREPARED);
if (!partitioningInfoDirty) {
partitioningInfoDirty = arePartitioningInfoDirty();
}

bool partitioningInfoDirty = arePartitioningInfoDirty();
if (partitioningInfoDirty) {
updatePartitioningInfo(true);
}
Expand Down Expand Up @@ -7012,7 +7013,7 @@ void PatchKernel::consecutiveRenumber(long vertexOffset, long cellOffset, long i
*/
int PatchKernel::getDumpVersion() const
{
const int KERNEL_DUMP_VERSION = 10;
const int KERNEL_DUMP_VERSION = 11;

return (KERNEL_DUMP_VERSION + _getDumpVersion());
}
Expand Down Expand Up @@ -7064,10 +7065,8 @@ bool PatchKernel::dump(std::ostream &stream) const
utils::binary::write(stream, m_dimension);
utils::binary::write(stream, m_vtk.getName());
#if BITPIT_ENABLE_MPI==1
utils::binary::write(stream, isPartitioned());
utils::binary::write(stream, m_haloSize);
#else
utils::binary::write(stream, false);
utils::binary::write(stream, 0);
#endif

Expand Down Expand Up @@ -7148,13 +7147,6 @@ void PatchKernel::restore(std::istream &stream, bool reregister)
utils::binary::read(stream, name);
m_vtk.setName(name);

// Partioned flag
bool partitioned;
utils::binary::read(stream, partitioned);
#if BITPIT_ENABLE_MPI==1
setPartitioned(partitioned);
#endif

// Halo size
#if BITPIT_ENABLE_MPI==1
utils::binary::read(stream, m_haloSize);
Expand Down
1 change: 0 additions & 1 deletion src/patchkernel/patch_kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,6 @@ friend class PatchManager;
int m_nProcessors;
#if BITPIT_ENABLE_MPI==1
MPI_Comm m_communicator;
bool m_partitioned;
PartitioningStatus m_partitioningStatus;

int m_owner;
Expand Down
15 changes: 1 addition & 14 deletions src/patchkernel/patch_kernel_parallel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1507,9 +1507,6 @@ std::vector<adaption::Info> PatchKernel::partitioningAlter(bool trackPartitionin
// Finalize patch alterations
finalizeAlterations(squeezeStorage);

// The patch is now partitioned
setPartitioned(true);

// Update the status
setPartitioningStatus(PARTITIONING_ALTERED);

Expand Down Expand Up @@ -1555,17 +1552,7 @@ void PatchKernel::partitioningCleanup()
*/
bool PatchKernel::isPartitioned() const
{
return m_partitioned;
}

/*!
Sets the partitioned flag.
\param partitioned is the flag that will be set
*/
void PatchKernel::setPartitioned(bool partitioned)
{
m_partitioned = partitioned;
return isCommunicatorSet();
}

/*!
Expand Down
17 changes: 0 additions & 17 deletions src/surfunstructured/surfunstructured.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ SurfUnstructured::SurfUnstructured(MPI_Comm communicator)
: SurfaceKernel(true)
#endif
{
#if BITPIT_ENABLE_MPI==1
// This patch supports partitioning
setPartitioningStatus(PARTITIONING_CLEAN);
#endif
}

/*!
Expand Down Expand Up @@ -91,10 +87,6 @@ SurfUnstructured::SurfUnstructured(int patch_dim, int space_dim, MPI_Comm commun
: SurfaceKernel(PatchManager::AUTOMATIC_ID, patch_dim, space_dim, true)
#endif
{
#if BITPIT_ENABLE_MPI==1
// This patch supports partitioning
setPartitioningStatus(PARTITIONING_CLEAN);
#endif
}

/*!
Expand Down Expand Up @@ -125,10 +117,6 @@ SurfUnstructured::SurfUnstructured(int id, int patch_dim, int space_dim, MPI_Com
: SurfaceKernel(id, patch_dim, space_dim, true)
#endif
{
#if BITPIT_ENABLE_MPI==1
// This patch supports partitioning
setPartitioningStatus(PARTITIONING_CLEAN);
#endif
}

/*!
Expand Down Expand Up @@ -156,11 +144,6 @@ SurfUnstructured::SurfUnstructured(std::istream &stream, MPI_Comm communicator)
: SurfaceKernel(false)
#endif
{
#if BITPIT_ENABLE_MPI==1
// This patch supports partitioning
setPartitioningStatus(PARTITIONING_CLEAN);
#endif

// Restore the patch
restore(stream);
}
Expand Down
29 changes: 20 additions & 9 deletions src/voloctree/voloctree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ VolOctree::VolOctree()
/*!
Creates an uninitialized partitioned patch.
Cells will be initialized the cells only on the process identified by the
rank zero in the communicator.
\param communicator is the communicator to be used for exchanging data
among the processes
\param haloSize is the size, expressed in number of layers, of the ghost
Expand Down Expand Up @@ -120,6 +123,9 @@ VolOctree::VolOctree(int dimension, const std::array<double, 3> &origin, double
/*!
Creates a partitioned patch.
Cells will be initialized the cells only on the process identified by the
rank zero in the communicator.
\param dimension is the dimension of the patch
\param origin is the origin of the domain
\param length is the length of the domain
Expand Down Expand Up @@ -155,6 +161,9 @@ VolOctree::VolOctree(int id, int dimension, const std::array<double, 3> &origin,
/*!
Creates a partitioned patch.
Cells will be initialized the cells only on the process identified by the
rank zero in the communicator.
\param id is the id that will be assigned to the patch
\param dimension is the dimension of the patch
\param origin is the origin of the domain
Expand Down Expand Up @@ -209,10 +218,11 @@ VolOctree::VolOctree(int id, int dimension, const std::array<double, 3> &origin,
// Set the bounding
setBoundingBox();

// Inizializzazione dell'octree
double initial_level = ceil(log2(std::max(1., length / dh)));

m_tree->setMarker((uint32_t) 0, initial_level);
// Initialize refinement markers
if (m_tree->getNumOctants() > 0) {
double initial_level = ceil(log2(std::max(1., length / dh)));
m_tree->setMarker((uint32_t) 0, initial_level);
}
}

/*!
Expand Down Expand Up @@ -276,6 +286,9 @@ VolOctree::VolOctree(std::unique_ptr<PabloUniform> &&tree, std::unique_ptr<Pablo

/*!
Creates a paritioned patch.
Cells will be initialized the cells only on the process identified by the
rank zero in the communicator.
*/
#if BITPIT_ENABLE_MPI==1
/*!
Expand Down Expand Up @@ -426,6 +439,9 @@ void VolOctree::initializeTree(std::unique_ptr<PabloUniform> *adopter)
if (haloSize != m_tree->getNofGhostLayers()) {
initializeTreeHaloSize(haloSize);
}

// Initialize partitioning
initializeTreePartitioning();
} else {
// Check if the current halo size is equal to the requested one
if (haloSize != m_tree->getNofGhostLayers()) {
Expand Down Expand Up @@ -456,11 +472,6 @@ void VolOctree::initialize()
// This patch supports adaption
setAdaptionStatus(ADAPTION_CLEAN);

#if BITPIT_ENABLE_MPI==1
// This patch supports partitioning
setPartitioningStatus(PARTITIONING_CLEAN);
#endif

// Initialize the tolerance
//
// Since the patch re-implements the function to reset the tolerance,
Expand Down
21 changes: 21 additions & 0 deletions src/voloctree/voloctree_parallel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,27 @@ using namespace std;

namespace bitpit {

/*!
Initialize tree partitioning.
All octants are moved to the process identified by the rank zero in the
communicator.
*/
void VolOctree::initializeTreePartitioning()
{
// Move all the octants to the first processor
//
// Assigning a null weight to every octant but the last octant and then
// doing a load balance will have the effect of moving all the octants
// to the first process.
std::size_t nOctants = m_tree->getNumOctants();
std::vector<double> octantWeights(nOctants, 0.);
if (nOctants > 0) {
octantWeights[nOctants - 1] = 1.;
}
m_tree->loadBalance(m_partitioningOctantWeights.get());
}

/*!
Initialize the size, expressed in number of layers, of the tree ghost
cells halo.
Expand Down
8 changes: 0 additions & 8 deletions src/volunstructured/volunstructured.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ VolUnstructured::VolUnstructured(MPI_Comm communicator)
: VolumeKernel(true)
#endif
{
#if BITPIT_ENABLE_MPI==1
// This patch supports partitioning
setPartitioningStatus(PARTITIONING_CLEAN);
#endif
}

/*!
Expand Down Expand Up @@ -118,10 +114,6 @@ VolUnstructured::VolUnstructured(int id, int dimension, MPI_Comm communicator)
: VolumeKernel(id, dimension, true)
#endif
{
#if BITPIT_ENABLE_MPI==1
// This patch supports partitioning
setPartitioningStatus(PARTITIONING_CLEAN);
#endif
}

/*!
Expand Down
Loading

0 comments on commit a6d686a

Please sign in to comment.