Skip to content

Commit 4dab160

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 fd7432f commit 4dab160

File tree

18 files changed

+174
-76
lines changed

18 files changed

+174
-76
lines changed

src/lineunstructured/lineunstructured.cpp

Lines changed: 4 additions & 4 deletions
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_ENABLED)
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_ENABLED)
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_ENABLED)
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_ENABLED)
131131
#else
132132
/*!
133133
Creates a patch restoring the patch saved in the specified stream.

src/patchkernel/line_kernel.cpp

Lines changed: 15 additions & 6 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ namespace bitpit {
6666
\param haloSize is the size, expressed in number of layers, of the ghost
6767
cells halo
6868
\param adaptionMode is the adaption mode that will be used for the patch
69+
\param partitioningMode is the partitioning mode that will be used for the
70+
patch
6971
*/
70-
PatchKernel::PatchKernel(MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode)
72+
PatchKernel::PatchKernel(MPI_Comm communicator, std::size_t haloSize,
73+
AdaptionMode adaptionMode, PartitioningMode partitioningMode)
7174
#else
7275
/*!
7376
Creates a patch.
@@ -77,6 +80,9 @@ PatchKernel::PatchKernel(MPI_Comm communicator, std::size_t haloSize, AdaptionMo
7780
PatchKernel::PatchKernel(AdaptionMode adaptionMode)
7881
#endif
7982
: m_adaptionMode(adaptionMode)
83+
#if BITPIT_ENABLE_MPI==1
84+
, m_partitioningMode(partitioningMode)
85+
#endif
8086
{
8187
// Initialize the patch
8288
#if BITPIT_ENABLE_MPI==1
@@ -108,8 +114,11 @@ PatchKernel::PatchKernel(AdaptionMode adaptionMode)
108114
\param haloSize is the size, expressed in number of layers, of the ghost
109115
cells halo
110116
\param adaptionMode is the adaption mode that will be used for the patch
117+
\param partitioningMode is the partitioning mode that will be used for the
118+
patch
111119
*/
112-
PatchKernel::PatchKernel(int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode)
120+
PatchKernel::PatchKernel(int dimension, MPI_Comm communicator, std::size_t haloSize,
121+
AdaptionMode adaptionMode, PartitioningMode partitioningMode)
113122
#else
114123
/*!
115124
Creates a patch.
@@ -120,6 +129,9 @@ PatchKernel::PatchKernel(int dimension, MPI_Comm communicator, std::size_t haloS
120129
PatchKernel::PatchKernel(int dimension, AdaptionMode adaptionMode)
121130
#endif
122131
: m_adaptionMode(adaptionMode)
132+
#if BITPIT_ENABLE_MPI==1
133+
, m_partitioningMode(partitioningMode)
134+
#endif
123135
{
124136
// Initialize the patch
125137
#if BITPIT_ENABLE_MPI==1
@@ -155,8 +167,11 @@ PatchKernel::PatchKernel(int dimension, AdaptionMode adaptionMode)
155167
\param haloSize is the size, expressed in number of layers, of the ghost
156168
cells halo
157169
\param adaptionMode is the adaption mode that will be used for the patch
170+
\param partitioningMode is the partitioning mode that will be used for the
171+
patch
158172
*/
159-
PatchKernel::PatchKernel(int id, int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode)
173+
PatchKernel::PatchKernel(int id, int dimension, MPI_Comm communicator, std::size_t haloSize,
174+
AdaptionMode adaptionMode, PartitioningMode partitioningMode)
160175
#else
161176
/*!
162177
Creates a patch.
@@ -168,6 +183,9 @@ PatchKernel::PatchKernel(int id, int dimension, MPI_Comm communicator, std::size
168183
PatchKernel::PatchKernel(int id, int dimension, AdaptionMode adaptionMode)
169184
#endif
170185
: m_adaptionMode(adaptionMode)
186+
#if BITPIT_ENABLE_MPI==1
187+
, m_partitioningMode(partitioningMode)
188+
#endif
171189
{
172190
// Initialize the patch
173191
#if BITPIT_ENABLE_MPI==1
@@ -232,7 +250,8 @@ PatchKernel::PatchKernel(const PatchKernel &other)
232250
m_toleranceCustom(other.m_toleranceCustom),
233251
m_tolerance(other.m_tolerance)
234252
#if BITPIT_ENABLE_MPI==1
235-
, m_partitioningStatus(other.m_partitioningStatus),
253+
, m_partitioningMode(other.m_partitioningMode),
254+
m_partitioningStatus(other.m_partitioningStatus),
236255
m_owner(other.m_owner),
237256
m_haloSize(other.m_haloSize),
238257
m_partitioningCellsTag(other.m_partitioningCellsTag),
@@ -322,6 +341,7 @@ PatchKernel::PatchKernel(PatchKernel &&other)
322341
m_nProcessors(std::move(other.m_nProcessors))
323342
#if BITPIT_ENABLE_MPI==1
324343
, m_communicator(std::move(MPI_COMM_NULL)),
344+
m_partitioningMode(other.m_partitioningMode),
325345
m_partitioningStatus(std::move(other.m_partitioningStatus)),
326346
m_owner(std::move(other.m_owner)),
327347
m_haloSize(std::move(other.m_haloSize)),
@@ -411,6 +431,7 @@ PatchKernel & PatchKernel::operator=(PatchKernel &&other)
411431
m_nProcessors = std::move(other.m_nProcessors);
412432
#if BITPIT_ENABLE_MPI==1
413433
m_communicator = std::move(MPI_COMM_NULL);
434+
m_partitioningMode = std::move(other.m_partitioningMode);
414435
m_partitioningStatus = std::move(other.m_partitioningStatus);
415436
m_owner = std::move(other.m_owner);
416437
m_haloSize = std::move(other.m_haloSize);
@@ -520,11 +541,7 @@ void PatchKernel::initialize()
520541
initializeHaloSize(haloSize);
521542

522543
// Mark patch as partioned
523-
if (getCommunicator() != MPI_COMM_NULL) {
524-
setPartitioningStatus(PARTITIONING_CLEAN);
525-
} else {
526-
setPartitioningStatus(PARTITIONING_UNSUPPORTED);
527-
}
544+
setPartitioningStatus(PARTITIONING_CLEAN);
528545

529546
// Initialize partitioning tags
530547
m_partitioningCellsTag = -1;
@@ -8325,11 +8342,13 @@ bool PatchKernel::dump(std::ostream &stream) const
83258342
utils::binary::write(stream, m_adaptionMode);
83268343
utils::binary::write(stream, m_adaptionStatus);
83278344

8328-
// Partition status
8345+
// Partition information
83298346
#if BITPIT_ENABLE_MPI==1
8347+
utils::binary::write(stream, m_partitioningMode);
83308348
utils::binary::write(stream, m_partitioningStatus);
83318349
#else
8332-
utils::binary::write(stream, PARTITIONING_UNSUPPORTED);
8350+
utils::binary::write(stream, PARTITIONING_DISABLED);
8351+
utils::binary::write(stream, PARTITIONING_CLEAN);
83338352
#endif
83348353

83358354
// Adjacencies build strategy
@@ -8424,10 +8443,14 @@ void PatchKernel::restore(std::istream &stream, bool reregister)
84248443
utils::binary::read(stream, m_adaptionMode);
84258444
utils::binary::read(stream, m_adaptionStatus);
84268445

8427-
// Partition status
8446+
// Partition information
84288447
#if BITPIT_ENABLE_MPI==1
8448+
utils::binary::read(stream, m_partitioningMode);
84298449
utils::binary::read(stream, m_partitioningStatus);
84308450
#else
8451+
PartitioningStatus dummyPartitioningMode;
8452+
utils::binary::read(stream, dummyPartitioningMode);
8453+
84318454
PartitioningStatus dummyPartitioningStatus;
84328455
utils::binary::read(stream, dummyPartitioningStatus);
84338456
#endif

src/patchkernel/patch_kernel.hpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,18 @@ friend class PatchManager;
361361
ADAPTION_ALTERED
362362
};
363363

364+
/*!
365+
Partitioning mode
366+
*/
367+
enum PartitioningMode {
368+
PARTITIONING_DISABLED = -1, //! No partitioning can be performed
369+
PARTITIONING_ENABLED //! The patch can be partitioned across the processes
370+
};
371+
364372
/*!
365373
Partitioning status
366374
*/
367375
enum PartitioningStatus {
368-
PARTITIONING_UNSUPPORTED = -1,
369376
PARTITIONING_CLEAN,
370377
PARTITIONING_PREPARED,
371378
PARTITIONING_ALTERED
@@ -749,6 +756,7 @@ friend class PatchManager;
749756
bool isPartitioned() const;
750757
bool isPartitioningSupported() const;
751758
bool arePartitioningInfoDirty(bool global = true) const;
759+
PartitioningMode getPartitioningMode() const;
752760
PartitioningStatus getPartitioningStatus(bool global = false) const;
753761
double evalPartitioningUnbalance() const;
754762
double evalPartitioningUnbalance(const std::unordered_map<long, double> &cellWeights) const;
@@ -813,9 +821,9 @@ friend class PatchManager;
813821
AlterationFlagsStorage m_alteredInterfaces;
814822

815823
#if BITPIT_ENABLE_MPI==1
816-
PatchKernel(MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode);
817-
PatchKernel(int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode);
818-
PatchKernel(int id, int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode);
824+
PatchKernel(MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode, PartitioningMode partitioningMode);
825+
PatchKernel(int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode, PartitioningMode partitioningMode);
826+
PatchKernel(int id, int dimension, MPI_Comm communicator, std::size_t haloSize, AdaptionMode adaptionMode, PartitioningMode partitioningMode);
819827
#else
820828
PatchKernel(AdaptionMode adaptionMode);
821829
PatchKernel(int dimension, AdaptionMode adaptionMode);
@@ -950,6 +958,7 @@ friend class PatchManager;
950958
virtual void _setHaloSize(std::size_t haloSize);
951959

952960
void setPartitioned(bool partitioned);
961+
void setPartitioningMode(PartitioningMode mode);
953962
void setPartitioningStatus(PartitioningStatus status);
954963
virtual std::vector<adaption::Info> _partitioningPrepare(const std::unordered_map<long, double> &cellWeights, double defaultWeight, bool trackPartitioning);
955964
virtual std::vector<adaption::Info> _partitioningPrepare(const std::unordered_map<long, int> &cellRanks, bool trackPartitioning);
@@ -1032,6 +1041,7 @@ friend class PatchManager;
10321041
int m_nProcessors;
10331042
#if BITPIT_ENABLE_MPI==1
10341043
MPI_Comm m_communicator;
1044+
PartitioningMode m_partitioningMode;
10351045
PartitioningStatus m_partitioningStatus;
10361046

10371047
int m_owner;

src/patchkernel/patch_kernel_parallel.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1695,7 +1695,36 @@ bool PatchKernel::isPartitioned() const
16951695
*/
16961696
bool PatchKernel::isPartitioningSupported() const
16971697
{
1698-
return (getPartitioningStatus() != PARTITIONING_UNSUPPORTED);
1698+
return (getPartitioningMode() != PARTITIONING_DISABLED);
1699+
}
1700+
1701+
/*!
1702+
Returns the current partitioning mode.
1703+
1704+
Partitioning mode tells if the patch can be partitioned across the processes.
1705+
1706+
The following partitioning modes are supported:
1707+
- disabled, no partitioning can be performed;
1708+
- enabled, the patch can be partitioned across the processes.
1709+
1710+
\return The current partitioning mode.
1711+
*/
1712+
PatchKernel::PartitioningMode PatchKernel::getPartitioningMode() const
1713+
{
1714+
return m_partitioningMode;
1715+
}
1716+
1717+
/*!
1718+
Set the current partitioning mode.
1719+
1720+
See PatchKernel::getPartitioningMode() for a list of supported partitioning
1721+
modes.
1722+
1723+
\param mode is the partitioning mode that will be set
1724+
*/
1725+
void PatchKernel::setPartitioningMode(PartitioningMode mode)
1726+
{
1727+
m_partitioningMode = mode;
16991728
}
17001729

17011730
/*!

src/patchkernel/point_kernel.cpp

Lines changed: 15 additions & 6 deletions
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

Lines changed: 3 additions & 3 deletions
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)