Skip to content

Commit b29597f

Browse files
committed
patchkernel: explicitly define the 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.
1 parent 461e472 commit b29597f

18 files changed

+174
-76
lines changed

src/lineunstructured/lineunstructured.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace bitpit {
5050
among the processes
5151
*/
5252
LineUnstructured::LineUnstructured(MPI_Comm communicator)
53-
: LineKernel(communicator, 1, ADAPTION_MANUAL)
53+
: LineKernel(communicator, 1, ADAPTION_MANUAL, PARTITIONING_DISABLED)
5454
#else
5555
/*!
5656
Creates an uninitialized serial patch.
@@ -74,7 +74,7 @@ LineUnstructured::LineUnstructured()
7474
among the processes
7575
*/
7676
LineUnstructured::LineUnstructured(int dimension, MPI_Comm communicator)
77-
: LineKernel(PatchManager::AUTOMATIC_ID, dimension, communicator, 1, ADAPTION_MANUAL)
77+
: LineKernel(PatchManager::AUTOMATIC_ID, dimension, communicator, 1, ADAPTION_MANUAL, PARTITIONING_DISABLED)
7878
#else
7979
/*!
8080
Creates a patch.
@@ -101,7 +101,7 @@ LineUnstructured::LineUnstructured(int dimension)
101101
among the processes
102102
*/
103103
LineUnstructured::LineUnstructured(int id, int dimension, MPI_Comm communicator)
104-
: LineKernel(id, dimension, communicator, 1, ADAPTION_MANUAL)
104+
: LineKernel(id, dimension, communicator, 1, ADAPTION_MANUAL, PARTITIONING_DISABLED)
105105
#else
106106
/*!
107107
Creates a patch.
@@ -127,7 +127,7 @@ LineUnstructured::LineUnstructured(int id, int dimension)
127127
among the processes
128128
*/
129129
LineUnstructured::LineUnstructured(std::istream &stream, MPI_Comm communicator)
130-
: LineKernel(communicator, 1, ADAPTION_MANUAL)
130+
: LineKernel(communicator, 1, ADAPTION_MANUAL, PARTITIONING_DISABLED)
131131
#else
132132
/*!
133133
Creates a patch restoring the patch saved in the specified stream.

src/patchkernel/line_kernel.cpp

+15-6
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ namespace bitpit {
4141
\param haloSize is the size, expressed in number of layers, of the ghost
4242
cells halo
4343
\param adaptionMode is the adaption mode that will be used for the patch
44+
\param partitioningMode is the partitioning mode that will be used for the
45+
patch
4446
*/
45-
LineKernel::LineKernel(MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode)
46-
: PatchKernel(communicator, haloSize, adaptionMode)
47+
LineKernel::LineKernel(MPI_Comm communicator, std::size_t haloSize,
48+
AdaptionMode adaptionMode, PartitioningMode partitioningMode)
49+
: PatchKernel(communicator, haloSize, adaptionMode, partitioningMode)
4750
#else
4851
/*!
4952
Creates a patch.
@@ -72,9 +75,12 @@ LineKernel::LineKernel(AdaptionMode adaptionMode)
7275
\param haloSize is the size, expressed in number of layers, of the ghost
7376
cells halo
7477
\param adaptionMode is the adaption mode that will be used for the patch
78+
\param partitioningMode is the partitioning mode that will be used for the
79+
patch
7580
*/
76-
LineKernel::LineKernel(int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode)
77-
: PatchKernel(dimension, communicator, haloSize, adaptionMode)
81+
LineKernel::LineKernel(int dimension, MPI_Comm communicator, std::size_t haloSize,
82+
AdaptionMode adaptionMode, PartitioningMode partitioningMode)
83+
: PatchKernel(dimension, communicator, haloSize, adaptionMode, partitioningMode)
7884
#else
7985
/*!
8086
Creates a patch.
@@ -105,9 +111,12 @@ LineKernel::LineKernel(int dimension, AdaptionMode adaptionMode)
105111
\param haloSize is the size, expressed in number of layers, of the ghost
106112
cells halo
107113
\param adaptionMode is the adaption mode that will be used for the patch
114+
\param partitioningMode is the partitioning mode that will be used for the
115+
patch
108116
*/
109-
LineKernel::LineKernel(int id, int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode)
110-
: PatchKernel(id, dimension, communicator, haloSize, adaptionMode)
117+
LineKernel::LineKernel(int id, int dimension, MPI_Comm communicator, std::size_t haloSize,
118+
AdaptionMode adaptionMode, PartitioningMode partitioningMode)
119+
: PatchKernel(id, dimension, communicator, haloSize, adaptionMode, partitioningMode)
111120
#else
112121
/*!
113122
Creates a patch.

src/patchkernel/line_kernel.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ class LineKernel : public PatchKernel {
4949

5050
protected:
5151
#if BITPIT_ENABLE_MPI==1
52-
LineKernel(MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode);
53-
LineKernel(int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode);
54-
LineKernel(int id, int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode);
52+
LineKernel(MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode, PartitioningMode partitioningMode);
53+
LineKernel(int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode, PartitioningMode partitioningMode);
54+
LineKernel(int id, int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode, PartitioningMode partitioningMode);
5555
#else
5656
LineKernel(AdaptionMode adaptionMode);
5757
LineKernel(int dimension, AdaptionMode adaptionMode);

src/patchkernel/patch_kernel.cpp

+35-12
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,11 @@ namespace bitpit {
6565
\param haloSize is the size, expressed in number of layers, of the ghost
6666
cells halo
6767
\param adaptionMode is the adaption mode that will be used for the patch
68+
\param partitioningMode is the partitioning mode that will be used for the
69+
patch
6870
*/
69-
PatchKernel::PatchKernel(MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode)
71+
PatchKernel::PatchKernel(MPI_Comm communicator, std::size_t haloSize,
72+
AdaptionMode adaptionMode, PartitioningMode partitioningMode)
7073
#else
7174
/*!
7275
Creates a patch.
@@ -76,6 +79,9 @@ PatchKernel::PatchKernel(MPI_Comm communicator, std::size_t haloSize, AdaptionMo
7679
PatchKernel::PatchKernel(AdaptionMode adaptionMode)
7780
#endif
7881
: m_adaptionMode(adaptionMode)
82+
#if BITPIT_ENABLE_MPI==1
83+
, m_partitioningMode(partitioningMode)
84+
#endif
7985
{
8086
// Initialize the patch
8187
#if BITPIT_ENABLE_MPI==1
@@ -107,8 +113,11 @@ PatchKernel::PatchKernel(AdaptionMode adaptionMode)
107113
\param haloSize is the size, expressed in number of layers, of the ghost
108114
cells halo
109115
\param adaptionMode is the adaption mode that will be used for the patch
116+
\param partitioningMode is the partitioning mode that will be used for the
117+
patch
110118
*/
111-
PatchKernel::PatchKernel(int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode)
119+
PatchKernel::PatchKernel(int dimension, MPI_Comm communicator, std::size_t haloSize,
120+
AdaptionMode adaptionMode, PartitioningMode partitioningMode)
112121
#else
113122
/*!
114123
Creates a patch.
@@ -119,6 +128,9 @@ PatchKernel::PatchKernel(int dimension, MPI_Comm communicator, std::size_t haloS
119128
PatchKernel::PatchKernel(int dimension, AdaptionMode adaptionMode)
120129
#endif
121130
: m_adaptionMode(adaptionMode)
131+
#if BITPIT_ENABLE_MPI==1
132+
, m_partitioningMode(partitioningMode)
133+
#endif
122134
{
123135
// Initialize the patch
124136
#if BITPIT_ENABLE_MPI==1
@@ -154,8 +166,11 @@ PatchKernel::PatchKernel(int dimension, AdaptionMode adaptionMode)
154166
\param haloSize is the size, expressed in number of layers, of the ghost
155167
cells halo
156168
\param adaptionMode is the adaption mode that will be used for the patch
169+
\param partitioningMode is the partitioning mode that will be used for the
170+
patch
157171
*/
158-
PatchKernel::PatchKernel(int id, int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode)
172+
PatchKernel::PatchKernel(int id, int dimension, MPI_Comm communicator, std::size_t haloSize,
173+
AdaptionMode adaptionMode, PartitioningMode partitioningMode)
159174
#else
160175
/*!
161176
Creates a patch.
@@ -167,6 +182,9 @@ PatchKernel::PatchKernel(int id, int dimension, MPI_Comm communicator, std::size
167182
PatchKernel::PatchKernel(int id, int dimension, AdaptionMode adaptionMode)
168183
#endif
169184
: m_adaptionMode(adaptionMode)
185+
#if BITPIT_ENABLE_MPI==1
186+
, m_partitioningMode(partitioningMode)
187+
#endif
170188
{
171189
// Initialize the patch
172190
#if BITPIT_ENABLE_MPI==1
@@ -231,7 +249,8 @@ PatchKernel::PatchKernel(const PatchKernel &other)
231249
m_toleranceCustom(other.m_toleranceCustom),
232250
m_tolerance(other.m_tolerance)
233251
#if BITPIT_ENABLE_MPI==1
234-
, m_partitioningStatus(other.m_partitioningStatus),
252+
, m_partitioningMode(other.m_partitioningMode),
253+
m_partitioningStatus(other.m_partitioningStatus),
235254
m_owner(other.m_owner),
236255
m_haloSize(other.m_haloSize),
237256
m_partitioningCellsTag(other.m_partitioningCellsTag),
@@ -321,6 +340,7 @@ PatchKernel::PatchKernel(PatchKernel &&other)
321340
m_nProcessors(std::move(other.m_nProcessors))
322341
#if BITPIT_ENABLE_MPI==1
323342
, m_communicator(std::move(MPI_COMM_NULL)),
343+
m_partitioningMode(other.m_partitioningMode),
324344
m_partitioningStatus(std::move(other.m_partitioningStatus)),
325345
m_owner(std::move(other.m_owner)),
326346
m_haloSize(std::move(other.m_haloSize)),
@@ -410,6 +430,7 @@ PatchKernel & PatchKernel::operator=(PatchKernel &&other)
410430
m_nProcessors = std::move(other.m_nProcessors);
411431
#if BITPIT_ENABLE_MPI==1
412432
m_communicator = std::move(MPI_COMM_NULL);
433+
m_partitioningMode = std::move(other.m_partitioningMode);
413434
m_partitioningStatus = std::move(other.m_partitioningStatus);
414435
m_owner = std::move(other.m_owner);
415436
m_haloSize = std::move(other.m_haloSize);
@@ -519,11 +540,7 @@ void PatchKernel::initialize()
519540
initializeHaloSize(haloSize);
520541

521542
// Mark patch as partioned
522-
if (isPartitioned()) {
523-
setPartitioningStatus(PARTITIONING_CLEAN);
524-
} else {
525-
setPartitioningStatus(PARTITIONING_UNSUPPORTED);
526-
}
543+
setPartitioningStatus(PARTITIONING_CLEAN);
527544

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

8334-
// Partition status
8351+
// Partition information
83358352
#if BITPIT_ENABLE_MPI==1
8353+
utils::binary::write(stream, m_partitioningMode);
83368354
utils::binary::write(stream, m_partitioningStatus);
83378355
#else
8338-
utils::binary::write(stream, PARTITIONING_UNSUPPORTED);
8356+
utils::binary::write(stream, PARTITIONING_DISABLED);
8357+
utils::binary::write(stream, PARTITIONING_CLEAN);
83398358
#endif
83408359

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

8433-
// Partition status
8452+
// Partition information
84348453
#if BITPIT_ENABLE_MPI==1
8454+
utils::binary::read(stream, m_partitioningMode);
84358455
utils::binary::read(stream, m_partitioningStatus);
84368456
#else
8457+
PartitioningStatus dummyPartitioningMode;
8458+
utils::binary::read(stream, dummyPartitioningMode);
8459+
84378460
PartitioningStatus dummyPartitioningStatus;
84388461
utils::binary::read(stream, dummyPartitioningStatus);
84398462
#endif

src/patchkernel/patch_kernel.hpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,18 @@ friend class PatchManager;
357357
ADAPTION_ALTERED
358358
};
359359

360+
/*!
361+
Partitioning mode
362+
*/
363+
enum PartitioningMode {
364+
PARTITIONING_DISABLED = -1,
365+
PARTITIONING_ENABLED
366+
};
367+
360368
/*!
361369
Partitioning status
362370
*/
363371
enum PartitioningStatus {
364-
PARTITIONING_UNSUPPORTED = -1,
365372
PARTITIONING_CLEAN,
366373
PARTITIONING_PREPARED,
367374
PARTITIONING_ALTERED
@@ -741,6 +748,7 @@ friend class PatchManager;
741748
bool isPartitioned() const;
742749
bool isPartitioningSupported() const;
743750
bool arePartitioningInfoDirty(bool global = true) const;
751+
PartitioningMode getPartitioningMode() const;
744752
PartitioningStatus getPartitioningStatus(bool global = false) const;
745753
double evalPartitioningUnbalance() const;
746754
double evalPartitioningUnbalance(const std::unordered_map<long, double> &cellWeights) const;
@@ -788,9 +796,9 @@ friend class PatchManager;
788796
AlterationFlagsStorage m_alteredInterfaces;
789797

790798
#if BITPIT_ENABLE_MPI==1
791-
PatchKernel(MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode);
792-
PatchKernel(int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode);
793-
PatchKernel(int id, int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode);
799+
PatchKernel(MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode, PartitioningMode partitioningMode);
800+
PatchKernel(int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode, PartitioningMode partitioningMode);
801+
PatchKernel(int id, int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode, PartitioningMode partitioningMode);
794802
#else
795803
PatchKernel(AdaptionMode adaptionMode);
796804
PatchKernel(int dimension, AdaptionMode adaptionMode);
@@ -922,6 +930,7 @@ friend class PatchManager;
922930
virtual void _setHaloSize(std::size_t haloSize);
923931

924932
void setPartitioned(bool partitioned);
933+
void setPartitioningMode(PartitioningMode mode);
925934
void setPartitioningStatus(PartitioningStatus status);
926935
virtual std::vector<adaption::Info> _partitioningPrepare(const std::unordered_map<long, double> &cellWeights, double defaultWeight, bool trackPartitioning);
927936
virtual std::vector<adaption::Info> _partitioningPrepare(const std::unordered_map<long, int> &cellRanks, bool trackPartitioning);
@@ -1007,6 +1016,7 @@ friend class PatchManager;
10071016
int m_nProcessors;
10081017
#if BITPIT_ENABLE_MPI==1
10091018
MPI_Comm m_communicator;
1019+
PartitioningMode m_partitioningMode;
10101020
PartitioningStatus m_partitioningStatus;
10111021

10121022
int m_owner;

src/patchkernel/patch_kernel_parallel.cpp

+30-1
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,36 @@ bool PatchKernel::isPartitioned() const
17861786
*/
17871787
bool PatchKernel::isPartitioningSupported() const
17881788
{
1789-
return (getPartitioningStatus() != PARTITIONING_UNSUPPORTED);
1789+
return (getPartitioningMode() != PARTITIONING_DISABLED);
1790+
}
1791+
1792+
/*!
1793+
Returns the current partitioning mode.
1794+
1795+
Partitioning mode tells if the patch can be partitioned across the processes.
1796+
1797+
The following partitioning modes are supported:
1798+
- disabled, no partitioning can be performed;
1799+
- enabled, the patch can be partitioned across the processes.
1800+
1801+
\return The current partitioning mode.
1802+
*/
1803+
PatchKernel::PartitioningMode PatchKernel::getPartitioningMode() const
1804+
{
1805+
return m_partitioningMode;
1806+
}
1807+
1808+
/*!
1809+
Set the current partitioning mode.
1810+
1811+
See PatchKernel::getPartitioningMode() for a list of supported partitioning
1812+
modes.
1813+
1814+
\param mode is the partitioning mode that will be set
1815+
*/
1816+
void PatchKernel::setPartitioningMode(PartitioningMode mode)
1817+
{
1818+
m_partitioningMode = mode;
17901819
}
17911820

17921821
/*!

src/patchkernel/point_kernel.cpp

+15-6
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ namespace bitpit {
3939
will be created
4040
\param adaptionMode is the adaption mode that will be used for the patch
4141
*/
42-
PointKernel::PointKernel(MPI_Comm communicator, AdaptionMode adaptionMode)
43-
: PatchKernel(communicator, 0, adaptionMode)
42+
PointKernel::PointKernel(MPI_Comm communicator,
43+
AdaptionMode adaptionMode, PartitioningMode partitioningMode)
44+
: PatchKernel(communicator, 0, adaptionMode, partitioningMode)
4445
#else
4546
/*!
4647
Creates a patch.
@@ -67,15 +68,20 @@ PointKernel::PointKernel(AdaptionMode adaptionMode)
6768
among the processes. If a null comunicator is provided, a serial patch
6869
will be created
6970
\param adaptionMode is the adaption mode that will be used for the patch
71+
\param partitioningMode is the partitioning mode that will be used for the
72+
patch
7073
*/
71-
PointKernel::PointKernel(int dimension, MPI_Comm communicator, AdaptionMode adaptionMode)
72-
: PatchKernel(dimension, communicator, 0, adaptionMode)
74+
PointKernel::PointKernel(int dimension, MPI_Comm communicator,
75+
AdaptionMode adaptionMode, PartitioningMode partitioningMode)
76+
: PatchKernel(dimension, communicator, 0, adaptionMode, partitioningMode)
7377
#else
7478
/*!
7579
Creates a patch.
7680
7781
\param dimension is the dimension of the patch
7882
\param adaptionMode is the adaption mode that will be used for the patch
83+
\param partitioningMode is the partitioning mode that will be used for the
84+
patch
7985
*/
8086
PointKernel::PointKernel(int dimension, AdaptionMode adaptionMode)
8187
: PatchKernel(dimension, adaptionMode)
@@ -98,9 +104,12 @@ PointKernel::PointKernel(int dimension, AdaptionMode adaptionMode)
98104
among the processes. If a null comunicator is provided, a serial patch
99105
will be created
100106
\param adaptionMode is the adaption mode that will be used for the patch
107+
\param partitioningMode is the partitioning mode that will be used for the
108+
patch
101109
*/
102-
PointKernel::PointKernel(int id, int dimension, MPI_Comm communicator, AdaptionMode adaptionMode)
103-
: PatchKernel(id, dimension, communicator, 0, adaptionMode)
110+
PointKernel::PointKernel(int id, int dimension, MPI_Comm communicator,
111+
AdaptionMode adaptionMode, PartitioningMode partitioningMode)
112+
: PatchKernel(id, dimension, communicator, 0, adaptionMode, partitioningMode)
104113
#else
105114
/*!
106115
Creates a patch.

src/patchkernel/point_kernel.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ class PointKernel : public PatchKernel {
4343

4444
protected:
4545
#if BITPIT_ENABLE_MPI==1
46-
PointKernel(MPI_Comm communicator, AdaptionMode adaptionMode);
47-
PointKernel(int dimension, MPI_Comm communicator, AdaptionMode adaptionMode);
48-
PointKernel(int id, int dimension, MPI_Comm communicator, AdaptionMode adaptionMode);
46+
PointKernel(MPI_Comm communicator, AdaptionMode adaptionMode, PartitioningMode partitioningMode);
47+
PointKernel(int dimension, MPI_Comm communicator, AdaptionMode adaptionMode, PartitioningMode partitioningMode);
48+
PointKernel(int id, int dimension, MPI_Comm communicator, AdaptionMode adaptionMode, PartitioningMode partitioningMode);
4949
#else
5050
PointKernel(AdaptionMode adaptionMode);
5151
PointKernel(int dimension, AdaptionMode adaptionMode);

0 commit comments

Comments
 (0)