Skip to content

Commit f470454

Browse files
committed
Some cleanup
1 parent 725bbee commit f470454

5 files changed

Lines changed: 83 additions & 89 deletions

File tree

include/openPMD/ChunkInfo.hpp

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct WrittenChunkInfo : ChunkInfo
8080
operator==( WrittenChunkInfo const & other ) const;
8181
};
8282

83+
// !< @todo Also add a ChunkTable for ReadChunkInfo or sth like that
8384
using ChunkTable = std::vector< WrittenChunkInfo >;
8485

8586
namespace chunk_assignment
@@ -108,6 +109,10 @@ namespace chunk_assignment
108109
*/
109110
struct Strategy
110111
{
112+
ChunkTable assign(
113+
ChunkTable,
114+
RankMeta const & rankMetaIn,
115+
RankMeta const & rankMetaOut );
111116
/**
112117
* @brief Assign chunks to be loaded to reading processes.
113118
*
@@ -141,6 +146,8 @@ namespace chunk_assignment
141146
*/
142147
struct PartialStrategy
143148
{
149+
PartialAssignment
150+
assign( ChunkTable table, RankMeta const & in, RankMeta const & out );
144151
/**
145152
* @brief Assign chunks to be loaded to reading processes.
146153
*
@@ -164,19 +171,6 @@ namespace chunk_assignment
164171
virtual ~PartialStrategy() = default;
165172
};
166173

167-
ChunkTable
168-
assignChunks(
169-
ChunkTable,
170-
RankMeta const & rankMetaIn,
171-
RankMeta const & rankMetaOut,
172-
Strategy & strategy );
173-
174-
PartialAssignment assignChunks(
175-
ChunkTable,
176-
RankMeta const & rankMetaIn,
177-
RankMeta const & rankMetaOut,
178-
PartialStrategy & strategy );
179-
180174
/**
181175
* @brief Combine a PartialStrategy and a Strategy to obtain a Strategy
182176
* working in two phases.
@@ -195,14 +189,12 @@ namespace chunk_assignment
195189
std::unique_ptr< PartialStrategy > firstPass,
196190
std::unique_ptr< Strategy > secondPass );
197191

198-
virtual ChunkTable
199-
assign( PartialAssignment, RankMeta const & in, RankMeta const & out );
192+
virtual ChunkTable assign(
193+
PartialAssignment,
194+
RankMeta const & in,
195+
RankMeta const & out ) override;
200196

201-
virtual std::unique_ptr< Strategy > clone() const override
202-
{
203-
return std::unique_ptr< Strategy >( new FromPartialStrategy(
204-
m_firstPass->clone(), m_secondPass->clone() ) );
205-
}
197+
virtual std::unique_ptr< Strategy > clone() const override;
206198

207199
private:
208200
std::unique_ptr< PartialStrategy > m_firstPass;
@@ -216,13 +208,12 @@ namespace chunk_assignment
216208
*/
217209
struct RoundRobin : Strategy
218210
{
219-
ChunkTable
220-
assign( PartialAssignment, RankMeta const & in, RankMeta const & out );
211+
ChunkTable assign(
212+
PartialAssignment,
213+
RankMeta const & in,
214+
RankMeta const & out ) override;
221215

222-
virtual std::unique_ptr< Strategy > clone() const override
223-
{
224-
return std::unique_ptr< Strategy >( new RoundRobin );
225-
}
216+
virtual std::unique_ptr< Strategy > clone() const override;
226217
};
227218

228219
/**
@@ -237,15 +228,12 @@ namespace chunk_assignment
237228
{
238229
ByHostname( std::unique_ptr< Strategy > withinNode );
239230

240-
PartialAssignment
241-
assign( PartialAssignment, RankMeta const & in, RankMeta const & out )
242-
override;
231+
PartialAssignment assign(
232+
PartialAssignment,
233+
RankMeta const & in,
234+
RankMeta const & out ) override;
243235

244-
virtual std::unique_ptr< PartialStrategy > clone() const override
245-
{
246-
return std::unique_ptr< PartialStrategy >(
247-
new ByHostname( m_withinNode->clone() ) );
248-
}
236+
virtual std::unique_ptr< PartialStrategy > clone() const override;
249237

250238
private:
251239
std::unique_ptr< Strategy > m_withinNode;
@@ -274,11 +262,7 @@ namespace chunk_assignment
274262
RankMeta const & in,
275263
RankMeta const & out ) override;
276264

277-
virtual std::unique_ptr< Strategy > clone() const override
278-
{
279-
return std::unique_ptr< Strategy >( new ByCuboidSlice(
280-
blockSlicer->clone(), totalExtent, mpi_rank, mpi_size ) );
281-
}
265+
virtual std::unique_ptr< Strategy > clone() const override;
282266

283267
private:
284268
std::unique_ptr< BlockSlicer > blockSlicer;
@@ -313,13 +297,9 @@ namespace chunk_assignment
313297
RankMeta const & in,
314298
RankMeta const & out ) override;
315299

316-
virtual std::unique_ptr< Strategy > clone() const override
317-
{
318-
return std::unique_ptr< Strategy >(
319-
new BinPacking( splitAlongDimension ) );
320-
}
300+
virtual std::unique_ptr< Strategy > clone() const override;
321301
};
322-
} // namespace chunk_assignment
302+
} // namespace chunk_assignment
323303

324304
namespace host_info
325305
{

src/ChunkInfo.cpp

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,20 @@ namespace chunk_assignment
8080
}
8181
} // namespace
8282

83+
ChunkTable Strategy::assign(
84+
ChunkTable table, RankMeta const & rankIn, RankMeta const & rankOut )
85+
{
86+
if( rankOut.size() == 0 )
87+
{
88+
throw std::runtime_error(
89+
"[assignChunks] No output ranks defined" );
90+
}
91+
return this->assign(
92+
PartialAssignment( std::move( table ) ), rankIn, rankOut );
93+
}
94+
8395
PartialAssignment::PartialAssignment(
84-
ChunkTable notAssigned_in,
85-
ChunkTable assigned_in )
96+
ChunkTable notAssigned_in, ChunkTable assigned_in )
8697
: notAssigned( std::move( notAssigned_in ) )
8798
, assigned( std::move( assigned_in ) )
8899
{
@@ -93,29 +104,10 @@ namespace chunk_assignment
93104
{
94105
}
95106

96-
ChunkTable
97-
assignChunks(
98-
ChunkTable table,
99-
RankMeta const & rankIn,
100-
RankMeta const & rankOut,
101-
Strategy & strategy )
107+
PartialAssignment PartialStrategy::assign(
108+
ChunkTable table, RankMeta const & rankIn, RankMeta const & rankOut )
102109
{
103-
if( rankOut.size() == 0 )
104-
{
105-
throw std::runtime_error(
106-
"[assignChunks] No output ranks defined" );
107-
}
108-
return strategy.assign(
109-
PartialAssignment( std::move( table ) ), rankIn, rankOut );
110-
}
111-
112-
PartialAssignment assignChunks(
113-
ChunkTable table,
114-
RankMeta const & rankIn,
115-
RankMeta const & rankOut,
116-
PartialStrategy & strategy )
117-
{
118-
return strategy.assign(
110+
return this->assign(
119111
PartialAssignment( std::move( table ) ), rankIn, rankOut );
120112
}
121113

@@ -139,8 +131,13 @@ namespace chunk_assignment
139131
out );
140132
}
141133

142-
ChunkTable
143-
RoundRobin::assign(
134+
std::unique_ptr< Strategy > FromPartialStrategy::clone() const
135+
{
136+
return std::unique_ptr< Strategy >( new FromPartialStrategy(
137+
m_firstPass->clone(), m_secondPass->clone() ) );
138+
}
139+
140+
ChunkTable RoundRobin::assign(
144141
PartialAssignment partialAssignment,
145142
RankMeta const &, // ignored parameter
146143
RankMeta const & out )
@@ -170,6 +167,11 @@ namespace chunk_assignment
170167
return sinkChunks;
171168
}
172169

170+
std::unique_ptr< Strategy > RoundRobin::clone() const
171+
{
172+
return std::unique_ptr< Strategy >( new RoundRobin );
173+
}
174+
173175
ByHostname::ByHostname( std::unique_ptr< Strategy > withinNode )
174176
: m_withinNode( std::move( withinNode ) )
175177
{
@@ -231,6 +233,12 @@ namespace chunk_assignment
231233
return res;
232234
}
233235

236+
std::unique_ptr< PartialStrategy > ByHostname::clone() const
237+
{
238+
return std::unique_ptr< PartialStrategy >(
239+
new ByHostname( m_withinNode->clone() ) );
240+
}
241+
234242
ByCuboidSlice::ByCuboidSlice(
235243
std::unique_ptr< BlockSlicer > blockSlicer_in,
236244
Extent totalExtent_in,
@@ -416,6 +424,12 @@ namespace chunk_assignment
416424
return res.assigned;
417425
}
418426

427+
std::unique_ptr< Strategy > ByCuboidSlice::clone() const
428+
{
429+
return std::unique_ptr< Strategy >( new ByCuboidSlice(
430+
blockSlicer->clone(), totalExtent, mpi_rank, mpi_size ) );
431+
}
432+
419433
BinPacking::BinPacking( size_t splitAlongDimension_in )
420434
: splitAlongDimension( splitAlongDimension_in )
421435
{
@@ -518,6 +532,12 @@ namespace chunk_assignment
518532

519533
return sinkChunks;
520534
}
535+
536+
std::unique_ptr< Strategy > BinPacking::clone() const
537+
{
538+
return std::unique_ptr< Strategy >(
539+
new BinPacking( splitAlongDimension ) );
540+
}
521541
} // namespace chunk_assignment
522542

523543
namespace host_info

src/binding/python/ChunkInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ void init_Chunk(py::module &m) {
7171
ChunkTable table,
7272
RankMeta const & rankMetaIn,
7373
RankMeta const & rankMetaOut ) {
74-
return assignChunks(
75-
std::move( table ), rankMetaIn, rankMetaOut, self );
74+
return self.assign(
75+
std::move( table ), rankMetaIn, rankMetaOut );
7676
},
7777
py::arg( "chunk_table" ),
7878
py::arg( "rank_meta_in" ) = RankMeta(),

test/CoreTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ TEST_CASE( "chunk_assignment", "[core]" )
8181
FromPartialStrategy fullStrategy(
8282
std::make_unique< ByHostname >( std::move( byHostname ) ),
8383
std::make_unique< BinPacking >() );
84-
ChunkTable res = assignChunks(
85-
params.table, params.metaSource, params.metaSink, fullStrategy );
84+
ChunkTable res =
85+
fullStrategy.assign( params.table, params.metaSource, params.metaSink );
8686
std::cout << "\nRESULTS:" << std::endl;
8787
test_chunk_assignment::print( params.metaSink, res );
8888
}

test/ParallelIOTest.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,8 +1313,8 @@ void adios2_chunk_distribution()
13131313
* ranks. Easy, but not particularly efficient.
13141314
*/
13151315
RoundRobin roundRobinStrategy;
1316-
auto roundRobinAssignment = assignChunks(
1317-
chunkTable, rankMetaIn, readingRanksHostnames, roundRobinStrategy );
1316+
auto roundRobinAssignment = roundRobinStrategy.assign(
1317+
chunkTable, rankMetaIn, readingRanksHostnames );
13181318
printAssignment(
13191319
"ROUND ROBIN", roundRobinAssignment, readingRanksHostnames );
13201320

@@ -1330,8 +1330,8 @@ void adios2_chunk_distribution()
13301330
*/
13311331
ByHostname byHostname(
13321332
std::make_unique< BinPacking >( /* splitAlongDimension = */ 1 ) );
1333-
auto byHostnamePartialAssignment = assignChunks(
1334-
chunkTable, rankMetaIn, readingRanksHostnames, byHostname );
1333+
auto byHostnamePartialAssignment =
1334+
byHostname.assign( chunkTable, rankMetaIn, readingRanksHostnames );
13351335
printAssignment(
13361336
"HOSTNAME, ASSIGNED",
13371337
byHostnamePartialAssignment.assigned,
@@ -1353,11 +1353,8 @@ void adios2_chunk_distribution()
13531353
FromPartialStrategy fromPartialStrategy(
13541354
std::make_unique< ByHostname >( std::move( byHostname ) ),
13551355
std::make_unique< BinPacking >( /* splitAlongDimension = */ 1 ) );
1356-
auto fromPartialAssignment = assignChunks(
1357-
chunkTable,
1358-
rankMetaIn,
1359-
readingRanksHostnames,
1360-
fromPartialStrategy );
1356+
auto fromPartialAssignment = fromPartialStrategy.assign(
1357+
chunkTable, rankMetaIn, readingRanksHostnames );
13611358
printAssignment(
13621359
"HOSTNAME WITH SECOND PASS",
13631360
fromPartialAssignment,
@@ -1380,11 +1377,8 @@ void adios2_chunk_distribution()
13801377
E_x.getExtent(),
13811378
mpi_rank,
13821379
mpi_size );
1383-
auto cuboidSliceAssignment = assignChunks(
1384-
chunkTable,
1385-
rankMetaIn,
1386-
readingRanksHostnames,
1387-
cuboidSliceStrategy );
1380+
auto cuboidSliceAssignment = cuboidSliceStrategy.assign(
1381+
chunkTable, rankMetaIn, readingRanksHostnames );
13881382
printAssignment(
13891383
"CUBOID SLICE", cuboidSliceAssignment, readingRanksHostnames );
13901384
}

0 commit comments

Comments
 (0)