Skip to content

Commit

Permalink
patchkernel: explicitly define the partitioning mode
Browse files Browse the repository at this point in the history
Partitioning mode tells if the patch can be partitioned across the processes.

The following partitioning modes are supported:
 - disabled, no partitioning can be performed;
 - enabled, the patch can be partitioned across the processes.
  • Loading branch information
andrea-iob committed Feb 6, 2023
1 parent 461e472 commit b29597f
Show file tree
Hide file tree
Showing 18 changed files with 174 additions and 76 deletions.
8 changes: 4 additions & 4 deletions src/lineunstructured/lineunstructured.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace bitpit {
among the processes
*/
LineUnstructured::LineUnstructured(MPI_Comm communicator)
: LineKernel(communicator, 1, ADAPTION_MANUAL)
: LineKernel(communicator, 1, ADAPTION_MANUAL, PARTITIONING_DISABLED)
#else
/*!
Creates an uninitialized serial patch.
Expand All @@ -74,7 +74,7 @@ LineUnstructured::LineUnstructured()
among the processes
*/
LineUnstructured::LineUnstructured(int dimension, MPI_Comm communicator)
: LineKernel(PatchManager::AUTOMATIC_ID, dimension, communicator, 1, ADAPTION_MANUAL)
: LineKernel(PatchManager::AUTOMATIC_ID, dimension, communicator, 1, ADAPTION_MANUAL, PARTITIONING_DISABLED)
#else
/*!
Creates a patch.
Expand All @@ -101,7 +101,7 @@ LineUnstructured::LineUnstructured(int dimension)
among the processes
*/
LineUnstructured::LineUnstructured(int id, int dimension, MPI_Comm communicator)
: LineKernel(id, dimension, communicator, 1, ADAPTION_MANUAL)
: LineKernel(id, dimension, communicator, 1, ADAPTION_MANUAL, PARTITIONING_DISABLED)
#else
/*!
Creates a patch.
Expand All @@ -127,7 +127,7 @@ LineUnstructured::LineUnstructured(int id, int dimension)
among the processes
*/
LineUnstructured::LineUnstructured(std::istream &stream, MPI_Comm communicator)
: LineKernel(communicator, 1, ADAPTION_MANUAL)
: LineKernel(communicator, 1, ADAPTION_MANUAL, PARTITIONING_DISABLED)
#else
/*!
Creates a patch restoring the patch saved in the specified stream.
Expand Down
21 changes: 15 additions & 6 deletions src/patchkernel/line_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ namespace bitpit {
\param haloSize is the size, expressed in number of layers, of the ghost
cells halo
\param adaptionMode is the adaption mode that will be used for the patch
\param partitioningMode is the partitioning mode that will be used for the
patch
*/
LineKernel::LineKernel(MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode)
: PatchKernel(communicator, haloSize, adaptionMode)
LineKernel::LineKernel(MPI_Comm communicator, std::size_t haloSize,
AdaptionMode adaptionMode, PartitioningMode partitioningMode)
: PatchKernel(communicator, haloSize, adaptionMode, partitioningMode)
#else
/*!
Creates a patch.
Expand Down Expand Up @@ -72,9 +75,12 @@ LineKernel::LineKernel(AdaptionMode adaptionMode)
\param haloSize is the size, expressed in number of layers, of the ghost
cells halo
\param adaptionMode is the adaption mode that will be used for the patch
\param partitioningMode is the partitioning mode that will be used for the
patch
*/
LineKernel::LineKernel(int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode)
: PatchKernel(dimension, communicator, haloSize, adaptionMode)
LineKernel::LineKernel(int dimension, MPI_Comm communicator, std::size_t haloSize,
AdaptionMode adaptionMode, PartitioningMode partitioningMode)
: PatchKernel(dimension, communicator, haloSize, adaptionMode, partitioningMode)
#else
/*!
Creates a patch.
Expand Down Expand Up @@ -105,9 +111,12 @@ LineKernel::LineKernel(int dimension, AdaptionMode adaptionMode)
\param haloSize is the size, expressed in number of layers, of the ghost
cells halo
\param adaptionMode is the adaption mode that will be used for the patch
\param partitioningMode is the partitioning mode that will be used for the
patch
*/
LineKernel::LineKernel(int id, int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode)
: PatchKernel(id, dimension, communicator, haloSize, adaptionMode)
LineKernel::LineKernel(int id, int dimension, MPI_Comm communicator, std::size_t haloSize,
AdaptionMode adaptionMode, PartitioningMode partitioningMode)
: PatchKernel(id, dimension, communicator, haloSize, adaptionMode, partitioningMode)
#else
/*!
Creates a patch.
Expand Down
6 changes: 3 additions & 3 deletions src/patchkernel/line_kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class LineKernel : public PatchKernel {

protected:
#if BITPIT_ENABLE_MPI==1
LineKernel(MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode);
LineKernel(int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode);
LineKernel(int id, int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode);
LineKernel(MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode, PartitioningMode partitioningMode);
LineKernel(int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode, PartitioningMode partitioningMode);
LineKernel(int id, int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode, PartitioningMode partitioningMode);
#else
LineKernel(AdaptionMode adaptionMode);
LineKernel(int dimension, AdaptionMode adaptionMode);
Expand Down
47 changes: 35 additions & 12 deletions src/patchkernel/patch_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ namespace bitpit {
\param haloSize is the size, expressed in number of layers, of the ghost
cells halo
\param adaptionMode is the adaption mode that will be used for the patch
\param partitioningMode is the partitioning mode that will be used for the
patch
*/
PatchKernel::PatchKernel(MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode)
PatchKernel::PatchKernel(MPI_Comm communicator, std::size_t haloSize,
AdaptionMode adaptionMode, PartitioningMode partitioningMode)
#else
/*!
Creates a patch.
Expand All @@ -76,6 +79,9 @@ PatchKernel::PatchKernel(MPI_Comm communicator, std::size_t haloSize, AdaptionMo
PatchKernel::PatchKernel(AdaptionMode adaptionMode)
#endif
: m_adaptionMode(adaptionMode)
#if BITPIT_ENABLE_MPI==1
, m_partitioningMode(partitioningMode)
#endif
{
// Initialize the patch
#if BITPIT_ENABLE_MPI==1
Expand Down Expand Up @@ -107,8 +113,11 @@ PatchKernel::PatchKernel(AdaptionMode adaptionMode)
\param haloSize is the size, expressed in number of layers, of the ghost
cells halo
\param adaptionMode is the adaption mode that will be used for the patch
\param partitioningMode is the partitioning mode that will be used for the
patch
*/
PatchKernel::PatchKernel(int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode)
PatchKernel::PatchKernel(int dimension, MPI_Comm communicator, std::size_t haloSize,
AdaptionMode adaptionMode, PartitioningMode partitioningMode)
#else
/*!
Creates a patch.
Expand All @@ -119,6 +128,9 @@ PatchKernel::PatchKernel(int dimension, MPI_Comm communicator, std::size_t haloS
PatchKernel::PatchKernel(int dimension, AdaptionMode adaptionMode)
#endif
: m_adaptionMode(adaptionMode)
#if BITPIT_ENABLE_MPI==1
, m_partitioningMode(partitioningMode)
#endif
{
// Initialize the patch
#if BITPIT_ENABLE_MPI==1
Expand Down Expand Up @@ -154,8 +166,11 @@ PatchKernel::PatchKernel(int dimension, AdaptionMode adaptionMode)
\param haloSize is the size, expressed in number of layers, of the ghost
cells halo
\param adaptionMode is the adaption mode that will be used for the patch
\param partitioningMode is the partitioning mode that will be used for the
patch
*/
PatchKernel::PatchKernel(int id, int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode)
PatchKernel::PatchKernel(int id, int dimension, MPI_Comm communicator, std::size_t haloSize,
AdaptionMode adaptionMode, PartitioningMode partitioningMode)
#else
/*!
Creates a patch.
Expand All @@ -167,6 +182,9 @@ PatchKernel::PatchKernel(int id, int dimension, MPI_Comm communicator, std::size
PatchKernel::PatchKernel(int id, int dimension, AdaptionMode adaptionMode)
#endif
: m_adaptionMode(adaptionMode)
#if BITPIT_ENABLE_MPI==1
, m_partitioningMode(partitioningMode)
#endif
{
// Initialize the patch
#if BITPIT_ENABLE_MPI==1
Expand Down Expand Up @@ -231,7 +249,8 @@ PatchKernel::PatchKernel(const PatchKernel &other)
m_toleranceCustom(other.m_toleranceCustom),
m_tolerance(other.m_tolerance)
#if BITPIT_ENABLE_MPI==1
, m_partitioningStatus(other.m_partitioningStatus),
, m_partitioningMode(other.m_partitioningMode),
m_partitioningStatus(other.m_partitioningStatus),
m_owner(other.m_owner),
m_haloSize(other.m_haloSize),
m_partitioningCellsTag(other.m_partitioningCellsTag),
Expand Down Expand Up @@ -321,6 +340,7 @@ PatchKernel::PatchKernel(PatchKernel &&other)
m_nProcessors(std::move(other.m_nProcessors))
#if BITPIT_ENABLE_MPI==1
, m_communicator(std::move(MPI_COMM_NULL)),
m_partitioningMode(other.m_partitioningMode),
m_partitioningStatus(std::move(other.m_partitioningStatus)),
m_owner(std::move(other.m_owner)),
m_haloSize(std::move(other.m_haloSize)),
Expand Down Expand Up @@ -410,6 +430,7 @@ PatchKernel & PatchKernel::operator=(PatchKernel &&other)
m_nProcessors = std::move(other.m_nProcessors);
#if BITPIT_ENABLE_MPI==1
m_communicator = std::move(MPI_COMM_NULL);
m_partitioningMode = std::move(other.m_partitioningMode);
m_partitioningStatus = std::move(other.m_partitioningStatus);
m_owner = std::move(other.m_owner);
m_haloSize = std::move(other.m_haloSize);
Expand Down Expand Up @@ -519,11 +540,7 @@ void PatchKernel::initialize()
initializeHaloSize(haloSize);

// Mark patch as partioned
if (isPartitioned()) {
setPartitioningStatus(PARTITIONING_CLEAN);
} else {
setPartitioningStatus(PARTITIONING_UNSUPPORTED);
}
setPartitioningStatus(PARTITIONING_CLEAN);

// Initialize partitioning tags
m_partitioningCellsTag = -1;
Expand Down Expand Up @@ -8331,11 +8348,13 @@ bool PatchKernel::dump(std::ostream &stream) const
utils::binary::write(stream, m_adaptionMode);
utils::binary::write(stream, m_adaptionStatus);

// Partition status
// Partition information
#if BITPIT_ENABLE_MPI==1
utils::binary::write(stream, m_partitioningMode);
utils::binary::write(stream, m_partitioningStatus);
#else
utils::binary::write(stream, PARTITIONING_UNSUPPORTED);
utils::binary::write(stream, PARTITIONING_DISABLED);
utils::binary::write(stream, PARTITIONING_CLEAN);
#endif

// Adjacencies build strategy
Expand Down Expand Up @@ -8430,10 +8449,14 @@ void PatchKernel::restore(std::istream &stream, bool reregister)
utils::binary::read(stream, m_adaptionMode);
utils::binary::read(stream, m_adaptionStatus);

// Partition status
// Partition information
#if BITPIT_ENABLE_MPI==1
utils::binary::read(stream, m_partitioningMode);
utils::binary::read(stream, m_partitioningStatus);
#else
PartitioningStatus dummyPartitioningMode;
utils::binary::read(stream, dummyPartitioningMode);

PartitioningStatus dummyPartitioningStatus;
utils::binary::read(stream, dummyPartitioningStatus);
#endif
Expand Down
18 changes: 14 additions & 4 deletions src/patchkernel/patch_kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,18 @@ friend class PatchManager;
ADAPTION_ALTERED
};

/*!
Partitioning mode
*/
enum PartitioningMode {
PARTITIONING_DISABLED = -1,
PARTITIONING_ENABLED
};

/*!
Partitioning status
*/
enum PartitioningStatus {
PARTITIONING_UNSUPPORTED = -1,
PARTITIONING_CLEAN,
PARTITIONING_PREPARED,
PARTITIONING_ALTERED
Expand Down Expand Up @@ -741,6 +748,7 @@ friend class PatchManager;
bool isPartitioned() const;
bool isPartitioningSupported() const;
bool arePartitioningInfoDirty(bool global = true) const;
PartitioningMode getPartitioningMode() const;
PartitioningStatus getPartitioningStatus(bool global = false) const;
double evalPartitioningUnbalance() const;
double evalPartitioningUnbalance(const std::unordered_map<long, double> &cellWeights) const;
Expand Down Expand Up @@ -788,9 +796,9 @@ friend class PatchManager;
AlterationFlagsStorage m_alteredInterfaces;

#if BITPIT_ENABLE_MPI==1
PatchKernel(MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode);
PatchKernel(int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode);
PatchKernel(int id, int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode);
PatchKernel(MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode, PartitioningMode partitioningMode);
PatchKernel(int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode, PartitioningMode partitioningMode);
PatchKernel(int id, int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode, PartitioningMode partitioningMode);
#else
PatchKernel(AdaptionMode adaptionMode);
PatchKernel(int dimension, AdaptionMode adaptionMode);
Expand Down Expand Up @@ -922,6 +930,7 @@ friend class PatchManager;
virtual void _setHaloSize(std::size_t haloSize);

void setPartitioned(bool partitioned);
void setPartitioningMode(PartitioningMode mode);
void setPartitioningStatus(PartitioningStatus status);
virtual std::vector<adaption::Info> _partitioningPrepare(const std::unordered_map<long, double> &cellWeights, double defaultWeight, bool trackPartitioning);
virtual std::vector<adaption::Info> _partitioningPrepare(const std::unordered_map<long, int> &cellRanks, bool trackPartitioning);
Expand Down Expand Up @@ -1007,6 +1016,7 @@ friend class PatchManager;
int m_nProcessors;
#if BITPIT_ENABLE_MPI==1
MPI_Comm m_communicator;
PartitioningMode m_partitioningMode;
PartitioningStatus m_partitioningStatus;

int m_owner;
Expand Down
31 changes: 30 additions & 1 deletion src/patchkernel/patch_kernel_parallel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1786,7 +1786,36 @@ bool PatchKernel::isPartitioned() const
*/
bool PatchKernel::isPartitioningSupported() const
{
return (getPartitioningStatus() != PARTITIONING_UNSUPPORTED);
return (getPartitioningMode() != PARTITIONING_DISABLED);
}

/*!
Returns the current partitioning mode.
Partitioning mode tells if the patch can be partitioned across the processes.
The following partitioning modes are supported:
- disabled, no partitioning can be performed;
- enabled, the patch can be partitioned across the processes.
\return The current partitioning mode.
*/
PatchKernel::PartitioningMode PatchKernel::getPartitioningMode() const
{
return m_partitioningMode;
}

/*!
Set the current partitioning mode.
See PatchKernel::getPartitioningMode() for a list of supported partitioning
modes.
\param mode is the partitioning mode that will be set
*/
void PatchKernel::setPartitioningMode(PartitioningMode mode)
{
m_partitioningMode = mode;
}

/*!
Expand Down
21 changes: 15 additions & 6 deletions src/patchkernel/point_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ namespace bitpit {
will be created
\param adaptionMode is the adaption mode that will be used for the patch
*/
PointKernel::PointKernel(MPI_Comm communicator, AdaptionMode adaptionMode)
: PatchKernel(communicator, 0, adaptionMode)
PointKernel::PointKernel(MPI_Comm communicator,
AdaptionMode adaptionMode, PartitioningMode partitioningMode)
: PatchKernel(communicator, 0, adaptionMode, partitioningMode)
#else
/*!
Creates a patch.
Expand All @@ -67,15 +68,20 @@ PointKernel::PointKernel(AdaptionMode adaptionMode)
among the processes. If a null comunicator is provided, a serial patch
will be created
\param adaptionMode is the adaption mode that will be used for the patch
\param partitioningMode is the partitioning mode that will be used for the
patch
*/
PointKernel::PointKernel(int dimension, MPI_Comm communicator, AdaptionMode adaptionMode)
: PatchKernel(dimension, communicator, 0, adaptionMode)
PointKernel::PointKernel(int dimension, MPI_Comm communicator,
AdaptionMode adaptionMode, PartitioningMode partitioningMode)
: PatchKernel(dimension, communicator, 0, adaptionMode, partitioningMode)
#else
/*!
Creates a patch.
\param dimension is the dimension of the patch
\param adaptionMode is the adaption mode that will be used for the patch
\param partitioningMode is the partitioning mode that will be used for the
patch
*/
PointKernel::PointKernel(int dimension, AdaptionMode adaptionMode)
: PatchKernel(dimension, adaptionMode)
Expand All @@ -98,9 +104,12 @@ PointKernel::PointKernel(int dimension, AdaptionMode adaptionMode)
among the processes. If a null comunicator is provided, a serial patch
will be created
\param adaptionMode is the adaption mode that will be used for the patch
\param partitioningMode is the partitioning mode that will be used for the
patch
*/
PointKernel::PointKernel(int id, int dimension, MPI_Comm communicator, AdaptionMode adaptionMode)
: PatchKernel(id, dimension, communicator, 0, adaptionMode)
PointKernel::PointKernel(int id, int dimension, MPI_Comm communicator,
AdaptionMode adaptionMode, PartitioningMode partitioningMode)
: PatchKernel(id, dimension, communicator, 0, adaptionMode, partitioningMode)
#else
/*!
Creates a patch.
Expand Down
6 changes: 3 additions & 3 deletions src/patchkernel/point_kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class PointKernel : public PatchKernel {

protected:
#if BITPIT_ENABLE_MPI==1
PointKernel(MPI_Comm communicator, AdaptionMode adaptionMode);
PointKernel(int dimension, MPI_Comm communicator, AdaptionMode adaptionMode);
PointKernel(int id, int dimension, MPI_Comm communicator, AdaptionMode adaptionMode);
PointKernel(MPI_Comm communicator, AdaptionMode adaptionMode, PartitioningMode partitioningMode);
PointKernel(int dimension, MPI_Comm communicator, AdaptionMode adaptionMode, PartitioningMode partitioningMode);
PointKernel(int id, int dimension, MPI_Comm communicator, AdaptionMode adaptionMode, PartitioningMode partitioningMode);
#else
PointKernel(AdaptionMode adaptionMode);
PointKernel(int dimension, AdaptionMode adaptionMode);
Expand Down
Loading

0 comments on commit b29597f

Please sign in to comment.