Arcane  v3.14.10.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-2023 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-2023 */
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 //H5Tset_precision(m_int_id,8*1);
708 }
709 {
710 hid_t type_id = H5Tcopy(H5T_NATIVE_UCHAR);
711 m_uchar_id.setId(type_id);
712 //H5Tset_precision(m_int_id,8*1);
713 }
714 {
715 hid_t type_id = H5Tcopy(H5T_NATIVE_SHORT);
716 H5Tset_precision(type_id,8*sizeof(short));
717 H5Tset_order(type_id,H5T_ORDER_LE);
718 m_short_id.setId(type_id);
719 }
720 {
721 hid_t type_id = H5Tcopy(H5T_NATIVE_INT);
722 H5Tset_precision(type_id,8*sizeof(int));
723 H5Tset_order(type_id,H5T_ORDER_LE);
724 m_int_id.setId(type_id);
725 }
726 {
727 hid_t type_id = H5Tcopy(H5T_NATIVE_LONG);
728 H5Tset_precision(type_id,8*sizeof(long));
729 H5Tset_order(type_id,H5T_ORDER_LE);
730 m_long_id.setId(type_id);
731 }
732 {
733 hid_t type_id = H5Tcopy(H5T_NATIVE_USHORT);
734 H5Tset_precision(type_id,8*sizeof(unsigned short));
735 H5Tset_order(type_id,H5T_ORDER_LE);
736 m_ushort_id.setId(type_id);
737 }
738 {
739 hid_t type_id = H5Tcopy(H5T_NATIVE_UINT);
740 H5Tset_precision(type_id,8*sizeof(unsigned int));
741 H5Tset_order(type_id,H5T_ORDER_LE);
742 m_uint_id.setId(type_id);
743 }
744 {
745 hid_t type_id = H5Tcopy(H5T_NATIVE_ULONG);
746 H5Tset_precision(type_id,8*sizeof(unsigned long));
747 H5Tset_order(type_id,H5T_ORDER_LE);
748 m_ulong_id.setId(type_id);
749 }
750 {
751 hid_t type_id = H5Tcopy(H5T_NATIVE_DOUBLE);
752 H5Tset_precision(type_id,8*sizeof(double));
753 H5Tset_order(type_id,H5T_ORDER_LE);
754 m_real_id.setId(type_id);
755 }
756 {
757 hid_t type_id = H5Tcreate(H5T_COMPOUND,sizeof(Real2POD));
758 _H5Tinsert(type_id,"X",HOFFSET(Real2POD,x),H5T_NATIVE_DOUBLE);
759 _H5Tinsert(type_id,"Y",HOFFSET(Real2POD,y),H5T_NATIVE_DOUBLE);
760 m_real2_id.setId(type_id);
761 }
762 {
763 hid_t type_id = H5Tcreate(H5T_COMPOUND,sizeof(Real3POD));
764 _H5Tinsert(type_id,"X",HOFFSET(Real3POD,x),H5T_NATIVE_DOUBLE);
765 _H5Tinsert(type_id,"Y",HOFFSET(Real3POD,y),H5T_NATIVE_DOUBLE);
766 _H5Tinsert(type_id,"Z",HOFFSET(Real3POD,z),H5T_NATIVE_DOUBLE);
767 m_real3_id.setId(type_id);
768 }
769 {
770 hid_t type_id = H5Tcreate(H5T_COMPOUND,sizeof(Real2x2POD));
771 _H5Tinsert(type_id,"XX",HOFFSET(Real2x2POD,x.x),H5T_NATIVE_DOUBLE);
772 _H5Tinsert(type_id,"XY",HOFFSET(Real2x2POD,x.y),H5T_NATIVE_DOUBLE);
773 _H5Tinsert(type_id,"YX",HOFFSET(Real2x2POD,y.x),H5T_NATIVE_DOUBLE);
774 _H5Tinsert(type_id,"YY",HOFFSET(Real2x2POD,y.y),H5T_NATIVE_DOUBLE);
775 m_real2x2_id.setId(type_id);
776 }
777 {
778 hid_t type_id = H5Tcreate(H5T_COMPOUND,sizeof(Real3x3POD));
779 _H5Tinsert(type_id,"XX",HOFFSET(Real3x3POD,x.x),H5T_NATIVE_DOUBLE);
780 _H5Tinsert(type_id,"XY",HOFFSET(Real3x3POD,x.y),H5T_NATIVE_DOUBLE);
781 _H5Tinsert(type_id,"XZ",HOFFSET(Real3x3POD,x.z),H5T_NATIVE_DOUBLE);
782 _H5Tinsert(type_id,"YX",HOFFSET(Real3x3POD,y.x),H5T_NATIVE_DOUBLE);
783 _H5Tinsert(type_id,"YY",HOFFSET(Real3x3POD,y.y),H5T_NATIVE_DOUBLE);
784 _H5Tinsert(type_id,"YZ",HOFFSET(Real3x3POD,y.z),H5T_NATIVE_DOUBLE);
785 _H5Tinsert(type_id,"ZX",HOFFSET(Real3x3POD,z.x),H5T_NATIVE_DOUBLE);
786 _H5Tinsert(type_id,"ZY",HOFFSET(Real3x3POD,z.y),H5T_NATIVE_DOUBLE);
787 _H5Tinsert(type_id,"ZZ",HOFFSET(Real3x3POD,z.z),H5T_NATIVE_DOUBLE);
788 m_real3x3_id.setId(type_id);
789 }
790}
791
792/*---------------------------------------------------------------------------*/
793/*---------------------------------------------------------------------------*/
794
795StandardTypes::
796~StandardTypes()
797{
798}
799
800
801/*---------------------------------------------------------------------------*/
802/*---------------------------------------------------------------------------*/
803
804void StandardTypes::
805_H5Tinsert(hid_t type,const char* name,Integer offset,hid_t field_id)
806{
807 herr_t herr = H5Tinsert(type,name,offset,field_id);
808 if (herr<0){
809 ARCANE_FATAL("Can not insert type");
810 }
811}
812
813/*---------------------------------------------------------------------------*/
814/*---------------------------------------------------------------------------*/
815
816#ifdef ARCANE_REAL_NOT_BUILTIN
817hid_t StandardTypes::
818nativeType(Real) const
819{
820 throw FatalErrorException("Hdf5Utils::StandardTypes::nativeType(Real)","Real is a complex type");
821}
822#endif
823
824hid_t StandardTypes::
825saveType(eDataType sd) const
826{
827 switch(sd){
828 case DT_Byte: return saveType(Byte());
829 case DT_Real: return saveType(Real());
830 case DT_Real2: return saveType(Real2());
831 case DT_Real2x2: return saveType(Real2x2());
832 case DT_Real3: return saveType(Real3());
833 case DT_Real3x3: return saveType(Real3x3());
834 case DT_Int16: return saveType(Int16());
835 case DT_Int32: return saveType(Int32());
836 case DT_Int64: return saveType(Int64());
837 default:
838 throw ArgumentException("Bad type");
839 }
840}
841
842/*---------------------------------------------------------------------------*/
843/*---------------------------------------------------------------------------*/
844
845hid_t StandardTypes::
846nativeType(eDataType sd) const
847{
848 switch(sd){
849 case DT_Byte: return nativeType(Byte());
850 case DT_Real: return nativeType(Real());
851 case DT_Real2: return nativeType(Real2());
852 case DT_Real2x2: return nativeType(Real2x2());
853 case DT_Real3: return nativeType(Real3());
854 case DT_Real3x3: return nativeType(Real3x3());
855 case DT_Int16: return nativeType(Int16());
856 case DT_Int32: return nativeType(Int32());
857 case DT_Int64: return nativeType(Int64());
858 default:
859 throw ArgumentException("Bad type");
860 }
861}
862
863/*---------------------------------------------------------------------------*/
864/*---------------------------------------------------------------------------*/
865
866/*---------------------------------------------------------------------------*/
867/*---------------------------------------------------------------------------*/
868
869StandardArray::
870StandardArray(hid_t hfile,const String& hpath)
871: m_hfile(hfile)
872, m_hpath(hpath)
873, m_ids_hpath(hpath + "_Ids")
874, m_is_init(false)
875{
876}
877
878/*---------------------------------------------------------------------------*/
879/*---------------------------------------------------------------------------*/
880
881void StandardArray::
882readDim()
883{
884 if (m_is_init)
885 return;
886 m_is_init = true;
887 m_hdataset.open(m_hfile,m_hpath);
888 HSpace hspace(m_hdataset.getSpace());
889 {
890 const int max_dim = 256; // Nombre maxi de dimensions des tableaux HDF
891 hsize_t hdf_dims[max_dim];
892 hsize_t max_dims[max_dim];
893 int nb_dim = H5Sget_simple_extent_ndims(hspace.id());
894 H5Sget_simple_extent_dims(hspace.id(),hdf_dims,max_dims);
895 for( Integer i=0; i<nb_dim; ++i ){
896 //cerr << "** DIM i=" << i << " hdim=" << hdf_dims[i]
897 // << " max=" << max_dims[i] << '\n';
898 m_dimensions.add((Int64)hdf_dims[i]);
899 }
900 }
901 // Vérifie s'il existe une variable suffixée '_Ids' contenant les numéros
902 // uniques des entités
903 m_ids_dataset.openIfExists(m_hfile,m_ids_hpath);
904 //cout << "TRY OPEN ID DATASET path=" << m_ids_hpath << " r=" << m_ids_dataset.id()>0 << '\n';
905}
906
907/*---------------------------------------------------------------------------*/
908/*---------------------------------------------------------------------------*/
909
911setIdsPath(const String& ids_path)
912{
913 m_ids_hpath = ids_path;
914}
915
916/*---------------------------------------------------------------------------*/
917/*---------------------------------------------------------------------------*/
918
919void StandardArray::
920_write(const void* buffer,Integer nb_element,hid_t save_type,hid_t native_type)
921{
922 if (!m_is_init){
923 hsize_t dims[1];
924 dims[0] = nb_element;
925
926 HSpace hspace;
927 hspace.createSimple(1,dims);
928 if (hspace.isBad())
929 ARCANE_THROW(IOException,"Can not create space");
930
931 m_dimensions.clear();
932 m_dimensions.add(nb_element);
933
934 m_hdataset.recursiveCreate(m_hfile,m_hpath,save_type,hspace,H5P_DEFAULT);
935 if (m_hdataset.isBad())
936 ARCANE_THROW(IOException,"Can not create dataset");
937
938 m_is_init = true;
939 }
940
941 m_hdataset.write(native_type,buffer);
942}
943
944/*---------------------------------------------------------------------------*/
945/*---------------------------------------------------------------------------*/
946
947bool StandardArray::
948exists() const
949{
950 HDataset dataset;
951 dataset.openIfExists(m_hfile,m_hpath);
952 return dataset.id()>0;
953}
954
955/*---------------------------------------------------------------------------*/
956/*---------------------------------------------------------------------------*/
957
958template<typename DataType> StandardArrayT<DataType>::
959StandardArrayT(hid_t hfile,const String& hpath)
960: StandardArray(hfile,hpath)
961{
962}
963
964/*---------------------------------------------------------------------------*/
965/*---------------------------------------------------------------------------*/
966
967template<typename DataType> void StandardArrayT<DataType>::
969{
970 m_hdataset.readWithException(st.nativeType(DataType()),buffer.data());
971}
972
973/*---------------------------------------------------------------------------*/
974/*---------------------------------------------------------------------------*/
975
976template<typename DataType> void StandardArrayT<DataType>::
978{
979 readDim();
980 buffer.resize(m_dimensions[0]);
981 read(st,buffer);
982}
983
984/*---------------------------------------------------------------------------*/
985/*---------------------------------------------------------------------------*/
986
987template<typename DataType> void StandardArrayT<DataType>::
989{
990 bool is_master = pm->isMasterIO();
991 Integer master_rank = pm->masterIORank();
992 bool has_ids = false;
993 if (is_master){
994 read(st,buffer);
995 Integer buf_size = buffer.size();
996 if (m_ids_dataset.id()>0){
997 has_ids = true;
998 m_ids_dataset.read(st.nativeType(Int64()),unique_ids.data());
999 }
1000 Integer infos[2];
1001 infos[0] = buf_size;
1002 infos[1] = has_ids ? 1 : 0;
1003 IntegerArrayView iav(2,infos);
1004 pm->broadcast(iav,master_rank);
1005 pm->broadcast(buffer,master_rank);
1006 pm->broadcast(unique_ids,master_rank);
1007 }
1008 else{
1009 Integer infos[2];
1010 IntegerArrayView iav(2,infos);
1011 pm->broadcast(iav,master_rank);
1012 Integer buf_size = infos[0];
1013 has_ids = infos[1]!=0;
1014 buffer.resize(buf_size);
1015 unique_ids.resize(buf_size);
1016 pm->broadcast(buffer,master_rank);
1017 pm->broadcast(unique_ids,master_rank);
1018 }
1019 if (!has_ids){
1020 for( Integer i=0, is=unique_ids.size(); i<is; ++i )
1021 unique_ids[i] = i;
1022 }
1023}
1024
1025/*---------------------------------------------------------------------------*/
1026/*---------------------------------------------------------------------------*/
1027
1028template<typename DataType> void StandardArrayT<DataType>::
1029write(StandardTypes& st,ConstArrayView<DataType> buffer)
1030{
1031 Integer nb_element = buffer.size();
1032 _write(buffer.data(),nb_element,st.saveType(DataType()),st.nativeType(DataType()));
1033}
1034
1035/*---------------------------------------------------------------------------*/
1036/*---------------------------------------------------------------------------*/
1037
1038template<typename DataType> void StandardArrayT<DataType>::
1039_writeSortedValues(ITraceMng* tm,StandardTypes& st,
1040 ConstArrayView<DataType> buffer,
1041 Int64ConstArrayView unique_ids)
1042{
1043 ARCANE_UNUSED(tm);
1044
1045 Integer total_size = buffer.size();
1046 Integer nb_element = unique_ids.size();
1047 Integer dim2_size = 1;
1048 if (nb_element != total_size){
1049 if (nb_element == 0)
1050 ARCANE_THROW(ArgumentException,"unique_ids size is zero but not buffer size ({0})",
1051 total_size);
1052 dim2_size = total_size / nb_element;
1053 if (dim2_size*nb_element != total_size)
1054 ARCANE_THROW(ArgumentException,"buffer size ({0}) is not a multiple of unique_ids size ({1})",
1055 total_size,nb_element);
1056 }
1057
1058 UniqueArray<ValueWithUid> values_to_sort(nb_element);
1059 UniqueArray<DataType> out_buffer(total_size);
1060 //tm->info() << " WRITE total_size=" << total_size
1061 //<< " uid_size=" << unique_ids.size();
1062 for( Integer i=0; i<nb_element; ++i ){
1063 values_to_sort[i].m_uid = unique_ids[i];
1064 values_to_sort[i].m_index = i;
1065 //values_to_sort[i].m_value = buffer[i];
1066 //tm->info() << "BEFORE SORT i=" << i << " uid=" << unique_ids[i];
1067 }
1068 std::sort(std::begin(values_to_sort),std::end(values_to_sort));
1069 for( Integer i=0; i<nb_element; ++i ){
1070 Integer old_index = values_to_sort[i].m_index;
1071 for( Integer j=0; j<dim2_size; ++j ){
1072 Integer pos = (i*dim2_size)+j;
1073 out_buffer[pos] = buffer[(old_index*dim2_size)+j];
1074 //tm->info() << "AFTER SORT i=" << i << " uid=" << values_to_sort[i].m_uid
1075 // << " j=" << j << " pos=" << pos
1076 // << " value=" << out_buffer[pos];
1077 }
1078 }
1079 write(st,out_buffer);
1080}
1081
1082/*---------------------------------------------------------------------------*/
1083/*---------------------------------------------------------------------------*/
1084
1085template<typename DataType> void StandardArrayT<DataType>::
1086parallelWrite(IParallelMng* pm,StandardTypes& st,
1087 ConstArrayView<DataType> buffer,Int64ConstArrayView unique_ids)
1088{
1089 //TODO:
1090 // Pour l'instant, seul le proc maitre ecrit.
1091 // Il recupère toutes les valeurs, les trie par uniqueId croissant
1092 // et les écrit.
1093 // Il est important que tout soit trié par ordre croissant car
1094 // cela permet de garder le même ordre d'écriture même en présence
1095 // de repartitionnement du maillage. La relecture considère
1096 // que cette contrainte est respectée et ne relit les informations
1097 // des uniqueId qu'au démarrage du cas.
1098 bool is_parallel = pm->isParallel();
1099 ITraceMng* tm = pm->traceMng();
1100
1101 if (!is_parallel){
1102 _writeSortedValues(tm,st,buffer,unique_ids);
1103 return;
1104 }
1105
1106 bool is_master = pm->isMasterIO();
1107 Integer master_rank = pm->masterIORank();
1108 Integer nb_rank = pm->commSize();
1109 Integer buf_size = buffer.size();
1110 Integer unique_id_size = unique_ids.size();
1111 IntegerUniqueArray rank_sizes(2*nb_rank);
1112 // Le sous-domaine maitre récupère les infos de tous les autres.
1113 // Si un sous-domaine n'a pas d'éléments à envoyer, il ne fait rien
1114 // (on n'envoie pas de buffers vides)
1115 if (is_master){
1116 Integer buf[2];
1117 buf[0] = buf_size;
1118 buf[1] = unique_id_size;
1119 IntegerArrayView iav(2,buf);
1120 pm->allGather(iav,rank_sizes);
1121
1122 Integer buffer_total_size = 0;
1123 Integer unique_id_total_size = 0;
1124 IntegerUniqueArray buffer_rank_index(nb_rank);
1125 IntegerUniqueArray unique_id_rank_index(nb_rank);
1126
1127 for( Integer i=0; i<nb_rank; ++i ){
1128 buffer_rank_index[i] = buffer_total_size;
1129 buffer_total_size += rank_sizes[(i*2)];
1130 unique_id_rank_index[i] = unique_id_total_size;
1131 unique_id_total_size += rank_sizes[(i*2)+1];
1132 }
1133
1134 UniqueArray<DataType> full_buffer(buffer_total_size);
1135 Int64UniqueArray full_unique_ids(unique_id_total_size);
1136
1137 for( Integer i=0; i<nb_rank; ++i ){
1138 // Ne recoit pas de valeurs des processus n'ayant pas de valeurs
1139 if (rank_sizes[(i*2)]==0)
1140 continue;
1141 ArrayView<DataType> local_buf(rank_sizes[(i*2)],&full_buffer[ buffer_rank_index[i] ]);
1142 Int64ArrayView local_unique_ids(rank_sizes[(i*2)+1],&full_unique_ids[ unique_id_rank_index[i] ]);
1143 if (i==master_rank){
1144 local_buf.copy(buffer);
1145 local_unique_ids.copy(unique_ids);
1146 }
1147 else{
1148 pm->recv(local_buf,i);
1149 pm->recv(local_unique_ids,i);
1150 }
1151 }
1152 tm->info(5) << "PARALLEL WRITE path=" << m_hpath << " total_size=" << full_buffer.size();
1153 _writeSortedValues(tm,st,full_buffer,full_unique_ids);
1154 }
1155 else{
1156 Integer buf[2];
1157 buf[0] = buf_size;
1158 buf[1] = unique_id_size;
1159 IntegerArrayView iav(2,buf);
1160 pm->allGather(iav,rank_sizes);
1161 // Pas la peine d'envoyer des buffers vides
1162 if (buffer.size()>0){
1163 pm->send(buffer,master_rank);
1164 pm->send(unique_ids,master_rank);
1165 }
1166 }
1167}
1168
1169/*---------------------------------------------------------------------------*/
1170/*---------------------------------------------------------------------------*/
1171
1172template class StandardArrayT<Real>;
1173template class StandardArrayT<Real3>;
1174template class StandardArrayT<Real3x3>;
1175template class StandardArrayT<Real2>;
1176template class StandardArrayT<Real2x2>;
1177template class StandardArrayT<Int16>;
1178template class StandardArrayT<Int32>;
1179template class StandardArrayT<Int64>;
1180template class StandardArrayT<Byte>;
1181
1182/*---------------------------------------------------------------------------*/
1183/*---------------------------------------------------------------------------*/
1184
1185template<typename DataType> DataType
1188{
1189 Hdf5Utils::HDataset m_hdataset;
1190 m_hdataset.open(m_hfile,m_hpath);
1191 Hdf5Utils::HSpace hspace(m_hdataset.getSpace());
1192 {
1193 const int max_dim = 256; // Nombre maxi de dimensions des tableaux HDF
1194 hsize_t hdf_dims[max_dim];
1195 hsize_t max_dims[max_dim];
1196 int nb_dim = H5Sget_simple_extent_ndims(hspace.id());
1197 H5Sget_simple_extent_dims(hspace.id(),hdf_dims,max_dims);
1198
1199 if (nb_dim!=1 || hdf_dims[0]!=1)
1200 ARCANE_THROW(IOException,"Cannot read non scalar");
1201 }
1202
1203 DataType dummy;
1204 m_hdataset.read(st.nativeType(DataType()),&dummy);
1205 return dummy;
1206}
1207
1208/*---------------------------------------------------------------------------*/
1209
1210template<> String
1213{
1214 ByteUniqueArray utf8_bytes;
1215
1216
1217 Hdf5Utils::HDataset m_hdataset;
1218 m_hdataset.open(m_hfile,m_hpath);
1219 Hdf5Utils::HSpace hspace(m_hdataset.getSpace());
1220 {
1221 const int max_dim = 256; // Nombre maxi de dimensions des tableaux HDF
1222 hsize_t hdf_dims[max_dim];
1223 hsize_t max_dims[max_dim];
1224 int nb_dim = H5Sget_simple_extent_ndims(hspace.id());
1225 H5Sget_simple_extent_dims(hspace.id(),hdf_dims,max_dims);
1226
1227 if (nb_dim != 1)
1228 ARCANE_THROW(IOException,"Cannot read multidim string");
1229 utf8_bytes.resize(hdf_dims[0]);
1230 }
1231
1232 m_hdataset.read(st.nativeType(Byte()),utf8_bytes.data());
1233 return String(utf8_bytes);
1234}
1235
1236/*---------------------------------------------------------------------------*/
1237
1238template<typename DataType> void
1240write(Hdf5Utils::StandardTypes & st, const DataType & t)
1241{
1242 hsize_t dims[1] = { 1 };
1243 Hdf5Utils::HSpace hspace;
1244 hspace.createSimple(1,dims);
1245 if (hspace.isBad())
1246 ARCANE_THROW(IOException,"Can not create space");
1247
1248 Hdf5Utils::HDataset m_hdataset;
1249 m_hdataset.recursiveCreate(m_hfile,m_hpath,st.saveType(DataType()),hspace,H5P_DEFAULT);
1250 if (m_hdataset.isBad())
1251 ARCANE_THROW(IOException,"Can not create dataset");
1252
1253 herr_t herr = m_hdataset.write(st.nativeType(DataType()),&t);
1254 if (herr<0)
1255 ARCANE_THROW(IOException,"Cannot write data");
1256}
1257
1258/*---------------------------------------------------------------------------*/
1259
1260template<> void
1262write(Hdf5Utils::StandardTypes & st, const String & s)
1263{
1264 ByteConstArrayView utf8_bytes = s.utf8();
1265
1266 hsize_t dims[1];
1267 dims[0] = utf8_bytes.size() + 1;
1268
1269 Hdf5Utils::HSpace hspace;
1270 hspace.createSimple(1,dims);
1271 if (hspace.isBad())
1272 ARCANE_THROW(IOException,"Can not create space");
1273
1274 Hdf5Utils::HDataset m_hdataset;
1275 m_hdataset.recursiveCreate(m_hfile,m_hpath,st.saveType(Byte()),hspace,H5P_DEFAULT);
1276 if (m_hdataset.isBad())
1277 ARCANE_THROW(IOException,"Can not create dataset");
1278
1279 herr_t herr = m_hdataset.write(st.nativeType(Byte()),utf8_bytes.data());
1280 if (herr<0)
1281 ARCANE_THROW(IOException,"Cannot write data");
1282}
1283
1284/*---------------------------------------------------------------------------*/
1285
1286template class StandardScalarT<Real>;
1287template class StandardScalarT<Real3>;
1288template class StandardScalarT<Real3x3>;
1289template class StandardScalarT<Real2>;
1290template class StandardScalarT<Real2x2>;
1291template class StandardScalarT<Int16>;
1292template class StandardScalarT<Int32>;
1293template class StandardScalarT<Int64>;
1294template class StandardScalarT<Byte>;
1295template class StandardScalarT<String>;
1296
1297/*---------------------------------------------------------------------------*/
1298/*---------------------------------------------------------------------------*/
1299
1300} // namespace Arcane::Hdf5Utils
1301
1302/*---------------------------------------------------------------------------*/
1303/*---------------------------------------------------------------------------*/
#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:382
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:335
Encapsule un dataset simple d'un fichier HDF5 qui représente un tableau.
Definition Hdf5Utils.h:777
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()....
Definition Hdf5Utils.cc:968
void directRead(StandardTypes &st, Array< DataType > &buffer)
Lit le dataset d'un tableau 1D.
Definition Hdf5Utils.cc:977
void setIdsPath(const String &ids_path)
En lecture, positionne le chemin dans hfile du dataset contenant les unique_ids.
Definition Hdf5Utils.cc:911
Encapsule un dataset simple d'un fichier HDF5 qui représente un scalaire (éventuellement String).
Definition Hdf5Utils.h:823
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:562
HType m_real2x2_id
Identifiant HDF pour les Real2x2.
Definition Hdf5Utils.h:719
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:713
HType m_int_id
Identifiant HDF des entiers signés.
Definition Hdf5Utils.h:712
HType m_short_id
Identifiant HDF des entiers signés.
Definition Hdf5Utils.h:710
HType m_real3x3_id
Identifiant HDF pour les Real3x3.
Definition Hdf5Utils.h:720
HType m_real_id
Identifiant HDF des réels.
Definition Hdf5Utils.h:716
HType m_ushort_id
Identifiant HDF des entiers long signés.
Definition Hdf5Utils.h:711
HType m_ulong_id
Identifiant HDF des entiers long non signés.
Definition Hdf5Utils.h:715
HType m_uchar_id
Identifiant HDF des caractères non-signés.
Definition Hdf5Utils.h:709
HType m_real2_id
Identifiant HDF pour les Real2.
Definition Hdf5Utils.h:717
HType m_char_id
Identifiant HDF des entiers signés.
Definition Hdf5Utils.h:708
void initialize()
Initialise les types.
Definition Hdf5Utils.cc:702
HType m_uint_id
Identifiant HDF des entiers non signés.
Definition Hdf5Utils.h:714
HType m_real3_id
Identifiant HDF pour les Real3.
Definition Hdf5Utils.h:718
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:513
ArrayView< Integer > IntegerArrayView
Equivalent C d'un tableau à une dimension d'entiers.
Definition UtilsTypes.h:615
ArrayView< Int64 > Int64ArrayView
Equivalent C d'un tableau à une dimension d'entiers 64 bits.
Definition UtilsTypes.h:609
unsigned char Byte
Type d'un octet.
Definition UtilsTypes.h:142
eDataType
Type d'une donnée.
Definition DataTypes.h:39
@ 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_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_Int64
Donnée de type entier 64 bits.
Definition DataTypes.h:44
@ 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:638
UniqueArray< Integer > IntegerUniqueArray
Tableau dynamique à une dimension d'entiers.
Definition UtilsTypes.h:519
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