|
20 | 20 | */ |
21 | 21 | #include "openPMD/auxiliary/Date.hpp" |
22 | 22 | #include "openPMD/auxiliary/Filesystem.hpp" |
| 23 | +#include "openPMD/auxiliary/MPI.hpp" |
23 | 24 | #include "openPMD/auxiliary/StringManip.hpp" |
24 | 25 | #include "openPMD/IO/AbstractIOHandler.hpp" |
25 | 26 | #include "openPMD/IO/AbstractIOHandlerHelper.hpp" |
@@ -92,6 +93,7 @@ Series::Series( |
92 | 93 | std::string const & options ) |
93 | 94 | : iterations{ Container< Iteration, uint64_t >() } |
94 | 95 | , m_iterationEncoding{ std::make_shared< IterationEncoding >() } |
| 96 | + , m_communicator{ comm } |
95 | 97 | { |
96 | 98 | auto input = parseInput( filepath ); |
97 | 99 | auto handler = |
@@ -193,6 +195,90 @@ Series::setMeshesPath(std::string const& mp) |
193 | 195 | return *this; |
194 | 196 | } |
195 | 197 |
|
| 198 | +chunk_assignment::RankMeta |
| 199 | +Series::mpiRanksMetaInfo() const |
| 200 | +{ |
| 201 | + std::vector< std::string > asContiguousVector; |
| 202 | + try |
| 203 | + { |
| 204 | + asContiguousVector = |
| 205 | + getAttribute( "rankMetaInfo" ).get< std::vector< std::string > >(); |
| 206 | + } |
| 207 | + catch( std::runtime_error const & ) |
| 208 | + { |
| 209 | + // workaround: if vector has length 1, some backends may report a |
| 210 | + // single value instead of a vector |
| 211 | + asContiguousVector = { |
| 212 | + getAttribute( "rankMetaInfo" ).get< std::string >() |
| 213 | + }; |
| 214 | + } |
| 215 | + chunk_assignment::RankMeta res; |
| 216 | + for( size_t i = 0; i < asContiguousVector.size(); ++i ) |
| 217 | + { |
| 218 | + res[ i ] = std::move( asContiguousVector[ i ] ); |
| 219 | + } |
| 220 | + return res; |
| 221 | +} |
| 222 | + |
| 223 | +Series & |
| 224 | +Series::setMpiRanksMetaInfo( chunk_assignment::RankMeta rankMeta ) |
| 225 | +{ |
| 226 | + std::vector< std::string > asContiguousVector; |
| 227 | + asContiguousVector.reserve( rankMeta.size() ); |
| 228 | + try |
| 229 | + { |
| 230 | + for( size_t i = 0; i < rankMeta.size(); ++i ) |
| 231 | + { |
| 232 | + asContiguousVector.emplace_back( std::move( rankMeta.at( i ) ) ); |
| 233 | + } |
| 234 | + } |
| 235 | + catch( std::out_of_range ) |
| 236 | + { |
| 237 | + throw std::runtime_error( "[setMpiRanksMetaInfo] Can only set meta " |
| 238 | + "info for contiguous ranks 0 to n." ); |
| 239 | + } |
| 240 | + |
| 241 | + setAttribute( "rankMetaInfo", std::move( asContiguousVector ) ); |
| 242 | + return *this; |
| 243 | +} |
| 244 | + |
| 245 | +Series & |
| 246 | +Series::setMpiRanksMetaInfo( std::string const & myRankInfo ) |
| 247 | +{ |
| 248 | + if( auxiliary::starts_with( myRankInfo, '@' ) ) |
| 249 | + { |
| 250 | + // read from file |
| 251 | + std::string fileName = auxiliary::replace_first( myRankInfo, "@", "" ); |
| 252 | + std::vector< std::string > rankMeta; |
| 253 | + try |
| 254 | + { |
| 255 | + rankMeta = auxiliary::read_file_by_lines( fileName ); |
| 256 | + } |
| 257 | + catch( auxiliary::no_such_file_error const & ) |
| 258 | + { |
| 259 | + std::cerr << "Not setting rank meta information, because file has " |
| 260 | + "not been found: " |
| 261 | + << fileName << std::endl; |
| 262 | + return *this; |
| 263 | + } |
| 264 | + setAttribute( "rankMetaInfo", rankMeta ); |
| 265 | + return *this; |
| 266 | + } |
| 267 | +#if openPMD_HAVE_MPI |
| 268 | + int rank; |
| 269 | + MPI_Comm_rank( m_communicator, &rank ); |
| 270 | + std::vector< std::string > rankMeta = |
| 271 | + auxiliary::collectStringsTo( m_communicator, 0, myRankInfo ); |
| 272 | + if( rank == 0 ) |
| 273 | + { |
| 274 | + setAttribute( "rankMetaInfo", std::move( rankMeta ) ); |
| 275 | + } |
| 276 | + return *this; |
| 277 | +#else |
| 278 | + setAttribute( "rankMetaInfo", std::vector< std::string >{ myRankInfo } ); |
| 279 | +#endif |
| 280 | +} |
| 281 | + |
196 | 282 | std::string |
197 | 283 | Series::particlesPath() const |
198 | 284 | { |
|
0 commit comments