@@ -165,25 +165,61 @@ SeriesInterface::setMeshesPath(std::string const& mp)
165165 return *this ;
166166}
167167
168- chunk_assignment::RankMeta
169- SeriesInterface::mpiRanksMetaInfo () const
168+ chunk_assignment::RankMeta SeriesInterface::mpiRanksMetaInfo ()
170169{
171- auto attribute = getAttribute ( " rankMetaInfo" );
172- std::vector< std::string > asContiguousVector;
173- try
170+ auto & series = get ();
171+ Parameter< Operation::OPEN_DATASET > openDataset;
172+ openDataset.name = " hostTable" ;
173+ IOHandler ()->enqueue ( IOTask ( &series.m_rankTable , openDataset ) );
174+
175+ IOHandler ()->flush ();
176+ if ( openDataset.extent ->size () != 2 )
177+ {
178+ // @todo use better error type
179+ throw std::runtime_error ( " [Series] rankTable must be 2D." );
180+ }
181+ if ( *openDataset.dtype != Datatype::CHAR &&
182+ *openDataset.dtype != Datatype::UCHAR )
174183 {
175- asContiguousVector = attribute.get < std::vector< std::string > >();
184+ // @todo use better error type
185+ throw std::runtime_error ( " [Series] rankTable must have char type." );
176186 }
177- catch ( std::runtime_error const & )
187+
188+ auto writerRanks = ( *openDataset.extent )[ 0 ];
189+ auto lineWidth = ( *openDataset.extent )[ 1 ];
190+
191+ if ( lineWidth < 1 )
178192 {
179- // workaround: if vector has length 1, some backends may report a
180- // single value instead of a vector
181- asContiguousVector = { attribute.get < std::string >() };
193+ // Check this because our indexing logic later relies on this
194+ // @todo use better error type
195+ throw std::runtime_error (
196+ " [Series] rankTable lines must not be empty." );
182197 }
198+
199+ Parameter< Operation::READ_DATASET > readDataset;
200+ // read the whole thing
201+ readDataset.offset .resize ( 2 );
202+ readDataset.extent = *openDataset.extent ;
203+ readDataset.dtype = Datatype::CHAR;
204+ std::shared_ptr< char > get{
205+ new char [ writerRanks * lineWidth ],
206+ []( char const * ptr ) { delete[] ptr; } };
207+ readDataset.data = get;
208+
209+ IOHandler ()->enqueue ( IOTask ( &series.m_rankTable , readDataset ) );
210+ IOHandler ()->flush ();
211+
183212 chunk_assignment::RankMeta res;
184- for ( size_t i = 0 ; i < asContiguousVector. size () ; ++i )
213+ for ( size_t i = 0 ; i < writerRanks ; ++i )
185214 {
186- res[ i ] = std::move ( asContiguousVector[ i ] );
215+ if ( get.get ()[ ( i + 1 ) * lineWidth - 1 ] != 0 )
216+ {
217+ throw std::runtime_error (
218+ " [Series] rankTable lines must be null-terminated strings." );
219+ }
220+ // Use C-String constructor for std::string in the following line
221+ // std::string::string(char const*);
222+ res[ i ] = get.get () + i * lineWidth;
187223 }
188224 return res;
189225}
0 commit comments