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