Arcane  v3.16.0.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
Hdf5Utils.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* Hdf5Utils.h (C) 2000-2024 */
9/* */
10/* Fonctions utilitaires pour hdf5. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_HDF5_HDF5UTILS_H
13#define ARCANE_HDF5_HDF5UTILS_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18#include "arcane/utils/String.h"
19#include "arcane/utils/Array.h"
20#include "arcane/utils/NumericTypes.h"
21
22#include "arcane/datatype/DataTypes.h"
23
24#include "arcane/hdf5/ArcaneHdf5Global.h"
25
26// Cette macro pour MSVC avec les dll, pour eviter des symbols externes
27// indéfinis avec H5T_NATIVE*
28#define _HDF5USEDLL_
29#include <hdf5.h>
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34// Il faut au moins hdf5 1.8
35#if (H5_VERS_MAJOR<2) && (H5_VERS_MAJOR==1 && H5_VERS_MINOR<10)
36#error "This version of HDF5 is too old. Version 1.10+ is required"
37#endif
38
39// Garde ces macros pour compatibilité mais il faudra les supprimer.
40#define ARCANE_HDF5_1_6_AND_AFTER
41#define ARCANE_HDF5_1_8_AND_AFTER
42
43/*---------------------------------------------------------------------------*/
44/*---------------------------------------------------------------------------*/
45
46namespace Arcane
47{
48
49/*---------------------------------------------------------------------------*/
50/*---------------------------------------------------------------------------*/
51
52class IParallelMng;
53
54/*---------------------------------------------------------------------------*/
55/*---------------------------------------------------------------------------*/
56/*!
57 * \brief Fonctions utilitaires pour Hdf5.
58 */
59namespace Hdf5Utils
60{
61extern "C"
62{
63 ARCANE_HDF5_EXPORT herr_t _ArcaneHdf5UtilsGroupIterateMe(hid_t,const char*,void*);
64}
65
66/*---------------------------------------------------------------------------*/
67/*---------------------------------------------------------------------------*/
68/*!
69 * \brief Classe servant d'initialiseur pour HDF.
70 *
71 * Cet objet permet d'initialiser de manière sure HDF5 en mode multi-thread.
72 */
73class ARCANE_HDF5_EXPORT HInit
74{
75 public:
76
77 HInit();
78
79 public:
80
81 //! Vrai HDF5 est compilé avec le support de MPI
82 static bool hasParallelHdf5();
83};
84
85/*---------------------------------------------------------------------------*/
86/*---------------------------------------------------------------------------*/
87/*!
88 * \brief Encapsule un hid_t.
89 *
90 * Cette classe n'est pas copiable.
91 */
92class ARCANE_HDF5_EXPORT Hid
93{
94 public:
95
96 Hid() = default;
97 Hid(hid_t id)
98 : m_id(id)
99 {}
100 virtual ~Hid() {}
101
102 protected:
103
104 // Il faudra interdire ce constructeur de recopie à terme
105 Hid(const Hid& hid)
106 : m_id(hid.id())
107 {}
108 void _setId(hid_t id) { m_id = id; }
109 void _setNullId() { m_id = -1; }
110
111 private:
112
113 Hid& operator=(const Hid& hid) = delete;
114
115 public:
116
117 hid_t id() const { return m_id; }
118 bool isBad() const { return m_id < 0; }
119
120 private:
121
122 hid_t m_id = -1;
123};
124
125/*---------------------------------------------------------------------------*/
126/*---------------------------------------------------------------------------*/
127/*!
128 * \brief Encapsule un hid_t pour une propriété (H5P*).
129 */
130class ARCANE_HDF5_EXPORT HProperty
131: public Hid
132{
133 public:
134
135 HProperty() { _setId(H5P_DEFAULT); }
136 ~HProperty()
137 {
138 close();
139 }
140 HProperty(HProperty&& rhs)
141 : Hid(rhs.id())
142 {
143 rhs._setNullId();
144 }
145 HProperty& operator=(HProperty&& rhs)
146 {
147 _setId(rhs.id());
148 rhs._setNullId();
149 return (*this);
150 }
151
152 public:
153
154 HProperty(const HProperty& v) = delete;
155 HProperty& operator=(const HProperty& hid) = delete;
156
157 public:
158
159 void close()
160 {
161 if (id() > 0) {
162 H5Pclose(id());
163 _setNullId();
164 }
165 }
166
167 void create(hid_t cls_id);
168 void setId(hid_t new_id)
169 {
170 _setId(new_id);
171 }
172
173 /*!
174 * \brief Créé une propriété de fichier pour MPIIO.
175 *
176 * Ne fonctionne que si HDF5 est compilé avec MPI. Sinon lance
177 * une exception. Si \a mpi_comm est le communicateur MPI associé
178 * à \a pm, l'appel à cette méthode créé une propriété comme suit:
179 *
180 * \code
181 * create(H5P_FILE_ACCESS);
182 * H5Pset_fapl_mpio(id(), mpi_comm, MPI_INFO_NULL);
183 * \endcode
184 */
186
187 /*!
188 * \brief Créé une propriété de dataset pour MPIIO.
189 *
190 * Ne fonctionne que si HDF5 est compilé avec MPI. Sinon lance
191 * une exception. L'appel à cette méthode créé une propriété comme suit:
192 *
193 * \code
194 * create(H5P_DATASET_XFER);
195 * H5Pset_dxpl_mpio(id(), H5FD_MPIO_COLLECTIVE);
196 * \endcode
197 */
199};
200
201/*---------------------------------------------------------------------------*/
202/*---------------------------------------------------------------------------*/
203/*!
204 * \brief Encapsule un hid_t pour un fichier.
205 */
206class ARCANE_HDF5_EXPORT HFile
207: public Hid
208{
209 public:
210
211 HFile() = default;
212 ~HFile() { _close(); }
213 HFile(HFile&& rhs)
214 : Hid(rhs.id())
215 {
216 rhs._setNullId();
217 }
218 HFile& operator=(HFile&& rhs)
219 {
220 _setId(rhs.id());
221 rhs._setNullId();
222 return (*this);
223 }
224 HFile& operator=(const HFile& hid) = delete;
225
226 public:
227
228 ARCANE_DEPRECATED_REASON("Y2023: Copy constructor is deprecated. This class has unique ownership")
229 HFile(const HFile& rhs)
230 : Hid(rhs)
231 {}
232
233 public:
234
235 void openTruncate(const String& var);
236 void openAppend(const String& var);
237 void openRead(const String& var);
238 void openTruncate(const String& var, hid_t plist_id);
239 void openAppend(const String& var, hid_t plist_id);
240 void openRead(const String& var, hid_t plist_id);
241 void close();
242
243 private:
244
245 herr_t _close();
246};
247
248/*---------------------------------------------------------------------------*/
249/*---------------------------------------------------------------------------*/
250/*!
251 * \brief Classe d'aide pour rechercher un groupe.
252 */
253class ARCANE_HDF5_EXPORT HGroupSearch
254{
255 public:
256 HGroupSearch(const String& group_name)
257 : m_group_name(group_name)
258 {
259 }
260 public:
261 herr_t iterateMe(const char* member_name)
262 {
263 //cerr << "** ITERATE <" << member_name << ">\n";
264 if (m_group_name==member_name)
265 return 1;
266 return 0;
267 }
268 private:
269 String m_group_name;
270};
271
272/*---------------------------------------------------------------------------*/
273/*---------------------------------------------------------------------------*/
274/*!
275 * \brief Encapsule un hid_t pour un groupe.
276 */
277class ARCANE_HDF5_EXPORT HGroup
278: public Hid
279{
280 public:
281
282 HGroup() {}
283 ~HGroup() { close(); }
284 HGroup(HGroup&& rhs)
285 : Hid(rhs.id())
286 {
287 rhs._setNullId();
288 }
289 HGroup& operator=(HGroup&& rhs)
290 {
291 _setId(rhs.id());
292 rhs._setNullId();
293 return (*this);
294 }
295 HGroup& operator=(const HGroup& hid) = delete;
296
297 public:
298
299 ARCANE_DEPRECATED_REASON("Y2023: Copy constructor is deprecated. This class has unique ownership")
300 HGroup(const HGroup& rhs)
301 : Hid(rhs)
302 {}
303
304 public:
305
306 void create(const Hid& loc_id, const String& group_name);
307 void openOrCreate(const Hid& loc_id, const String& group_name);
308 void recursiveCreate(const Hid& loc_id, const String& var);
309 void recursiveCreate(const Hid& loc_id, const Array<String>& paths);
310 void checkDelete(const Hid& loc_id, const String& var);
311 void recursiveOpen(const Hid& loc_id, const String& var);
312 void open(const Hid& loc_id, const String& var);
313 void openIfExists(const Hid& loc_id, const Array<String>& var);
314 bool hasChildren(const String& var);
315 void close();
316 static bool hasChildren(hid_t loc_id, const String& var);
317
318 private:
319
320 hid_t _checkOrCreate(hid_t loc_id, const String& group_name);
321 hid_t _checkExist(hid_t loc_id, const String& group_name);
322
323 public:
324};
325
326/*---------------------------------------------------------------------------*/
327/*---------------------------------------------------------------------------*/
328/*!
329 * \brief Encapsule un hid_t pour un dataspace.
330 */
331class ARCANE_HDF5_EXPORT HSpace
332: public Hid
333{
334 public:
335
336 HSpace() {}
337 explicit HSpace(hid_t id)
338 : Hid(id)
339 {}
340 HSpace(HSpace&& rhs)
341 : Hid(rhs.id())
342 {
343 rhs._setNullId();
344 }
345 ~HSpace()
346 {
347 if (id() > 0)
348 H5Sclose(id());
349 }
350 HSpace& operator=(HSpace&& rhs)
351 {
352 _setId(rhs.id());
353 rhs._setNullId();
354 return (*this);
355 }
356 HSpace& operator=(const HSpace& hid) = delete;
357
358 public:
359
360 ARCANE_DEPRECATED_REASON("Y2023: Copy constructor is deprecated. This class has unique ownership")
361 HSpace(const HSpace& v)
362 : Hid(v)
363 {}
364
365 public:
366
367 void createSimple(int nb, hsize_t dims[]);
368 void createSimple(int nb, hsize_t dims[], hsize_t max_dims[]);
369 int nbDimension();
370 herr_t getDimensions(hsize_t dims[], hsize_t max_dims[]);
371};
372
373/*---------------------------------------------------------------------------*/
374/*---------------------------------------------------------------------------*/
375/*!
376 * \brief Encapsule un hid_t pour un dataset.
377 */
378class ARCANE_HDF5_EXPORT HDataset
379: public Hid
380{
381 public:
382
383 HDataset() {}
384 ~HDataset() { close(); }
385 HDataset(HDataset&& rhs)
386 : Hid(rhs.id())
387 {
388 rhs._setNullId();
389 }
390 HDataset& operator=(HDataset&& rhs)
391 {
392 _setId(rhs.id());
393 rhs._setNullId();
394 return (*this);
395 }
396 HDataset& operator=(const HDataset& hid) = delete;
397
398 public:
399
400 ARCANE_DEPRECATED_REASON("Y2023: Copy constructor is deprecated. This class has unique ownership")
401 HDataset(const HDataset& v)
402 : Hid(v)
403 {}
404
405 public:
406
407 void close()
408 {
409 if (id() > 0)
410 H5Dclose(id());
411 _setNullId();
412 }
413 void create(const Hid& loc_id, const String& var, hid_t save_type, const HSpace& space_id, hid_t plist);
414 void create(const Hid& loc_id,const String& var,hid_t save_type,
415 const HSpace& space_id,const HProperty& link_plist,
416 const HProperty& creation_plist,const HProperty& access_plist);
417 void recursiveCreate(const Hid& loc_id, const String& var, hid_t save_type, const HSpace& space_id, hid_t plist);
418 void open(const Hid& loc_id, const String& var);
419 void openIfExists(const Hid& loc_id, const String& var);
420 herr_t write(hid_t native_type, const void* array);
421 herr_t write(hid_t native_type, const void* array, const HSpace& memspace_id,
422 const HSpace& filespace_id, hid_t plist);
423 herr_t write(hid_t native_type, const void* array, const HSpace& memspace_id,
424 const HSpace& filespace_id, const HProperty& plist);
425 herr_t read(hid_t native_type, void* array)
426 {
427 return H5Dread(id(), native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, array);
428 }
429 void readWithException(hid_t native_type, void* array);
430 HSpace getSpace();
431 herr_t setExtent(const hsize_t new_dims[]);
432
433 private:
434
435 void _remove(hid_t hid, const String& var);
436};
437
438/*---------------------------------------------------------------------------*/
439/*---------------------------------------------------------------------------*/
440/*!
441 * \brief Encapsule un hid_t pour un attribute.
442 */
443class ARCANE_HDF5_EXPORT HAttribute
444: public Hid
445{
446 public:
447
448 HAttribute() {}
449 ~HAttribute()
450 {
451 if (id() > 0)
452 H5Aclose(id());
453 }
454 HAttribute(HAttribute&& rhs)
455 : Hid(rhs.id())
456 {
457 rhs._setNullId();
458 }
459 HAttribute& operator=(HAttribute&& rhs)
460 {
461 _setId(rhs.id());
462 rhs._setNullId();
463 return (*this);
464 }
465 HAttribute& operator=(const HAttribute& hid) = delete;
466
467 public:
468
469 ARCANE_DEPRECATED_REASON("Y2023: Copy constructor is deprecated. This class has unique ownership")
470 HAttribute(const HAttribute& v)
471 : Hid(v)
472 {}
473
474 public:
475
476 void remove(const Hid& loc_id, const String& var)
477 {
478 _setId(H5Adelete(loc_id.id(), var.localstr()));
479 }
480 void create(const Hid& loc_id, const String& var, hid_t save_type, const HSpace& space_id)
481 {
482 _setId(H5Acreate2(loc_id.id(), var.localstr(), save_type, space_id.id(), H5P_DEFAULT, H5P_DEFAULT));
483 }
484 void open(const Hid& loc_id, const String& var)
485 {
486 _setId(H5Aopen_name(loc_id.id(), var.localstr()));
487 }
488 herr_t write(hid_t native_type, void* array)
489 {
490 return H5Awrite(id(), native_type, array);
491 }
492 herr_t read(hid_t native_type, void* array)
493 {
494 return H5Aread(id(), native_type, array);
495 }
496 HSpace getSpace()
497 {
498 return HSpace(H5Aget_space(id()));
499 }
500};
501
502
503/*---------------------------------------------------------------------------*/
504/*---------------------------------------------------------------------------*/
505/*!
506 * \brief Encapsule un hid_t pour un type.
507 */
508class ARCANE_HDF5_EXPORT HType
509: public Hid
510{
511 public:
512
513 HType() {}
514 ~HType()
515 {
516 if (id() > 0)
517 H5Tclose(id());
518 }
519 HType(HType&& rhs)
520 : Hid(rhs.id())
521 {
522 rhs._setNullId();
523 }
524 HType& operator=(HType&& rhs)
525 {
526 _setId(rhs.id());
527 rhs._setNullId();
528 return (*this);
529 }
530 HType& operator=(const HType& hid) = delete;
531
532 public:
533
534 ARCANE_DEPRECATED_REASON("Y2023: Copy constructor is deprecated. This class has unique ownership")
535 HType(const HType& v)
536 : Hid(v)
537 {}
538
539 public:
540
541 void setId(hid_t new_id)
542 {
543 _setId(new_id);
544 }
545};
546
547/*---------------------------------------------------------------------------*/
548/*---------------------------------------------------------------------------*/
549/*!
550 * \brief Définition des types standards Arcane pour hdf5.
551 *
552 * Une instance de cette classe construit des types HDF5 pour faire la
553 * conversion entre les types HDF5 et les types Arcane.
554 *
555 * Le constructeur par défaut utilisant des appels HDF5, il n'est pas thread-safe.
556 * Si on est en contexte multi-thread, il est préférable d'utiliser
557 * StandardTypes(false) et d'appeler init() pour initialiser les types.
558 */
559class ARCANE_HDF5_EXPORT StandardTypes
560{
561 public:
562
563 /*!
564 * \brief Créé une instance en initialisant les types.
565 *
566 * \warning non thread-safe.
567 */
569
570 //! Créé une instance sans initialiser les types is \a do_init est faux.
571 explicit StandardTypes(bool do_init);
572
573 ARCANE_DEPRECATED_REASON("Y2023: Copy constructor is deprecated. This class has unique ownership")
574 StandardTypes(const StandardTypes& rhs) = default;
575
577
578 StandardTypes& operator=(const StandardTypes& rhs) = delete;
579
580 public:
581
582 //! Initialise les types.
583 void initialize();
584
585 public:
586
587 hid_t nativeType(float) const { return H5T_NATIVE_FLOAT; }
588 hid_t nativeType(double) const { return H5T_NATIVE_DOUBLE; }
589 hid_t nativeType(Real2) const { return m_real2_id.id(); }
590 hid_t nativeType(Real3) const { return m_real3_id.id(); }
591 hid_t nativeType(Real2x2) const { return m_real2x2_id.id(); }
592 hid_t nativeType(Real3x3) const { return m_real3x3_id.id(); }
593 hid_t nativeType(long double) const { return H5T_NATIVE_LDOUBLE; }
594 hid_t nativeType(unsigned int) const { return H5T_NATIVE_UINT; }
595 hid_t nativeType(unsigned long) const { return H5T_NATIVE_ULONG; }
596 hid_t nativeType(unsigned long long) const { return H5T_NATIVE_ULLONG; }
597 hid_t nativeType(int) const { return H5T_NATIVE_INT; }
598 hid_t nativeType(long long) const { return H5T_NATIVE_LLONG; }
599 hid_t nativeType(long) const { return H5T_NATIVE_LONG; }
600 hid_t nativeType(char) const { return H5T_NATIVE_CHAR; }
601 hid_t nativeType(unsigned char) const { return H5T_NATIVE_UCHAR; }
602 hid_t nativeType(signed char) const { return H5T_NATIVE_SCHAR; }
603 hid_t nativeType(unsigned short) const { return H5T_NATIVE_USHORT; }
604 hid_t nativeType(short) const { return H5T_NATIVE_SHORT; }
605#ifdef ARCANE_REAL_NOT_BUILTIN
606 hid_t nativeType(Real) const;
607#endif
608 hid_t nativeType(eDataType sd) const;
609 hid_t nativeType(BFloat16) const { return m_bfloat16_id.id(); }
610 hid_t nativeType(Float16) const { return m_float16_id.id(); }
611
612 public:
613
614 hid_t saveType(float) const
615 {
616 return m_float32_id.id();
617 }
618 hid_t saveType(double) const
619 {
620 return m_real_id.id();
621 }
622 hid_t saveType(Real2) const
623 {
624 return m_real2_id.id();
625 }
626 hid_t saveType(Real3) const
627 {
628 return m_real3_id.id();
629 }
630 hid_t saveType(Real2x2) const
631 {
632 return m_real2x2_id.id();
633 }
634 hid_t saveType(Real3x3) const
635 {
636 return m_real3x3_id.id();
637 }
638 hid_t saveType(long double) const
639 {
640 return m_real_id.id();
641 }
642 hid_t saveType(short) const
643 {
644 return m_short_id.id();
645 }
646 hid_t saveType(unsigned short) const
647 {
648 return m_ushort_id.id();
649 }
650 hid_t saveType(unsigned int) const
651 {
652 return m_uint_id.id();
653 }
654 hid_t saveType(unsigned long) const
655 {
656 return m_ulong_id.id();
657 }
658 hid_t saveType(unsigned long long) const
659 {
660 return m_ulong_id.id();
661 }
662 hid_t saveType(int) const
663 {
664 return m_int_id.id();
665 }
666 hid_t saveType(long) const
667 {
668 return m_long_id.id();
669 }
670 hid_t saveType(long long) const
671 {
672 return m_long_id.id();
673 }
674 hid_t saveType(char) const
675 {
676 return m_char_id.id();
677 }
678 hid_t saveType(unsigned char) const
679 {
680 return m_uchar_id.id();
681 }
682 hid_t saveType(signed char) const
683 {
684 return m_schar_id.id();
685 }
686 hid_t saveType(BFloat16) const
687 {
688 return m_bfloat16_id.id();
689 }
690 hid_t saveType(Float16) const
691 {
692 return m_float16_id.id();
693 }
694#ifdef ARCANE_REAL_NOT_BUILTIN
695 hid_t saveType(Real) const
696 {
697 return m_real_id.id();
698 }
699#endif
700 hid_t saveType(eDataType sd) const;
701
702 private:
703
704 /*!
705 * \brief Classe initialisant HDF.
706 *
707 * \warning Cette instance doit toujours être définie avant les membres qui
708 * utilisent HDF5 pour que l'initialisation est lieu en premier et la libération
709 * des ressources en dernier.
710 */
711 HInit m_init;
712
713 public:
714
715 HType m_char_id; //!< Identifiant HDF des charactères
716 HType m_uchar_id; //!< Identifiant HDF des caractères non-signés
717 HType m_schar_id; //!< Identifiant HDF des caractères signés
718 HType m_short_id; //!< Identifiant HDF des entiers signés
719 HType m_ushort_id; //!< Identifiant HDF des entiers long signés
720 HType m_int_id; //!< Identifiant HDF des entiers signés
721 HType m_long_id; //!< Identifiant HDF des entiers long signés
722 HType m_uint_id; //!< Identifiant HDF des entiers non signés
723 HType m_ulong_id; //!< Identifiant HDF des entiers long non signés
724 HType m_real_id; //!< Identifiant HDF des réels
725 HType m_real2_id; //!< Identifiant HDF pour les Real2
726 HType m_real3_id; //!< Identifiant HDF pour les Real3
727 HType m_real2x2_id; //!< Identifiant HDF pour les Real2x2
728 HType m_real3x3_id; //!< Identifiant HDF pour les Real3x3
729 HType m_float16_id; //!< Identifiant HDF pour les Float16
730 HType m_bfloat16_id; //!< Identifiant HDF pour les BFloat16
731 HType m_float32_id; //!< Identifiant HDF pour les Float16
732
733 private:
734
735 void _H5Tinsert(hid_t type, const char* name, Integer offset, hid_t field_id);
736};
737
738/*---------------------------------------------------------------------------*/
739/*---------------------------------------------------------------------------*/
740/*!
741 * \brief Encapsule un dataset simple d'un fichier HDF5 qui représente
742 * un tableau.
743 */
744class ARCANE_HDF5_EXPORT StandardArray
745{
746 public:
747
748 StandardArray(hid_t hfile, const String& hpath);
749 virtual ~StandardArray() {}
750
751 public:
752
753 /*!
754 * \brief En lecture, positionne le chemin dans \a hfile du dataset contenant les unique_ids.
755 *
756 * Cet appel est optionnel mais s'il est utilisé, il doit l'être avant
757 * de lire les valeurs.
758 */
759 void setIdsPath(const String& ids_path);
760 void readDim();
761 Int64ConstArrayView dimensions() const { return m_dimensions; }
762 virtual bool exists() const;
763
764 protected:
765
766 void _write(const void* buffer, Integer nb_element, hid_t save_type, hid_t native_type);
767
768 protected:
769
770 hid_t m_hfile;
771 String m_hpath;
772 String m_ids_hpath;
773 HDataset m_hdataset;
774 HDataset m_ids_dataset;
775 Int64UniqueArray m_dimensions;
776 bool m_is_init;
777};
778
779/*---------------------------------------------------------------------------*/
780/*---------------------------------------------------------------------------*/
781/*!
782 * \brief Encapsule un dataset simple d'un fichier HDF5 qui représente
783 * un tableau.
784 */
785template<typename DataType>
786class ARCANE_HDF5_EXPORT StandardArrayT
787: public StandardArray
788{
789 private:
790 struct ValueWithUid
791 {
792 public:
793 Int64 m_uid;
794 Integer m_index;
795 public:
796 bool operator<(const ValueWithUid& rhs) const
797 {
798 return m_uid < rhs.m_uid;
799 }
800 };
801 public:
802 StandardArrayT(hid_t hfile,const String& hpath);
803 public:
804 /*!
805 * \brief Lit le dataset d'un tableau 1D.
806 * Cette opération n'est valide qu'après un appel à readDim().
807 * \a buffer doit avoir été alloué.
808 * Pour lire directement, utiliser directRead()
809 */
810 void read(StandardTypes& st,ArrayView<DataType> buffer);
811 /*!
812 * \brief Lit le dataset d'un tableau 1D.
813 */
814 void directRead(StandardTypes& st,Array<DataType>& buffer);
815 void parallelRead(IParallelMng* pm,StandardTypes& st,
816 Array<DataType>& buffer,Int64Array& unique_ids);
817 void write(StandardTypes& st,ConstArrayView<DataType> buffer);
818 void parallelWrite(IParallelMng* pm,StandardTypes& st,
820 Int64ConstArrayView unique_ids);
821 private:
822 void _writeSortedValues(ITraceMng* tm,StandardTypes& st,ConstArrayView<DataType> buffer,
823 Int64ConstArrayView unique_ids);
824};
825
826/*---------------------------------------------------------------------------*/
827/*---------------------------------------------------------------------------*/
828
829/*!
830 * \brief Encapsule un dataset simple d'un fichier HDF5 qui représente un scalaire (éventuellement String).
831 */
832template<typename DataType>
833class ARCANE_HDF5_EXPORT StandardScalarT
834{
835 public:
836 //! Constructeur
837 StandardScalarT(hid_t hfile,const String& hpath) : m_hfile(hfile), m_hpath(hpath) { }
838 public:
839 //! Lit une donnée
840 DataType read(Hdf5Utils::StandardTypes& st);
841
842 //! Ecrit une donnée
843 void write(Hdf5Utils::StandardTypes& st, const DataType & t);
844
845 protected:
846 hid_t m_hfile;
847 String m_hpath;
848};
849
850/*---------------------------------------------------------------------------*/
851/*---------------------------------------------------------------------------*/
852
853}
854
855/*---------------------------------------------------------------------------*/
856/*---------------------------------------------------------------------------*/
857
858} // End namespace Arcane
859
860/*---------------------------------------------------------------------------*/
861/*---------------------------------------------------------------------------*/
862
863#endif
Déclarations des types utilisés dans Arcane.
Vue modifiable d'un tableau d'un type T.
Classe de base des vecteurs 1D de données.
Vue constante d'un tableau de type T.
Type flottant demi-précision.
Encapsule un hid_t pour un dataset.
Definition Hdf5Utils.h:380
Classe servant d'initialiseur pour HDF.
Definition Hdf5Utils.h:74
static bool hasParallelHdf5()
Vrai HDF5 est compilé avec le support de MPI.
Definition Hdf5Utils.cc:61
Encapsule un hid_t pour une propriété (H5P*).
Definition Hdf5Utils.h:132
void createDatasetTransfertCollectiveMPIIO()
Créé une propriété de dataset pour MPIIO.
Definition Hdf5Utils.cc:666
void createFilePropertyMPIIO(IParallelMng *pm)
Créé une propriété de fichier pour MPIIO.
Definition Hdf5Utils.cc:645
Encapsule un hid_t pour un dataspace.
Definition Hdf5Utils.h:333
Encapsule un hid_t pour un type.
Definition Hdf5Utils.h:510
void read(StandardTypes &st, ArrayView< DataType > buffer)
Lit le dataset d'un tableau 1D. Cette opération n'est valide qu'après un appel à readDim()....
void directRead(StandardTypes &st, Array< DataType > &buffer)
Lit le dataset d'un tableau 1D.
void setIdsPath(const String &ids_path)
En lecture, positionne le chemin dans hfile du dataset contenant les unique_ids.
Definition Hdf5Utils.cc:943
StandardScalarT(hid_t hfile, const String &hpath)
Constructeur.
Definition Hdf5Utils.h:837
Définition des types standards Arcane pour hdf5.
Definition Hdf5Utils.h:560
HType m_bfloat16_id
Identifiant HDF pour les BFloat16.
Definition Hdf5Utils.h:730
HType m_real2x2_id
Identifiant HDF pour les Real2x2.
Definition Hdf5Utils.h:727
StandardTypes()
Créé une instance en initialisant les types.
Definition Hdf5Utils.cc:683
HType m_long_id
Identifiant HDF des entiers long signés.
Definition Hdf5Utils.h:721
HType m_int_id
Identifiant HDF des entiers signés.
Definition Hdf5Utils.h:720
HType m_short_id
Identifiant HDF des entiers signés.
Definition Hdf5Utils.h:718
HType m_real3x3_id
Identifiant HDF pour les Real3x3.
Definition Hdf5Utils.h:728
HType m_real_id
Identifiant HDF des réels.
Definition Hdf5Utils.h:724
HType m_ushort_id
Identifiant HDF des entiers long signés.
Definition Hdf5Utils.h:719
HType m_ulong_id
Identifiant HDF des entiers long non signés.
Definition Hdf5Utils.h:723
HType m_schar_id
Identifiant HDF des caractères signés.
Definition Hdf5Utils.h:717
HType m_uchar_id
Identifiant HDF des caractères non-signés.
Definition Hdf5Utils.h:716
HType m_real2_id
Identifiant HDF pour les Real2.
Definition Hdf5Utils.h:725
HType m_float32_id
Identifiant HDF pour les Float16.
Definition Hdf5Utils.h:731
HType m_float16_id
Identifiant HDF pour les Float16.
Definition Hdf5Utils.h:729
HType m_char_id
Identifiant HDF des charactères.
Definition Hdf5Utils.h:715
void initialize()
Initialise les types.
Definition Hdf5Utils.cc:702
HType m_uint_id
Identifiant HDF des entiers non signés.
Definition Hdf5Utils.h:722
HType m_real3_id
Identifiant HDF pour les Real3.
Definition Hdf5Utils.h:726
Interface du gestionnaire de parallélisme pour un sous-domaine.
Interface du gestionnaire de traces.
Classe gérant un vecteur de réel de dimension 2.
Definition Real2.h:121
Classe gérant une matrice de réel de dimension 2x2.
Definition Real2x2.h:53
Classe gérant un vecteur de réel de dimension 3.
Definition Real3.h:132
Classe gérant une matrice de réel de dimension 3x3.
Definition Real3x3.h:66
Chaîne de caractères unicode.
const char * localstr() const
Retourne la conversion de l'instance dans l'encodage UTF-8.
Definition String.cc:227
Fonctions utilitaires pour Hdf5.
Definition Hdf5Utils.cc:36
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Array< Int64 > Int64Array
Tableau dynamique à une dimension d'entiers 64 bits.
Definition UtilsTypes.h:212
UniqueArray< Int64 > Int64UniqueArray
Tableau dynamique à une dimension d'entiers 64 bits.
Definition UtilsTypes.h:426
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
bool operator<(const Item &item1, const Item &item2)
Compare deux entités.
Definition Item.h:542
ConstArrayView< Int64 > Int64ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 64 bits.
Definition UtilsTypes.h:567
double Real
Type représentant un réel.
eDataType
Type d'une donnée.
Definition DataTypes.h:39