Arcane  v3.15.0.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
Hdf5Utils.cc
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.cc (C) 2000-2024 */
9/* */
10/* Utilitaires HDF5. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/Iostream.h"
15#include "arcane/utils/Array.h"
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/NotSupportedException.h"
18#include "arcane/utils/ArgumentException.h"
19#include "arcane/utils/ITraceMng.h"
20#include "arcane/utils/TraceInfo.h"
21#include "arcane/utils/IOException.h"
22
23#include "arcane/ArcaneException.h"
24#include "arcane/IParallelMng.h"
25
26#include "arcane/hdf5/Hdf5Utils.h"
27
28#include <algorithm>
29
30#include <mutex>
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
36{
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
41namespace
42{
43std::once_flag h5open_once_flag;
44}
45
46/*---------------------------------------------------------------------------*/
47/*---------------------------------------------------------------------------*/
48
49HInit::
50HInit()
51{
52 // Garanti que cela ne sera appelé qu'une seule fois et protège des appels
53 // concurrents.
54 std::call_once(h5open_once_flag, [](){ H5open(); });
55}
56
57/*---------------------------------------------------------------------------*/
58/*---------------------------------------------------------------------------*/
59
62{
63#ifdef H5_HAVE_PARALLEL
64 return true;
65#else
66 return false;
67#endif
68}
69
70/*---------------------------------------------------------------------------*/
71/*---------------------------------------------------------------------------*/
72
73namespace
74{
75
76hid_t _H5Gopen(hid_t loc_id, const char *name)
77{
78 return H5Gopen2(loc_id,name,H5P_DEFAULT);
79}
80
81hid_t _H5Gcreate(hid_t loc_id, const char *name)
82{
83 return H5Gcreate2(loc_id, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
84}
85
86}
87/*---------------------------------------------------------------------------*/
88/*---------------------------------------------------------------------------*/
89
90extern "C" ARCANE_HDF5_EXPORT herr_t
91_ArcaneHdf5UtilsGroupIterateMe(hid_t g,const char* mn,void* ptr)
92{
93 ARCANE_UNUSED(g);
94 HGroupSearch* rw = reinterpret_cast<HGroupSearch*>(ptr);
95 return rw->iterateMe(mn);
96}
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
100
101void
102splitString(const String& str,Array<String>& str_array,char c)
103{
104 const char* str_str = str.localstr();
105 Int64 offset = 0;
106 Int64 len = str.length();
107 for( Int64 i=0; i<len; ++i ){
108 if (str_str[i]==c && i!=offset){
109 str_array.add(std::string_view(str_str+offset,i-offset));
110 offset = i+1;
111 }
112 }
113 if (len!=offset)
114 str_array.add(std::string_view(str_str+offset,len-offset));
115}
116
117/*---------------------------------------------------------------------------*/
118/*---------------------------------------------------------------------------*/
119
120void HFile::
121openTruncate(const String& var)
122{
123 close();
124 _setId(H5Fcreate(var.localstr(),H5F_ACC_TRUNC,H5P_DEFAULT,H5P_DEFAULT));
125 if (isBad())
126 ARCANE_THROW(ReaderWriterException,"Can not open file '{0}'",var);
127}
128
129void HFile::
130openAppend(const String& var)
131{
132 close();
133 _setId(H5Fopen(var.localstr(),H5F_ACC_RDWR,H5P_DEFAULT));
134 if (isBad())
135 ARCANE_THROW(ReaderWriterException,"Can not open file '{0}'",var);
136}
137
138void HFile::
139openRead(const String& var)
140{
141 close();
142 _setId(H5Fopen(var.localstr(),H5F_ACC_RDONLY,H5P_DEFAULT));
143 if (isBad())
144 ARCANE_THROW(ReaderWriterException,"Can not open file '{0}'",var);
145}
146
147void HFile::
148openTruncate(const String& var,hid_t plist_id)
149{
150 close();
151 _setId(H5Fcreate(var.localstr(),H5F_ACC_TRUNC,H5P_DEFAULT,plist_id));
152 if (isBad())
153 ARCANE_THROW(ReaderWriterException,"Can not open file '{0}'",var);
154}
155
156void HFile::
157openAppend(const String& var,hid_t plist_id)
158{
159 close();
160 _setId(H5Fopen(var.localstr(),H5F_ACC_RDWR,plist_id));
161 if (isBad())
162 ARCANE_THROW(ReaderWriterException,"Can not open file '{0}'",var);
163}
164
165void HFile::
166openRead(const String& var,hid_t plist_id)
167{
168 close();
169 _setId(H5Fopen(var.localstr(),H5F_ACC_RDONLY,plist_id));
170 if (isBad())
171 ARCANE_THROW(ReaderWriterException,"Can not open file '{0}'",var);
172}
173
174/*---------------------------------------------------------------------------*/
175/*---------------------------------------------------------------------------*/
176
177herr_t HFile::
178_close()
179{
180 herr_t e = 0;
181 if (id()>0){
182 e = H5Fclose(id());
183 _setNullId();
184 }
185 return e;
186}
187
188/*---------------------------------------------------------------------------*/
189/*---------------------------------------------------------------------------*/
190
191void HFile::
192close()
193{
194 herr_t e = _close();
195 if (e<0)
196 ARCANE_THROW(ReaderWriterException,"Can not close file");
197}
198
199/*---------------------------------------------------------------------------*/
200/*---------------------------------------------------------------------------*/
201
202void HGroup::
203recursiveCreate(const Hid& loc_id,const String& var)
204{
205 UniqueArray<String> bufs;
206 splitString(var,bufs,'/');
207 recursiveCreate(loc_id,bufs);
208}
209
210void HGroup::
211recursiveCreate(const Hid& loc_id,const Array<String>& bufs)
212{
213 close();
214 hid_t last_hid = loc_id.id();
215 Integer nb_create = bufs.size();
216 UniqueArray<hid_t> ref_ids(nb_create);
217 for( Integer i=0; i<nb_create; ++i ){
218 last_hid = _checkOrCreate(last_hid,bufs[i]);
219 ref_ids[i] = last_hid;
220 }
221 // Libere tous les groupes intermediaires crees
222 for( Integer i=0; i<nb_create-1; ++i )
223 H5Gclose(ref_ids[i]);
224 _setId(last_hid);
225}
226
227/*---------------------------------------------------------------------------*/
228/*---------------------------------------------------------------------------*/
229
230void HGroup::
231checkDelete(const Hid& loc_id,const String& var)
232{
233 UniqueArray<String> bufs;
234 splitString(var,bufs,'/');
235 hid_t last_hid = loc_id.id();
236 hid_t parent_hid = last_hid;
237 Integer i = 0;
238 Integer size = bufs.size();
239 for( ; i<size; ++i ){
240 parent_hid = last_hid;
241 last_hid = _checkExist(last_hid,bufs[i]);
242 if (last_hid==0)
243 break;
244 }
245 // Groupe trouvé, on le détruit.
246 if (last_hid>0 && parent_hid>0 && i==size){
247 //cerr << "** DELETE <" << bufs[size-1] << "\n";
248 H5Gunlink(parent_hid,bufs[size-1].localstr());
249 }
250}
251
252/*---------------------------------------------------------------------------*/
253/*---------------------------------------------------------------------------*/
254
255void HGroup::
256recursiveOpen(const Hid& loc_id,const String& var)
257{
258 close();
259 UniqueArray<String> bufs;
260 splitString(var,bufs,'/');
261 hid_t last_hid = loc_id.id();
262 Integer nb_open = bufs.size();
263 UniqueArray<hid_t> ref_ids(nb_open);
264 for( Integer i=0; i<nb_open; ++i ){
265 last_hid = _H5Gopen(last_hid,bufs[i].localstr());
266 ref_ids[i] = last_hid;
267 }
268 // Libere tous les groupes intermediaires ouverts
269 for( Integer i=0; i<nb_open-1; ++i )
270 H5Gclose(ref_ids[i]);
271 _setId(last_hid);
272}
273
274/*---------------------------------------------------------------------------*/
275/*---------------------------------------------------------------------------*/
276
277void HGroup::
278openIfExists(const Hid& loc_id,const Array<String>& paths)
279{
280 close();
281 hid_t last_hid = loc_id.id();
282 bool is_valid = true;
283 Integer nb_open = paths.size();
284 UniqueArray<hid_t> ref_ids;
285 ref_ids.reserve(nb_open);
286 for( Integer i=0; i<nb_open; ++i ){
287 if (HGroup::hasChildren(last_hid,paths[i].localstr())){
288 last_hid = _H5Gopen(last_hid,paths[i].localstr());
289 ref_ids.add(last_hid);
290 }
291 else{
292 is_valid = false;
293 break;
294 }
295 }
296 if (is_valid)
297 _setId(last_hid);
298 // Ferme tous les groupes intermediaires
299 for( Integer i=0; i<ref_ids.size(); ++i ){
300 if (ref_ids[i]!=last_hid)
301 H5Gclose(ref_ids[i]);
302 }
303}
304
305/*---------------------------------------------------------------------------*/
306/*---------------------------------------------------------------------------*/
307
308bool HGroup::
309hasChildren(const String& var)
310{
311 return hasChildren(id(),var);
312}
313
314/*---------------------------------------------------------------------------*/
315/*---------------------------------------------------------------------------*/
316
317bool HGroup::
318hasChildren(hid_t loc_id,const String& var)
319{
320 HGroupSearch gs(var);
321 herr_t v = H5Giterate(loc_id,".",0,_ArcaneHdf5UtilsGroupIterateMe,&gs);
322 bool has_children = v>0;
323 //cout << "** HAS CHILDREN " << var << " v=" << has_children << '\n';
324 return has_children;
325}
326
327/*---------------------------------------------------------------------------*/
328/*---------------------------------------------------------------------------*/
329
330hid_t HGroup::
331_checkOrCreate(hid_t loc_id,const String& group_name)
332{
333 // Pour vérifier si un groupe existe déjà, comme il n'existe aucune
334 // fonction digne de ce nom dans HDF5, on utilise le mécanisme d'itération
335 // pour stocker tous les groupes fils de ce groupe, et on recherche ensuite
336 // si le groupe souhaité existe
337 HGroupSearch gs(group_name);
338 //cerr << "** CHECK CREATE <" << group_name.str() << ">\n";
339 herr_t v = H5Giterate(loc_id,".",0,_ArcaneHdf5UtilsGroupIterateMe,&gs);
340
341 // Regarde si le groupe existe déjà
342 //herr_t he = H5Gget_objinfo(loc_id,group_name.str(),true,0);
343 //cerr << "** CHECK CREATE <" << group_name.str() << "> " << v << "\n";
344 //cerr << "** CHECK CREATE <" << group_name.str() << "> " << v << ' ' << he << "\n";
345 if (v>0){
346 return _H5Gopen(loc_id,group_name.localstr());
347 }
348 hid_t new_id = _H5Gcreate(loc_id,group_name.localstr());
349 //cerr << "** TRY TO CREATE <" << group_name.str() << "> " << new_id << "\n";
350 return new_id;
351}
352
353/*---------------------------------------------------------------------------*/
354/*---------------------------------------------------------------------------*/
355
356void HGroup::
357create(const Hid& loc_id, const String& group_name)
358{
359 _setId(H5Gcreate2(loc_id.id(), group_name.localstr(), H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT));
360}
361
362/*---------------------------------------------------------------------------*/
363/*---------------------------------------------------------------------------*/
364
365void HGroup::
366openOrCreate(const Hid& loc_id, const String& group_name)
367{
368 hid_t id = _checkOrCreate(loc_id.id(),group_name);
369 if (id<0)
370 ARCANE_THROW(ReaderWriterException,"Can not open or create group named '{0}'",group_name);
371 _setId(id);
372}
373
374/*---------------------------------------------------------------------------*/
375/*---------------------------------------------------------------------------*/
376
377void HGroup::
378open(const Hid& loc_id,const String& var)
379{
380 hid_t id = _H5Gopen(loc_id.id(),var.localstr());
381 if (id<0)
382 ARCANE_THROW(ReaderWriterException,"Can not find group named '{0}'",var);
383 _setId(id);
384}
385
386/*---------------------------------------------------------------------------*/
387/*---------------------------------------------------------------------------*/
388
389void HGroup::
390close()
391{
392 if (id()>0){
393 H5Gclose(id());
394 _setNullId();
395 }
396}
397
398/*---------------------------------------------------------------------------*/
399/*---------------------------------------------------------------------------*/
400
401hid_t HGroup::
402_checkExist(hid_t loc_id,const String& group_name)
403{
404 // Pour vérifier si un groupe existe déjà, comme il n'existe aucune
405 // fonction digne de ce nom dans HDF5, on utilise le mécanisme d'itération
406 // pour stocker tous les groupes fils de ce groupe, et on recherche ensuite
407 // si le groupe souhaité existe
408 HGroupSearch gs(group_name);
409 //cerr << "** CHECK CREATE <" << group_name.str() << ">\n";
410 herr_t v = H5Giterate(loc_id,".",0,_ArcaneHdf5UtilsGroupIterateMe,&gs);
411
412 // Regarde si le groupe existe déjà
413 //herr_t he = H5Gget_objinfo(loc_id,group_name.str(),true,0);
414 //cerr << "** CHECK CREATE <" << group_name.str() << "> " << v << "\n";
415 //cerr << "** CHECK CREATE <" << group_name.str() << "> " << v << ' ' << he << "\n";
416 if (v>0){
417 return _H5Gopen(loc_id,group_name.localstr());
418 }
419 //hid_t new_id = H5Gcreate(loc_id,group_name.localstr(),0);
420 //cerr << "** TRY TO CREATE <" << group_name.str() << "> " << new_id << "\n";
421 return 0;
422}
423
424/*---------------------------------------------------------------------------*/
425/*---------------------------------------------------------------------------*/
426
427/*---------------------------------------------------------------------------*/
428/*---------------------------------------------------------------------------*/
429
430void HSpace::
431createSimple(int nb, hsize_t dims[])
432{
433 _setId(H5Screate_simple(nb, dims, nullptr));
434}
435
436/*---------------------------------------------------------------------------*/
437/*---------------------------------------------------------------------------*/
438
439void HSpace::
440createSimple(int nb, hsize_t dims[], hsize_t max_dims[])
441{
442 _setId(H5Screate_simple(nb, dims, max_dims));
443}
444
445/*---------------------------------------------------------------------------*/
446/*---------------------------------------------------------------------------*/
447
448int HSpace::
449nbDimension()
450{
451 return H5Sget_simple_extent_ndims(id());
452}
453
454/*---------------------------------------------------------------------------*/
455/*---------------------------------------------------------------------------*/
456
457herr_t HSpace::
458getDimensions(hsize_t dims[], hsize_t max_dims[])
459{
460 return H5Sget_simple_extent_dims(id(), dims, max_dims);
461}
462
463/*---------------------------------------------------------------------------*/
464/*---------------------------------------------------------------------------*/
465
466/*---------------------------------------------------------------------------*/
467/*---------------------------------------------------------------------------*/
468
469void HDataset::
470create(const Hid& loc_id,const String& var,hid_t save_type,
471 const HSpace& space_id,hid_t plist)
472{
473 hid_t hid = H5Dcreate2(loc_id.id(),var.localstr(),save_type,space_id.id(),
474 plist,H5P_DEFAULT,H5P_DEFAULT);
475 //cerr << "** CREATE ID=" << hid << '\n';
476 _setId(hid);
477}
478
479/*---------------------------------------------------------------------------*/
480/*---------------------------------------------------------------------------*/
481
482void HDataset::
483create(const Hid& loc_id,const String& var,hid_t save_type,
484 const HSpace& space_id,const HProperty& link_plist,
485 const HProperty& creation_plist,const HProperty& access_plist)
486{
487 hid_t hid = H5Dcreate2(loc_id.id(),var.localstr(),save_type,space_id.id(),
488 link_plist.id(),creation_plist.id(),access_plist.id());
489 //cerr << "** CREATE ID=" << hid << '\n';
490 _setId(hid);
491}
492
493/*---------------------------------------------------------------------------*/
494/*---------------------------------------------------------------------------*/
495
496herr_t HDataset::
497write(hid_t native_type,const void* array)
498{
499 //cerr << "** WRITE ID=" << id() << '\n';
500 return H5Dwrite(id(),native_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,array);
501}
502
503/*---------------------------------------------------------------------------*/
504/*---------------------------------------------------------------------------*/
505
506herr_t HDataset::
507write(hid_t native_type,const void* array,const HSpace& memspace_id,
508 const HSpace& filespace_id,hid_t plist)
509{
510 //cerr << "** WRITE ID=" << id() << '\n';
511 return H5Dwrite(id(),native_type,memspace_id.id(),filespace_id.id(),plist,array);
512}
513
514/*---------------------------------------------------------------------------*/
515/*---------------------------------------------------------------------------*/
516
517herr_t HDataset::
518write(hid_t native_type,const void* array,const HSpace& memspace_id,
519 const HSpace& filespace_id,const HProperty& plist)
520{
521 //cerr << "** WRITE ID=" << id() << '\n';
522 return H5Dwrite(id(),native_type,memspace_id.id(),filespace_id.id(),plist.id(),array);
523}
524
525/*---------------------------------------------------------------------------*/
526/*---------------------------------------------------------------------------*/
527
528void HDataset::
529readWithException(hid_t native_type,void* array)
530{
531 herr_t err = H5Dread(id(),native_type,H5S_ALL,H5S_ALL,H5P_DEFAULT,array);
532 if (err!=0)
533 ARCANE_THROW(IOException,"Can not read dataset");
534}
535
536/*---------------------------------------------------------------------------*/
537/*---------------------------------------------------------------------------*/
538
539HSpace HDataset::
540getSpace()
541{
542 return HSpace(H5Dget_space(id()));
543}
544
545/*---------------------------------------------------------------------------*/
546/*---------------------------------------------------------------------------*/
547
548herr_t HDataset::
549setExtent(const hsize_t new_dims[])
550{
551 return H5Dset_extent(id(),new_dims);
552}
553
554/*---------------------------------------------------------------------------*/
555/*---------------------------------------------------------------------------*/
556
557void HDataset::
558recursiveCreate(const Hid& loc_id,const String& var,hid_t save_type,
559 const HSpace& space_id,hid_t plist)
560{
561 // Si le dataset existe déjà, il faut le supprimer
562 // car sinon il n'est pas toujours possible de modifer le space_id
563 UniqueArray<String> paths;
564 splitString(var,paths,'/');
565 Integer nb_path = paths.size();
566 if (nb_path==1){
567 if (HGroup::hasChildren(loc_id.id(),var)){
568 _remove(loc_id.id(),var);
569 }
570 create(loc_id,var,save_type,space_id,plist);
571 return;
572 }
573 String last_name = paths[nb_path-1];
574 paths.resize(nb_path-1);
575 HGroup group;
576 group.recursiveCreate(loc_id,paths);
577 if (group.hasChildren(last_name)){
578 _remove(group.id(),last_name);
579 }
580 create(group.id(),last_name,save_type,space_id,plist);
581}
582
583/*---------------------------------------------------------------------------*/
584/*---------------------------------------------------------------------------*/
585
586void HDataset::
587_remove(hid_t hid,const String& var)
588{
589 H5Gunlink(hid,var.localstr());
590}
591
592/*---------------------------------------------------------------------------*/
593/*---------------------------------------------------------------------------*/
594
595void HDataset::
596open(const Hid& loc_id,const String& var)
597{
598 _setId(H5Dopen2(loc_id.id(),var.localstr(),H5P_DEFAULT));
599 if(isBad())
600 ARCANE_THROW(IOException,"Can not open dataset '{0}'",var);
601}
602
603/*---------------------------------------------------------------------------*/
604/*---------------------------------------------------------------------------*/
605
606void HDataset::
607openIfExists(const Hid& loc_id,const String& var)
608{
609 UniqueArray<String> paths;
610 splitString(var,paths,'/');
611 Integer nb_path = paths.size();
612 HGroup parent_group;
613 String last_name = var;
614 if (nb_path>1){
615 last_name = paths[nb_path-1];
616 paths.resize(nb_path-1);
617 parent_group.openIfExists(loc_id,paths);
618 }
619 else{
620 parent_group.open(loc_id,".");
621 }
622 if (parent_group.isBad())
623 return;
624 if (parent_group.hasChildren(last_name))
625 open(loc_id.id(),var.localstr());
626}
627
628/*---------------------------------------------------------------------------*/
629/*---------------------------------------------------------------------------*/
630
631/*---------------------------------------------------------------------------*/
632/*---------------------------------------------------------------------------*/
633
634void HProperty::
635create(hid_t cls_id)
636{
637 close();
638 _setId(H5Pcreate(cls_id));
639}
640
641/*---------------------------------------------------------------------------*/
642/*---------------------------------------------------------------------------*/
643
646{
647#ifdef H5_HAVE_PARALLEL
648 void* arcane_comm = pm->getMPICommunicator();
649 if (!arcane_comm)
650 ARCANE_FATAL("No MPI environment available");
651 MPI_Comm mpi_comm = *((MPI_Comm*)arcane_comm);
652 MPI_Info mpi_info = MPI_INFO_NULL;
653
654 create(H5P_FILE_ACCESS);
655 H5Pset_fapl_mpio(id(), mpi_comm, mpi_info);
656#else
657 ARCANE_UNUSED(pm);
658 ARCANE_THROW(NotSupportedException,"HDF5 is not compiled with MPI support");
659#endif
660}
661
662/*---------------------------------------------------------------------------*/
663/*---------------------------------------------------------------------------*/
664
667{
668#ifdef H5_HAVE_PARALLEL
669 create(H5P_DATASET_XFER);
670 H5Pset_dxpl_mpio(id(), H5FD_MPIO_COLLECTIVE);
671#else
672 ARCANE_THROW(NotSupportedException,"HDF5 is not compiled with MPI support");
673#endif
674}
675
676/*---------------------------------------------------------------------------*/
677/*---------------------------------------------------------------------------*/
678
679/*---------------------------------------------------------------------------*/
680/*---------------------------------------------------------------------------*/
681
687
688/*---------------------------------------------------------------------------*/
689/*---------------------------------------------------------------------------*/
690
692StandardTypes(bool do_init)
693{
694 if (do_init)
695 initialize();
696}
697
698/*---------------------------------------------------------------------------*/
699/*---------------------------------------------------------------------------*/
700
703{
704 {
705 hid_t type_id = H5Tcopy(H5T_NATIVE_CHAR);
706 m_char_id.setId(type_id);
707 }
708 {
709 hid_t type_id = H5Tcopy(H5T_NATIVE_UCHAR);
710 m_uchar_id.setId(type_id);
711 }
712 {
713 hid_t type_id = H5Tcopy(H5T_NATIVE_SCHAR);
714 m_schar_id.setId(type_id);
715 }
716 {
717 hid_t type_id = H5Tcopy(H5T_NATIVE_SHORT);
718 H5Tset_precision(type_id,8*sizeof(short));
719 H5Tset_order(type_id,H5T_ORDER_LE);
720 m_short_id.setId(type_id);
721 }
722 {
723 hid_t type_id = H5Tcopy(H5T_NATIVE_INT);
724 H5Tset_precision(type_id,8*sizeof(int));
725 H5Tset_order(type_id,H5T_ORDER_LE);
726 m_int_id.setId(type_id);
727 }
728 {
729 hid_t type_id = H5Tcopy(H5T_NATIVE_LONG);
730 H5Tset_precision(type_id,8*sizeof(long));
731 H5Tset_order(type_id,H5T_ORDER_LE);
732 m_long_id.setId(type_id);
733 }
734 {
735 hid_t type_id = H5Tcopy(H5T_NATIVE_USHORT);
736 H5Tset_precision(type_id,8*sizeof(unsigned short));
737 H5Tset_order(type_id,H5T_ORDER_LE);
738 m_ushort_id.setId(type_id);
739 }
740 {
741 hid_t type_id = H5Tcopy(H5T_NATIVE_UINT);
742 H5Tset_precision(type_id,8*sizeof(unsigned int));
743 H5Tset_order(type_id,H5T_ORDER_LE);
744 m_uint_id.setId(type_id);
745 }
746 {
747 hid_t type_id = H5Tcopy(H5T_NATIVE_ULONG);
748 H5Tset_precision(type_id,8*sizeof(unsigned long));
749 H5Tset_order(type_id,H5T_ORDER_LE);
750 m_ulong_id.setId(type_id);
751 }
752 {
753 hid_t type_id = H5Tcopy(H5T_NATIVE_FLOAT);
754 H5Tset_precision(type_id,8*sizeof(float));
755 H5Tset_order(type_id,H5T_ORDER_LE);
756 m_float32_id.setId(type_id);
757 }
758 {
759 hid_t type_id = H5Tcopy(H5T_NATIVE_DOUBLE);
760 H5Tset_precision(type_id,8*sizeof(double));
761 H5Tset_order(type_id,H5T_ORDER_LE);
762 m_real_id.setId(type_id);
763 }
764 {
765 hid_t type_id = H5Tcreate(H5T_COMPOUND,sizeof(Real2POD));
766 _H5Tinsert(type_id,"X",HOFFSET(Real2POD,x),H5T_NATIVE_DOUBLE);
767 _H5Tinsert(type_id,"Y",HOFFSET(Real2POD,y),H5T_NATIVE_DOUBLE);
768 m_real2_id.setId(type_id);
769 }
770 {
771 hid_t type_id = H5Tcreate(H5T_COMPOUND,sizeof(Real3POD));
772 _H5Tinsert(type_id,"X",HOFFSET(Real3POD,x),H5T_NATIVE_DOUBLE);
773 _H5Tinsert(type_id,"Y",HOFFSET(Real3POD,y),H5T_NATIVE_DOUBLE);
774 _H5Tinsert(type_id,"Z",HOFFSET(Real3POD,z),H5T_NATIVE_DOUBLE);
775 m_real3_id.setId(type_id);
776 }
777 {
778 hid_t type_id = H5Tcreate(H5T_COMPOUND,sizeof(Real2x2POD));
779 _H5Tinsert(type_id,"XX",HOFFSET(Real2x2POD,x.x),H5T_NATIVE_DOUBLE);
780 _H5Tinsert(type_id,"XY",HOFFSET(Real2x2POD,x.y),H5T_NATIVE_DOUBLE);
781 _H5Tinsert(type_id,"YX",HOFFSET(Real2x2POD,y.x),H5T_NATIVE_DOUBLE);
782 _H5Tinsert(type_id,"YY",HOFFSET(Real2x2POD,y.y),H5T_NATIVE_DOUBLE);
783 m_real2x2_id.setId(type_id);
784 }
785 {
786 hid_t type_id = H5Tcreate(H5T_COMPOUND,sizeof(Real3x3POD));
787 _H5Tinsert(type_id,"XX",HOFFSET(Real3x3POD,x.x),H5T_NATIVE_DOUBLE);
788 _H5Tinsert(type_id,"XY",HOFFSET(Real3x3POD,x.y),H5T_NATIVE_DOUBLE);
789 _H5Tinsert(type_id,"XZ",HOFFSET(Real3x3POD,x.z),H5T_NATIVE_DOUBLE);
790 _H5Tinsert(type_id,"YX",HOFFSET(Real3x3POD,y.x),H5T_NATIVE_DOUBLE);
791 _H5Tinsert(type_id,"YY",HOFFSET(Real3x3POD,y.y),H5T_NATIVE_DOUBLE);
792 _H5Tinsert(type_id,"YZ",HOFFSET(Real3x3POD,y.z),H5T_NATIVE_DOUBLE);
793 _H5Tinsert(type_id,"ZX",HOFFSET(Real3x3POD,z.x),H5T_NATIVE_DOUBLE);
794 _H5Tinsert(type_id,"ZY",HOFFSET(Real3x3POD,z.y),H5T_NATIVE_DOUBLE);
795 _H5Tinsert(type_id,"ZZ",HOFFSET(Real3x3POD,z.z),H5T_NATIVE_DOUBLE);
796 m_real3x3_id.setId(type_id);
797 }
798
799 // HDF5 1.10 et 1.12 ne supportent pas encore les types 'BFloat16' et 'Float16'.
800 // Lorsque ce sera le cas, on pourra utiliser le type fourni par HDF5.
801 // (NOTE: HDF5 1.14.4 supporte Float16)
802
803 // Ajoute type opaque pour BFloat16.
804 {
805 hid_t type_id = H5Tcopy(H5T_NATIVE_B16);
806 m_bfloat16_id.setId(type_id);
807 }
808 // Ajoute type opaque pour Float16.
809 {
810 hid_t type_id = H5Tcopy(H5T_NATIVE_B16);
811 m_float16_id.setId(type_id);
812 }
813
814 }
815
816/*---------------------------------------------------------------------------*/
817/*---------------------------------------------------------------------------*/
818
819StandardTypes::
820~StandardTypes()
821{
822}
823
824
825/*---------------------------------------------------------------------------*/
826/*---------------------------------------------------------------------------*/
827
828void StandardTypes::
829_H5Tinsert(hid_t type,const char* name,Integer offset,hid_t field_id)
830{
831 herr_t herr = H5Tinsert(type,name,offset,field_id);
832 if (herr<0){
833 ARCANE_FATAL("Can not insert type");
834 }
835}
836
837/*---------------------------------------------------------------------------*/
838/*---------------------------------------------------------------------------*/
839
840#ifdef ARCANE_REAL_NOT_BUILTIN
841hid_t StandardTypes::
842nativeType(Real) const
843{
844 ARCANE_FATAL("Real is a complex type");
845}
846#endif
847
848hid_t StandardTypes::
849saveType(eDataType sd) const
850{
851 switch(sd){
852 case DT_Byte: return saveType(Byte());
853 case DT_Real: return saveType(Real());
854 case DT_Real2: return saveType(Real2());
855 case DT_Real2x2: return saveType(Real2x2());
856 case DT_Real3: return saveType(Real3());
857 case DT_Real3x3: return saveType(Real3x3());
858 case DT_Int8: return saveType(Int8());
859 case DT_Int16: return saveType(Int16());
860 case DT_Int32: return saveType(Int32());
861 case DT_Int64: return saveType(Int64());
862 case DT_Float32: return saveType(Float32());
863 case DT_Float16: return saveType(Float16());
864 case DT_BFloat16: return saveType(BFloat16());
865 default:
866 throw ArgumentException(String::format("Bad type '{0}'",sd));
867 }
868}
869
870/*---------------------------------------------------------------------------*/
871/*---------------------------------------------------------------------------*/
872
873hid_t StandardTypes::
874nativeType(eDataType sd) const
875{
876 switch(sd){
877 case DT_Byte: return nativeType(Byte());
878 case DT_Real: return nativeType(Real());
879 case DT_Real2: return nativeType(Real2());
880 case DT_Real2x2: return nativeType(Real2x2());
881 case DT_Real3: return nativeType(Real3());
882 case DT_Real3x3: return nativeType(Real3x3());
883 case DT_Int8: return nativeType(Int8());
884 case DT_Int16: return nativeType(Int16());
885 case DT_Int32: return nativeType(Int32());
886 case DT_Int64: return nativeType(Int64());
887 case DT_Float32: return nativeType(Float32());
888 case DT_Float16: return nativeType(Float16());
889 case DT_BFloat16: return nativeType(BFloat16());
890 default:
891 throw ArgumentException(String::format("Bad type '{0}'",sd));
892 }
893}
894
895/*---------------------------------------------------------------------------*/
896/*---------------------------------------------------------------------------*/
897
898/*---------------------------------------------------------------------------*/
899/*---------------------------------------------------------------------------*/
900
901StandardArray::
902StandardArray(hid_t hfile,const String& hpath)
903: m_hfile(hfile)
904, m_hpath(hpath)
905, m_ids_hpath(hpath + "_Ids")
906, m_is_init(false)
907{
908}
909
910/*---------------------------------------------------------------------------*/
911/*---------------------------------------------------------------------------*/
912
913void StandardArray::
914readDim()
915{
916 if (m_is_init)
917 return;
918 m_is_init = true;
919 m_hdataset.open(m_hfile,m_hpath);
920 HSpace hspace(m_hdataset.getSpace());
921 {
922 const int max_dim = 256; // Nombre maxi de dimensions des tableaux HDF
923 hsize_t hdf_dims[max_dim];
924 hsize_t max_dims[max_dim];
925 int nb_dim = H5Sget_simple_extent_ndims(hspace.id());
926 H5Sget_simple_extent_dims(hspace.id(),hdf_dims,max_dims);
927 for( Integer i=0; i<nb_dim; ++i ){
928 //cerr << "** DIM i=" << i << " hdim=" << hdf_dims[i]
929 // << " max=" << max_dims[i] << '\n';
930 m_dimensions.add((Int64)hdf_dims[i]);
931 }
932 }
933 // Vérifie s'il existe une variable suffixée '_Ids' contenant les numéros
934 // uniques des entités
935 m_ids_dataset.openIfExists(m_hfile,m_ids_hpath);
936 //cout << "TRY OPEN ID DATASET path=" << m_ids_hpath << " r=" << m_ids_dataset.id()>0 << '\n';
937}
938
939/*---------------------------------------------------------------------------*/
940/*---------------------------------------------------------------------------*/
941
943setIdsPath(const String& ids_path)
944{
945 m_ids_hpath = ids_path;
946}
947
948/*---------------------------------------------------------------------------*/
949/*---------------------------------------------------------------------------*/
950
951void StandardArray::
952_write(const void* buffer,Integer nb_element,hid_t save_type,hid_t native_type)
953{
954 if (!m_is_init){
955 hsize_t dims[1];
956 dims[0] = nb_element;
957
958 HSpace hspace;
959 hspace.createSimple(1,dims);
960 if (hspace.isBad())
961 ARCANE_THROW(IOException,"Can not create space");
962
963 m_dimensions.clear();
964 m_dimensions.add(nb_element);
965
966 m_hdataset.recursiveCreate(m_hfile,m_hpath,save_type,hspace,H5P_DEFAULT);
967 if (m_hdataset.isBad())
968 ARCANE_THROW(IOException,"Can not create dataset");
969
970 m_is_init = true;
971 }
972
973 m_hdataset.write(native_type,buffer);
974}
975
976/*---------------------------------------------------------------------------*/
977/*---------------------------------------------------------------------------*/
978
979bool StandardArray::
980exists() const
981{
982 HDataset dataset;
983 dataset.openIfExists(m_hfile,m_hpath);
984 return dataset.id()>0;
985}
986
987/*---------------------------------------------------------------------------*/
988/*---------------------------------------------------------------------------*/
989
990template<typename DataType> StandardArrayT<DataType>::
991StandardArrayT(hid_t hfile,const String& hpath)
992: StandardArray(hfile,hpath)
993{
994}
995
996/*---------------------------------------------------------------------------*/
997/*---------------------------------------------------------------------------*/
998
999template<typename DataType> void StandardArrayT<DataType>::
1001{
1002 m_hdataset.readWithException(st.nativeType(DataType()),buffer.data());
1003}
1004
1005/*---------------------------------------------------------------------------*/
1006/*---------------------------------------------------------------------------*/
1007
1008template<typename DataType> void StandardArrayT<DataType>::
1010{
1011 readDim();
1012 buffer.resize(m_dimensions[0]);
1013 read(st,buffer);
1014}
1015
1016/*---------------------------------------------------------------------------*/
1017/*---------------------------------------------------------------------------*/
1018
1019template<typename DataType> void StandardArrayT<DataType>::
1021{
1022 bool is_master = pm->isMasterIO();
1023 Integer master_rank = pm->masterIORank();
1024 bool has_ids = false;
1025 if (is_master){
1026 read(st,buffer);
1027 Integer buf_size = buffer.size();
1028 if (m_ids_dataset.id()>0){
1029 has_ids = true;
1030 m_ids_dataset.read(st.nativeType(Int64()),unique_ids.data());
1031 }
1032 Integer infos[2];
1033 infos[0] = buf_size;
1034 infos[1] = has_ids ? 1 : 0;
1035 IntegerArrayView iav(2,infos);
1036 pm->broadcast(iav,master_rank);
1037 pm->broadcast(buffer,master_rank);
1038 pm->broadcast(unique_ids,master_rank);
1039 }
1040 else{
1041 Integer infos[2];
1042 IntegerArrayView iav(2,infos);
1043 pm->broadcast(iav,master_rank);
1044 Integer buf_size = infos[0];
1045 has_ids = infos[1]!=0;
1046 buffer.resize(buf_size);
1047 unique_ids.resize(buf_size);
1048 pm->broadcast(buffer,master_rank);
1049 pm->broadcast(unique_ids,master_rank);
1050 }
1051 if (!has_ids){
1052 for( Integer i=0, is=unique_ids.size(); i<is; ++i )
1053 unique_ids[i] = i;
1054 }
1055}
1056
1057/*---------------------------------------------------------------------------*/
1058/*---------------------------------------------------------------------------*/
1059
1060template<typename DataType> void StandardArrayT<DataType>::
1061write(StandardTypes& st,ConstArrayView<DataType> buffer)
1062{
1063 Integer nb_element = buffer.size();
1064 _write(buffer.data(),nb_element,st.saveType(DataType()),st.nativeType(DataType()));
1065}
1066
1067/*---------------------------------------------------------------------------*/
1068/*---------------------------------------------------------------------------*/
1069
1070template<typename DataType> void StandardArrayT<DataType>::
1071_writeSortedValues(ITraceMng* tm,StandardTypes& st,
1072 ConstArrayView<DataType> buffer,
1073 Int64ConstArrayView unique_ids)
1074{
1075 ARCANE_UNUSED(tm);
1076
1077 Integer total_size = buffer.size();
1078 Integer nb_element = unique_ids.size();
1079 Integer dim2_size = 1;
1080 if (nb_element != total_size){
1081 if (nb_element == 0)
1082 ARCANE_THROW(ArgumentException,"unique_ids size is zero but not buffer size ({0})",
1083 total_size);
1084 dim2_size = total_size / nb_element;
1085 if (dim2_size*nb_element != total_size)
1086 ARCANE_THROW(ArgumentException,"buffer size ({0}) is not a multiple of unique_ids size ({1})",
1087 total_size,nb_element);
1088 }
1089
1090 UniqueArray<ValueWithUid> values_to_sort(nb_element);
1091 UniqueArray<DataType> out_buffer(total_size);
1092 //tm->info() << " WRITE total_size=" << total_size
1093 //<< " uid_size=" << unique_ids.size();
1094 for( Integer i=0; i<nb_element; ++i ){
1095 values_to_sort[i].m_uid = unique_ids[i];
1096 values_to_sort[i].m_index = i;
1097 //values_to_sort[i].m_value = buffer[i];
1098 //tm->info() << "BEFORE SORT i=" << i << " uid=" << unique_ids[i];
1099 }
1100 std::sort(std::begin(values_to_sort),std::end(values_to_sort));
1101 for( Integer i=0; i<nb_element; ++i ){
1102 Integer old_index = values_to_sort[i].m_index;
1103 for( Integer j=0; j<dim2_size; ++j ){
1104 Integer pos = (i*dim2_size)+j;
1105 out_buffer[pos] = buffer[(old_index*dim2_size)+j];
1106 //tm->info() << "AFTER SORT i=" << i << " uid=" << values_to_sort[i].m_uid
1107 // << " j=" << j << " pos=" << pos
1108 // << " value=" << out_buffer[pos];
1109 }
1110 }
1111 write(st,out_buffer);
1112}
1113
1114/*---------------------------------------------------------------------------*/
1115/*---------------------------------------------------------------------------*/
1116
1117template<typename DataType> void StandardArrayT<DataType>::
1118parallelWrite(IParallelMng* pm,StandardTypes& st,
1119 ConstArrayView<DataType> buffer,Int64ConstArrayView unique_ids)
1120{
1121 //TODO:
1122 // Pour l'instant, seul le proc maitre ecrit.
1123 // Il recupère toutes les valeurs, les trie par uniqueId croissant
1124 // et les écrit.
1125 // Il est important que tout soit trié par ordre croissant car
1126 // cela permet de garder le même ordre d'écriture même en présence
1127 // de repartitionnement du maillage. La relecture considère
1128 // que cette contrainte est respectée et ne relit les informations
1129 // des uniqueId qu'au démarrage du cas.
1130 bool is_parallel = pm->isParallel();
1131 ITraceMng* tm = pm->traceMng();
1132
1133 if (!is_parallel){
1134 _writeSortedValues(tm,st,buffer,unique_ids);
1135 return;
1136 }
1137
1138 bool is_master = pm->isMasterIO();
1139 Integer master_rank = pm->masterIORank();
1140 Integer nb_rank = pm->commSize();
1141 Integer buf_size = buffer.size();
1142 Integer unique_id_size = unique_ids.size();
1143 IntegerUniqueArray rank_sizes(2*nb_rank);
1144 // Le sous-domaine maitre récupère les infos de tous les autres.
1145 // Si un sous-domaine n'a pas d'éléments à envoyer, il ne fait rien
1146 // (on n'envoie pas de buffers vides)
1147 if (is_master){
1148 Integer buf[2];
1149 buf[0] = buf_size;
1150 buf[1] = unique_id_size;
1151 IntegerArrayView iav(2,buf);
1152 pm->allGather(iav,rank_sizes);
1153
1154 Integer buffer_total_size = 0;
1155 Integer unique_id_total_size = 0;
1156 IntegerUniqueArray buffer_rank_index(nb_rank);
1157 IntegerUniqueArray unique_id_rank_index(nb_rank);
1158
1159 for( Integer i=0; i<nb_rank; ++i ){
1160 buffer_rank_index[i] = buffer_total_size;
1161 buffer_total_size += rank_sizes[(i*2)];
1162 unique_id_rank_index[i] = unique_id_total_size;
1163 unique_id_total_size += rank_sizes[(i*2)+1];
1164 }
1165
1166 UniqueArray<DataType> full_buffer(buffer_total_size);
1167 Int64UniqueArray full_unique_ids(unique_id_total_size);
1168
1169 for( Integer i=0; i<nb_rank; ++i ){
1170 // Ne recoit pas de valeurs des processus n'ayant pas de valeurs
1171 if (rank_sizes[(i*2)]==0)
1172 continue;
1173 ArrayView<DataType> local_buf(rank_sizes[(i*2)],&full_buffer[ buffer_rank_index[i] ]);
1174 Int64ArrayView local_unique_ids(rank_sizes[(i*2)+1],&full_unique_ids[ unique_id_rank_index[i] ]);
1175 if (i==master_rank){
1176 local_buf.copy(buffer);
1177 local_unique_ids.copy(unique_ids);
1178 }
1179 else{
1180 pm->recv(local_buf,i);
1181 pm->recv(local_unique_ids,i);
1182 }
1183 }
1184 tm->info(5) << "PARALLEL WRITE path=" << m_hpath << " total_size=" << full_buffer.size();
1185 _writeSortedValues(tm,st,full_buffer,full_unique_ids);
1186 }
1187 else{
1188 Integer buf[2];
1189 buf[0] = buf_size;
1190 buf[1] = unique_id_size;
1191 IntegerArrayView iav(2,buf);
1192 pm->allGather(iav,rank_sizes);
1193 // Pas la peine d'envoyer des buffers vides
1194 if (buffer.size()>0){
1195 pm->send(buffer,master_rank);
1196 pm->send(unique_ids,master_rank);
1197 }
1198 }
1199}
1200
1201/*---------------------------------------------------------------------------*/
1202/*---------------------------------------------------------------------------*/
1203
1204template class StandardArrayT<Real>;
1205template class StandardArrayT<Real3>;
1206template class StandardArrayT<Real3x3>;
1207template class StandardArrayT<Real2>;
1208template class StandardArrayT<Real2x2>;
1209template class StandardArrayT<Int16>;
1210template class StandardArrayT<Int32>;
1211template class StandardArrayT<Int64>;
1212template class StandardArrayT<Byte>;
1213template class StandardArrayT<Int8>;
1214template class StandardArrayT<Float32>;
1215// NOTE: on ne peut pas encore instantier ces types car ils nécessitent
1216// de pouvoir faire des send/receive via le IParallelMng et cela n'est pas
1217// encore implémenté.
1218//template class StandardArrayT<Float16>;
1219//template class StandardArrayT<BFloat16>;
1220
1221/*---------------------------------------------------------------------------*/
1222/*---------------------------------------------------------------------------*/
1223
1224template<typename DataType> DataType
1227{
1228 Hdf5Utils::HDataset m_hdataset;
1229 m_hdataset.open(m_hfile,m_hpath);
1230 Hdf5Utils::HSpace hspace(m_hdataset.getSpace());
1231 {
1232 const int max_dim = 256; // Nombre maxi de dimensions des tableaux HDF
1233 hsize_t hdf_dims[max_dim];
1234 hsize_t max_dims[max_dim];
1235 int nb_dim = H5Sget_simple_extent_ndims(hspace.id());
1236 H5Sget_simple_extent_dims(hspace.id(),hdf_dims,max_dims);
1237
1238 if (nb_dim!=1 || hdf_dims[0]!=1)
1239 ARCANE_THROW(IOException,"Cannot read non scalar");
1240 }
1241
1242 DataType dummy;
1243 m_hdataset.read(st.nativeType(DataType()),&dummy);
1244 return dummy;
1245}
1246
1247/*---------------------------------------------------------------------------*/
1248
1249template<> String
1252{
1253 ByteUniqueArray utf8_bytes;
1254
1255
1256 Hdf5Utils::HDataset m_hdataset;
1257 m_hdataset.open(m_hfile,m_hpath);
1258 Hdf5Utils::HSpace hspace(m_hdataset.getSpace());
1259 {
1260 const int max_dim = 256; // Nombre maxi de dimensions des tableaux HDF
1261 hsize_t hdf_dims[max_dim];
1262 hsize_t max_dims[max_dim];
1263 int nb_dim = H5Sget_simple_extent_ndims(hspace.id());
1264 H5Sget_simple_extent_dims(hspace.id(),hdf_dims,max_dims);
1265
1266 if (nb_dim != 1)
1267 ARCANE_THROW(IOException,"Cannot read multidim string");
1268 utf8_bytes.resize(hdf_dims[0]);
1269 }
1270
1271 m_hdataset.read(st.nativeType(Byte()),utf8_bytes.data());
1272 return String(utf8_bytes);
1273}
1274
1275/*---------------------------------------------------------------------------*/
1276
1277template<typename DataType> void
1279write(Hdf5Utils::StandardTypes & st, const DataType & t)
1280{
1281 hsize_t dims[1] = { 1 };
1282 Hdf5Utils::HSpace hspace;
1283 hspace.createSimple(1,dims);
1284 if (hspace.isBad())
1285 ARCANE_THROW(IOException,"Can not create space");
1286
1287 Hdf5Utils::HDataset m_hdataset;
1288 m_hdataset.recursiveCreate(m_hfile,m_hpath,st.saveType(DataType()),hspace,H5P_DEFAULT);
1289 if (m_hdataset.isBad())
1290 ARCANE_THROW(IOException,"Can not create dataset");
1291
1292 herr_t herr = m_hdataset.write(st.nativeType(DataType()),&t);
1293 if (herr<0)
1294 ARCANE_THROW(IOException,"Cannot write data");
1295}
1296
1297/*---------------------------------------------------------------------------*/
1298
1299template<> void
1301write(Hdf5Utils::StandardTypes & st, const String & s)
1302{
1303 ByteConstArrayView utf8_bytes = s.utf8();
1304
1305 hsize_t dims[1];
1306 dims[0] = utf8_bytes.size() + 1;
1307
1308 Hdf5Utils::HSpace hspace;
1309 hspace.createSimple(1,dims);
1310 if (hspace.isBad())
1311 ARCANE_THROW(IOException,"Can not create space");
1312
1313 Hdf5Utils::HDataset m_hdataset;
1314 m_hdataset.recursiveCreate(m_hfile,m_hpath,st.saveType(Byte()),hspace,H5P_DEFAULT);
1315 if (m_hdataset.isBad())
1316 ARCANE_THROW(IOException,"Can not create dataset");
1317
1318 herr_t herr = m_hdataset.write(st.nativeType(Byte()),utf8_bytes.data());
1319 if (herr<0)
1320 ARCANE_THROW(IOException,"Cannot write data");
1321}
1322
1323/*---------------------------------------------------------------------------*/
1324
1325template class StandardScalarT<String>;
1326template class StandardScalarT<Real>;
1327template class StandardScalarT<Real3>;
1328template class StandardScalarT<Real3x3>;
1329template class StandardScalarT<Real2>;
1330template class StandardScalarT<Real2x2>;
1331template class StandardScalarT<Int16>;
1332template class StandardScalarT<Int32>;
1333template class StandardScalarT<Int64>;
1334template class StandardScalarT<Byte>;
1335template class StandardScalarT<Int8>;
1336template class StandardScalarT<Float16>;
1337template class StandardScalarT<BFloat16>;
1338template class StandardScalarT<Float32>;
1339
1340/*---------------------------------------------------------------------------*/
1341/*---------------------------------------------------------------------------*/
1342
1343} // namespace Arcane::Hdf5Utils
1344
1345/*---------------------------------------------------------------------------*/
1346/*---------------------------------------------------------------------------*/
#define ARCANE_THROW(exception_class,...)
Macro pour envoyer une exception avec formattage.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Encapsule un hid_t pour un dataset.
Definition Hdf5Utils.h:380
static bool hasParallelHdf5()
Vrai HDF5 est compilé avec le support de MPI.
Definition Hdf5Utils.cc:61
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 dataset simple d'un fichier HDF5 qui représente un tableau.
Definition Hdf5Utils.h:788
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
Encapsule un dataset simple d'un fichier HDF5 qui représente un scalaire (éventuellement String).
Definition Hdf5Utils.h:834
DataType read(Hdf5Utils::StandardTypes &st)
Lit une donnée.
void write(Hdf5Utils::StandardTypes &st, const DataType &t)
Ecrit une donnée.
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
Exception lorsqu'une erreur d'entrée/sortie est détectée.
Definition IOException.h:32
Interface du gestionnaire de parallélisme pour un sous-domaine.
virtual bool isMasterIO() const =0
true si l'instance est un gestionnaire maître des entrées/sorties.
virtual Integer masterIORank() const =0
Rang de l'instance gérant les entrées/sorties (pour laquelle isMasterIO() est vrai)
virtual void * getMPICommunicator()=0
Adresse du communicateur MPI associé à ce gestionnaire.
Integer size() const
Nombre d'éléments du vecteur.
Vue modifiable d'un tableau d'un type T.
constexpr const_pointer data() const noexcept
Pointeur sur le début de la vue.
Classe de base des vecteurs 1D de données.
const T * data() const
Accès à la racine du tableau hors toute protection.
void resize(Int64 s)
Change le nombre d'éléments du tableau à s.
void add(ConstReferenceType val)
Ajoute l'élément val à la fin du tableau.
void clear()
Supprime les éléments du tableau.
Vue constante d'un tableau de type T.
constexpr Integer size() const noexcept
Nombre d'éléments du tableau.
constexpr const_pointer data() const noexcept
Pointeur sur la mémoire allouée.
Chaîne de caractères unicode.
ByteConstArrayView utf8() const
Retourne la conversion de l'instance dans l'encodage UTF-8.
Definition String.cc:275
Vecteur 1D de données avec sémantique par valeur (style STL).
Integer len(const char *s)
Retourne la longueur de la chaîne s.
Fonctions utilitaires pour Hdf5.
Definition Hdf5Utils.cc:36
UniqueArray< Int64 > Int64UniqueArray
Tableau dynamique à une dimension d'entiers 64 bits.
Definition UtilsTypes.h:550
ArrayView< Integer > IntegerArrayView
Equivalent C d'un tableau à une dimension d'entiers.
Definition UtilsTypes.h:668
Arccore::Float16 Float16
Type 'Float16' (binary16)
Arccore::Int8 Int8
Type représentant un entier sur 8 bits.
Arccore::BFloat16 BFloat16
Type 'Brain Float16'.
ArrayView< Int64 > Int64ArrayView
Equivalent C d'un tableau à une dimension d'entiers 64 bits.
Definition UtilsTypes.h:662
float Float32
Type flottant IEEE-753 simple précision (binary32)
unsigned char Byte
Type d'un octet.
Definition UtilsTypes.h:148
eDataType
Type d'une donnée.
Definition DataTypes.h:39
@ DT_Float32
Donnée de type 'Float32'.
Definition DataTypes.h:52
@ DT_Real2x2
Donnée de type tenseur 3x3.
Definition DataTypes.h:48
@ DT_Int16
Donnée de type entier 16 bits.
Definition DataTypes.h:42
@ DT_Int8
Donnée de type entier sur 8 bits.
Definition DataTypes.h:53
@ DT_Real3x3
Donnée de type tenseur 3x3.
Definition DataTypes.h:49
@ DT_Int32
Donnée de type entier 32 bits.
Definition DataTypes.h:43
@ DT_Real3
Donnée de type vecteur 3.
Definition DataTypes.h:47
@ DT_Float16
Donnée de type 'Float16'.
Definition DataTypes.h:51
@ DT_Int64
Donnée de type entier 64 bits.
Definition DataTypes.h:44
@ DT_BFloat16
Donnée de type 'BFloat16'.
Definition DataTypes.h:50
@ DT_Real2
Donnée de type vecteur 2.
Definition DataTypes.h:46
@ DT_Real
Donnée de type réel.
Definition DataTypes.h:41
@ DT_Byte
Donnée de type octet.
Definition DataTypes.h:40
ConstArrayView< Int64 > Int64ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 64 bits.
Definition UtilsTypes.h:691
UniqueArray< Integer > IntegerUniqueArray
Tableau dynamique à une dimension d'entiers.
Definition UtilsTypes.h:558
double Real
Type représentant un réel.
Int32 Integer
Type représentant un entier.
Structure POD pour un Real2x2.
Definition Real2x2.h:31
Structure POD pour un Real3x3.
Definition Real3x3.h:31