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