forked from openPMD/openPMD-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathADIOS2IOHandler.hpp
1416 lines (1220 loc) · 44.1 KB
/
ADIOS2IOHandler.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Copyright 2017-2021 Fabian Koller and Franz Poeschel
*
* This file is part of openPMD-api.
*
* openPMD-api is free software: you can redistribute it and/or modify
* it under the terms of of either the GNU General Public License or
* the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* openPMD-api is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License and the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* and the GNU Lesser General Public License along with openPMD-api.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "openPMD/IO/AbstractIOHandler.hpp"
#include "openPMD/IO/AbstractIOHandlerImpl.hpp"
#include "openPMD/IO/AbstractIOHandlerImplCommon.hpp"
#include "openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp"
#include "openPMD/IO/ADIOS/ADIOS2FilePosition.hpp"
#include "openPMD/IO/ADIOS/ADIOS2PreloadAttributes.hpp"
#include "openPMD/IO/IOTask.hpp"
#include "openPMD/IO/InvalidatableFile.hpp"
#include "openPMD/auxiliary/JSON_internal.hpp"
#include "openPMD/auxiliary/Option.hpp"
#include "openPMD/backend/Writable.hpp"
#include "openPMD/config.hpp"
#include "openPMD/IterationEncoding.hpp"
#if openPMD_HAVE_ADIOS2
# include <adios2.h>
#endif
#if openPMD_HAVE_MPI
# include <mpi.h>
#endif
#include <nlohmann/json.hpp>
#include <array>
#include <exception>
#include <future>
#include <iostream>
#include <memory> // shared_ptr
#include <set>
#include <string>
#include <unordered_map>
#include <utility> // pair
#include <vector>
namespace openPMD
{
#if openPMD_HAVE_ADIOS2
class ADIOS2IOHandler;
namespace detail
{
template < typename, typename > struct DatasetHelper;
struct GetSpan;
struct DatasetReader;
struct AttributeReader;
struct AttributeWriter;
struct OldAttributeReader;
struct OldAttributeWriter;
template < typename > struct AttributeTypes;
struct DatasetOpener;
struct VariableDefiner;
template < typename > struct DatasetTypes;
struct WriteDataset;
struct BufferedActions;
struct BufferedPut;
struct BufferedGet;
struct BufferedAttributeRead;
struct BufferedAttributeWrite;
} // namespace detail
namespace ADIOS2Schema
{
using schema_t = uint64_t;
/*
* Original ADIOS schema.
*/
constexpr schema_t schema_0000_00_00 = 00000000;
/*
* This introduces attribute layout via scalar ADIOS variables.
*/
constexpr schema_t schema_2021_02_09 = 20210209;
enum class SupportedSchema : char
{
s_0000_00_00,
s_2021_02_09
};
}
using SupportedSchema = ADIOS2Schema::SupportedSchema;
class ADIOS2IOHandlerImpl
: public AbstractIOHandlerImplCommon< ADIOS2FilePosition >
{
template < typename, typename > friend struct detail::DatasetHelper;
friend struct detail::GetSpan;
friend struct detail::DatasetReader;
friend struct detail::AttributeReader;
friend struct detail::AttributeWriter;
friend struct detail::OldAttributeReader;
friend struct detail::OldAttributeWriter;
template < typename > friend struct detail::AttributeTypes;
friend struct detail::DatasetOpener;
friend struct detail::VariableDefiner;
template < typename > friend struct detail::DatasetTypes;
friend struct detail::WriteDataset;
friend struct detail::BufferedActions;
friend struct detail::BufferedAttributeRead;
static constexpr bool ADIOS2_DEBUG_MODE = false;
public:
#if openPMD_HAVE_MPI
ADIOS2IOHandlerImpl(
AbstractIOHandler *,
MPI_Comm,
json::TracingJSON config,
std::string engineType );
#endif // openPMD_HAVE_MPI
explicit ADIOS2IOHandlerImpl(
AbstractIOHandler *,
json::TracingJSON config,
std::string engineType );
~ADIOS2IOHandlerImpl() override;
std::future< void > flush( ) override;
void createFile( Writable *,
Parameter< Operation::CREATE_FILE > const & ) override;
void createPath( Writable *,
Parameter< Operation::CREATE_PATH > const & ) override;
void
createDataset( Writable *,
Parameter< Operation::CREATE_DATASET > const & ) override;
void
extendDataset( Writable *,
Parameter< Operation::EXTEND_DATASET > const & ) override;
void openFile( Writable *,
Parameter< Operation::OPEN_FILE > const & ) override;
void closeFile( Writable *,
Parameter< Operation::CLOSE_FILE > const & ) override;
void openPath( Writable *,
Parameter< Operation::OPEN_PATH > const & ) override;
void closePath( Writable *,
Parameter< Operation::CLOSE_PATH > const & ) override;
void openDataset( Writable *,
Parameter< Operation::OPEN_DATASET > & ) override;
void deleteFile( Writable *,
Parameter< Operation::DELETE_FILE > const & ) override;
void deletePath( Writable *,
Parameter< Operation::DELETE_PATH > const & ) override;
void
deleteDataset( Writable *,
Parameter< Operation::DELETE_DATASET > const & ) override;
void deleteAttribute( Writable *,
Parameter< Operation::DELETE_ATT > const & ) override;
void writeDataset( Writable *,
Parameter< Operation::WRITE_DATASET > const & ) override;
void writeAttribute( Writable *,
Parameter< Operation::WRITE_ATT > const & ) override;
void readDataset( Writable *,
Parameter< Operation::READ_DATASET > & ) override;
void getBufferView( Writable *,
Parameter< Operation::GET_BUFFER_VIEW > & ) override;
void readAttribute( Writable *,
Parameter< Operation::READ_ATT > & ) override;
void listPaths( Writable *, Parameter< Operation::LIST_PATHS > & ) override;
void listDatasets( Writable *,
Parameter< Operation::LIST_DATASETS > & ) override;
void
listAttributes( Writable *,
Parameter< Operation::LIST_ATTS > & parameters ) override;
void
advance( Writable*, Parameter< Operation::ADVANCE > & ) override;
void
availableChunks( Writable*,
Parameter< Operation::AVAILABLE_CHUNKS > &) override;
/**
* @brief The ADIOS2 access type to chose for Engines opened
* within this instance.
*/
adios2::Mode adios2AccessMode( std::string const & fullPath );
private:
adios2::ADIOS m_ADIOS;
/*
* If the iteration encoding is variableBased, we default to using the
* 2021_02_09 schema since it allows mutable attributes.
*/
IterationEncoding m_iterationEncoding = IterationEncoding::groupBased;
/**
* The ADIOS2 engine type, to be passed to adios2::IO::SetEngine
*/
std::string m_engineType;
ADIOS2Schema::schema_t m_schema = ADIOS2Schema::schema_0000_00_00;
enum class AttributeLayout : char
{
ByAdiosAttributes,
ByAdiosVariables
};
inline SupportedSchema schema() const
{
switch( m_schema )
{
case ADIOS2Schema::schema_0000_00_00:
return SupportedSchema::s_0000_00_00;
case ADIOS2Schema::schema_2021_02_09:
return SupportedSchema::s_2021_02_09;
default:
throw std::runtime_error(
"[ADIOS2] Encountered unsupported schema version: " +
std::to_string( m_schema ) );
}
}
inline AttributeLayout attributeLayout() const
{
switch( schema() )
{
case SupportedSchema::s_0000_00_00:
return AttributeLayout::ByAdiosAttributes;
case SupportedSchema::s_2021_02_09:
return AttributeLayout::ByAdiosVariables;
}
throw std::runtime_error( "Unreachable!" );
}
struct ParameterizedOperator
{
adios2::Operator op;
adios2::Params params;
};
std::vector< ParameterizedOperator > defaultOperators;
json::TracingJSON m_config;
static json::TracingJSON nullvalue;
void
init( json::TracingJSON config );
template< typename Key >
json::TracingJSON
config( Key && key, json::TracingJSON & cfg )
{
if( cfg.json().is_object() && cfg.json().contains( key ) )
{
return cfg[ key ];
}
else
{
return nullvalue;
}
}
template< typename Key >
json::TracingJSON
config( Key && key )
{
return config< Key >( std::forward< Key >( key ), m_config );
}
/**
*
* @param config The top-level of the ADIOS2 configuration JSON object
* with operators to be found under dataset.operators
* @return first parameter: the operators, second parameters: whether
* operators have been configured
*/
auxiliary::Option< std::vector< ParameterizedOperator > >
getOperators( json::TracingJSON config );
// use m_config
auxiliary::Option< std::vector< ParameterizedOperator > >
getOperators();
std::string
fileSuffix() const;
/*
* We need to give names to IO objects. These names are irrelevant
* within this application, since:
* 1) The name of the file written to is decided by the opened Engine's
* name.
* 2) The IOs are managed by the unordered_map m_fileData, so we do not
* need the ADIOS2 internal management.
* Since within one m_ADIOS object, the same IO name cannot be used more
* than once, we ensure different names by using the name counter.
* This allows to overwrite a file later without error.
*/
int nameCounter{0};
/*
* IO-heavy actions are deferred to a later point. This map stores for
* each open file (identified by an InvalidatableFile object) an object
* that manages IO-heavy actions, as well as its ADIOS2 objects, i.e.
* IO and Engine object.
* Not to be accessed directly, use getFileData().
*/
std::unordered_map< InvalidatableFile,
std::unique_ptr< detail::BufferedActions >
> m_fileData;
std::map< std::string, adios2::Operator > m_operators;
// Overrides from AbstractIOHandlerImplCommon.
std::string
filePositionToString( std::shared_ptr< ADIOS2FilePosition > ) override;
std::shared_ptr< ADIOS2FilePosition >
extendFilePosition( std::shared_ptr< ADIOS2FilePosition > const & pos,
std::string extend ) override;
// Helper methods.
auxiliary::Option< adios2::Operator >
getCompressionOperator( std::string const & compression );
/*
* The name of the ADIOS2 variable associated with this Writable.
* To be used for Writables that represent a dataset.
*/
std::string nameOfVariable( Writable * writable );
/**
* @brief nameOfAttribute
* @param writable The Writable at whose level the attribute lies.
* @param attribute The openPMD name of the attribute.
* @return The ADIOS2 name of the attribute, consisting of
* the variable that the attribute is associated with
* (possibly the empty string, representing no variable)
* and the actual name.
*/
std::string nameOfAttribute( Writable * writable, std::string attribute );
/*
* Figure out whether the Writable corresponds with a
* group or a dataset.
*/
ADIOS2FilePosition::GD groupOrDataset( Writable * );
enum class IfFileNotOpen : bool
{
OpenImplicitly,
ThrowError
};
detail::BufferedActions &
getFileData( InvalidatableFile file, IfFileNotOpen );
void dropFileData( InvalidatableFile file );
/*
* Prepare a variable that already exists for an IO
* operation, including:
* (1) checking that its datatype matches T.
* (2) the offset and extent match the variable's shape
* (3) setting the offset and extent (ADIOS lingo: start
* and count)
*/
template < typename T >
adios2::Variable< T > verifyDataset( Offset const & offset,
Extent const & extent, adios2::IO & IO,
std::string const & var );
}; // ADIOS2IOHandlerImpl
/*
* The following strings are used during parsing of the JSON configuration
* string for the ADIOS2 backend.
*/
namespace ADIOS2Defaults
{
using const_str = char const * const;
constexpr const_str str_engine = "engine";
constexpr const_str str_type = "type";
constexpr const_str str_params = "parameters";
constexpr const_str str_usesteps = "usesteps";
constexpr const_str str_usesstepsAttribute = "__openPMD_internal/useSteps";
constexpr const_str str_adios2Schema =
"__openPMD_internal/openPMD2_adios2_schema";
constexpr const_str str_isBooleanOldLayout = "__is_boolean__";
constexpr const_str str_isBooleanNewLayout =
"__openPMD_internal/is_boolean";
} // namespace ADIOS2Defaults
namespace detail
{
// Helper structs for calls to the switchType function
struct DatasetReader
{
template< typename T >
static void call(
ADIOS2IOHandlerImpl * impl,
BufferedGet & bp,
adios2::IO & IO,
adios2::Engine & engine,
std::string const & fileName );
static constexpr char const * errorMsg = "ADIOS2: readDataset()";
};
struct OldAttributeReader
{
template< typename T >
static Datatype call(
adios2::IO & IO,
std::string name,
std::shared_ptr< Attribute::resource > resource );
template< int n, typename... Params >
static Datatype call( Params &&... );
};
struct OldAttributeWriter
{
template< typename T >
static void call(
ADIOS2IOHandlerImpl * impl,
Writable * writable,
const Parameter< Operation::WRITE_ATT > & parameters );
template< int n, typename... Params >
static void call( Params &&... );
};
struct AttributeReader
{
template< typename T >
static Datatype call(
adios2::IO & IO,
detail::PreloadAdiosAttributes const & preloadedAttributes,
std::string name,
std::shared_ptr< Attribute::resource > resource );
template< int n, typename... Params >
static Datatype call( Params &&... );
};
struct AttributeWriter
{
template< typename T >
static void call(
detail::BufferedAttributeWrite & params,
BufferedActions & fileData );
template< int n, typename... Params >
static void call( Params &&... );
};
struct DatasetOpener
{
template< typename T >
static void call(
ADIOS2IOHandlerImpl * impl,
InvalidatableFile,
const std::string & varName,
Parameter< Operation::OPEN_DATASET > & parameters );
static constexpr char const * errorMsg = "ADIOS2: openDataset()";
};
struct WriteDataset
{
template< typename T >
static void call(
ADIOS2IOHandlerImpl * impl,
BufferedPut & bp,
adios2::IO & IO,
adios2::Engine & engine );
template< int n, typename... Params >
static void call( Params &&... );
};
struct VariableDefiner
{
/**
* @brief Define a Variable of type T within the passed IO.
*
* @param IO The adios2::IO object within which to define the
* variable. The variable can later be retrieved from
* the IO using the passed name.
* @param name As in adios2::IO::DefineVariable
* @param compressions ADIOS2 operators, including an arbitrary
* number of parameters, to be added to the
* variable upon definition.
* @param shape As in adios2::IO::DefineVariable
* @param start As in adios2::IO::DefineVariable
* @param count As in adios2::IO::DefineVariable
* @param constantDims As in adios2::IO::DefineVariable
*/
template< typename T >
static void call(
adios2::IO & IO,
std::string const & name,
std::vector< ADIOS2IOHandlerImpl::ParameterizedOperator > const &
compressions,
adios2::Dims const & shape = adios2::Dims(),
adios2::Dims const & start = adios2::Dims(),
adios2::Dims const & count = adios2::Dims(),
bool const constantDims = false );
static constexpr char const * errorMsg = "ADIOS2: defineVariable()";
};
struct RetrieveBlocksInfo
{
template< typename T >
static void call(
Parameter< Operation::AVAILABLE_CHUNKS > & params,
adios2::IO & IO,
adios2::Engine & engine,
std::string const & varName );
template < int n, typename... Params >
static void call( Params &&... );
};
// Helper structs to help distinguish valid attribute/variable
// datatypes from invalid ones
/*
* This struct's purpose is to have specialisations
* for vector and array types, as well as the boolean
* type (which is not natively supported by ADIOS).
*/
template< typename T >
struct AttributeTypes
{
static void
oldCreateAttribute(
adios2::IO & IO,
std::string name,
T value );
static void
oldReadAttribute(
adios2::IO & IO,
std::string name,
std::shared_ptr< Attribute::resource > resource );
static void
createAttribute(
adios2::IO & IO,
adios2::Engine & engine,
detail::BufferedAttributeWrite & params,
T value );
static void
readAttribute(
detail::PreloadAdiosAttributes const &,
std::string name,
std::shared_ptr< Attribute::resource > resource );
/**
* @brief Is the attribute given by parameters name and val already
* defined exactly in that way within the given IO?
*/
static bool
attributeUnchanged( adios2::IO & IO, std::string name, T val )
{
auto attr = IO.InquireAttribute< T >( name );
if( !attr )
{
return false;
}
std::vector< T > data = attr.Data();
if( data.size() != 1 )
{
return false;
}
return data[ 0 ] == val;
}
};
template< > struct AttributeTypes< std::complex< long double > >
{
static void
oldCreateAttribute(
adios2::IO &,
std::string,
std::complex< long double > )
{
throw std::runtime_error(
"[ADIOS2] Internal error: no support for long double complex attribute types" );
}
static void
oldReadAttribute(
adios2::IO &,
std::string,
std::shared_ptr< Attribute::resource > )
{
throw std::runtime_error(
"[ADIOS2] Internal error: no support for long double complex attribute types" );
}
static void
createAttribute(
adios2::IO &,
adios2::Engine &,
detail::BufferedAttributeWrite &,
std::complex< long double > )
{
throw std::runtime_error(
"[ADIOS2] Internal error: no support for long double complex attribute types" );
}
static void
readAttribute(
detail::PreloadAdiosAttributes const &,
std::string,
std::shared_ptr< Attribute::resource > )
{
throw std::runtime_error(
"[ADIOS2] Internal error: no support for long double complex attribute types" );
}
static bool
attributeUnchanged(
adios2::IO &, std::string, std::complex< long double > )
{
throw std::runtime_error(
"[ADIOS2] Internal error: no support for long double complex attribute types" );
}
};
template< > struct AttributeTypes< std::vector< std::complex< long double > > >
{
static void
oldCreateAttribute(
adios2::IO &,
std::string,
const std::vector< std::complex< long double > > & )
{
throw std::runtime_error(
"[ADIOS2] Internal error: no support for long double complex vector attribute types" );
}
static void
oldReadAttribute(
adios2::IO &,
std::string,
std::shared_ptr< Attribute::resource > )
{
throw std::runtime_error(
"[ADIOS2] Internal error: no support for long double complex vector attribute types" );
}
static void
createAttribute(
adios2::IO &,
adios2::Engine &,
detail::BufferedAttributeWrite &,
const std::vector< std::complex< long double > > & )
{
throw std::runtime_error(
"[ADIOS2] Internal error: no support for long double complex vector attribute types" );
}
static void
readAttribute(
detail::PreloadAdiosAttributes const &,
std::string,
std::shared_ptr< Attribute::resource > )
{
throw std::runtime_error(
"[ADIOS2] Internal error: no support for long double complex vector attribute types" );
}
static bool
attributeUnchanged(
adios2::IO &,
std::string,
std::vector< std::complex< long double > > )
{
throw std::runtime_error(
"[ADIOS2] Internal error: no support for long double complex vector attribute types" );
}
};
template < typename T > struct AttributeTypes< std::vector< T > >
{
static void
oldCreateAttribute(
adios2::IO & IO,
std::string name,
const std::vector< T > & value );
static void
oldReadAttribute(
adios2::IO & IO,
std::string name,
std::shared_ptr< Attribute::resource > resource );
static void
createAttribute(
adios2::IO & IO,
adios2::Engine & engine,
detail::BufferedAttributeWrite & params,
const std::vector< T > & value );
static void
readAttribute(
detail::PreloadAdiosAttributes const &,
std::string name,
std::shared_ptr< Attribute::resource > resource );
static bool
attributeUnchanged(
adios2::IO & IO,
std::string name,
std::vector< T > val )
{
auto attr = IO.InquireAttribute< T >( name );
if( !attr )
{
return false;
}
std::vector< T > data = attr.Data();
if( data.size() != val.size() )
{
return false;
}
for( size_t i = 0; i < val.size(); ++i )
{
if( data[ i ] != val[ i ] )
{
return false;
}
}
return true;
}
};
template<>
struct AttributeTypes< std::vector< std::string > >
{
static void
oldCreateAttribute(
adios2::IO & IO,
std::string name,
const std::vector< std::string > & value );
static void
oldReadAttribute(
adios2::IO & IO,
std::string name,
std::shared_ptr< Attribute::resource > resource );
static void
createAttribute(
adios2::IO & IO,
adios2::Engine & engine,
detail::BufferedAttributeWrite & params,
const std::vector< std::string > & vec );
static void
readAttribute(
detail::PreloadAdiosAttributes const &,
std::string name,
std::shared_ptr< Attribute::resource > resource );
static bool
attributeUnchanged(
adios2::IO & IO,
std::string name,
std::vector< std::string > val )
{
auto attr = IO.InquireAttribute< std::string >( name );
if( !attr )
{
return false;
}
std::vector< std::string > data = attr.Data();
if( data.size() != val.size() )
{
return false;
}
for( size_t i = 0; i < val.size(); ++i )
{
if( data[ i ] != val[ i ] )
{
return false;
}
}
return true;
}
};
template < typename T, size_t n >
struct AttributeTypes< std::array< T, n > >
{
static void
oldCreateAttribute(
adios2::IO & IO,
std::string name,
const std::array< T, n > & value );
static void
oldReadAttribute(
adios2::IO & IO,
std::string name,
std::shared_ptr< Attribute::resource > resource );
static void
createAttribute(
adios2::IO & IO,
adios2::Engine & engine,
detail::BufferedAttributeWrite & params,
const std::array< T, n > & value );
static void
readAttribute(
detail::PreloadAdiosAttributes const &,
std::string name,
std::shared_ptr< Attribute::resource > resource );
static bool
attributeUnchanged(
adios2::IO & IO,
std::string name,
std::array< T, n > val )
{
auto attr = IO.InquireAttribute< T >( name );
if( !attr )
{
return false;
}
std::vector< T > data = attr.Data();
if( data.size() != n )
{
return false;
}
for( size_t i = 0; i < n; ++i )
{
if( data[ i ] != val[ i ] )
{
return false;
}
}
return true;
}
};
template <> struct AttributeTypes< bool >
{
using rep = detail::bool_representation;
static void
oldCreateAttribute( adios2::IO & IO, std::string name, bool value );
static void
oldReadAttribute(
adios2::IO & IO,
std::string name,
std::shared_ptr< Attribute::resource > resource );
static void
createAttribute(
adios2::IO & IO,
adios2::Engine & engine,
detail::BufferedAttributeWrite & params,
bool value );
static void
readAttribute(
detail::PreloadAdiosAttributes const &,
std::string name,
std::shared_ptr< Attribute::resource > resource );
static constexpr rep toRep( bool b )
{
return b ? 1U : 0U;
}
static constexpr bool fromRep( rep r )
{
return r != 0;
}
static bool
attributeUnchanged( adios2::IO & IO, std::string name, bool val )
{
auto attr = IO.InquireAttribute< rep >( name );
if( !attr )
{
return false;
}
std::vector< rep > data = attr.Data();
if( data.size() != 1 )
{
return false;
}
return data[ 0 ] == toRep( val );
}
};
// Other datatypes used in the ADIOS2IOHandler implementation
struct BufferedActions;
/*
* IO-heavy action to be executed upon flushing.
*/
struct BufferedAction
{
explicit BufferedAction( ) = default;
virtual ~BufferedAction( ) = default;
BufferedAction( BufferedAction const & other ) = delete;
BufferedAction( BufferedAction && other ) = default;
BufferedAction & operator=( BufferedAction const & other ) = delete;
BufferedAction & operator=( BufferedAction && other ) = default;
virtual void run( BufferedActions & ) = 0;
};
struct BufferedGet : BufferedAction
{
std::string name;
Parameter< Operation::READ_DATASET > param;
void run( BufferedActions & ) override;
};
struct BufferedPut : BufferedAction
{
std::string name;
Parameter< Operation::WRITE_DATASET > param;
void run( BufferedActions & ) override;
};
struct OldBufferedAttributeRead : BufferedAction
{
Parameter< Operation::READ_ATT > param;
std::string name;
void run( BufferedActions & ) override;
};
struct BufferedAttributeRead
{
Parameter< Operation::READ_ATT > param;
std::string name;
void
run( BufferedActions & );
};