Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
Variable.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* Variable.cc (C) 2000-2026 */
9/* */
10/* Class managing a variable. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13#ifndef ARCANE_VARIABLE_CC
14#define ARCANE_VARIABLE_CC
15/*---------------------------------------------------------------------------*/
16/*---------------------------------------------------------------------------*/
17
18#include "arcane/utils/List.h"
19#include "arcane/utils/FatalErrorException.h"
20#include "arcane/utils/OStringStream.h"
21#include "arcane/utils/Iterator.h"
22#include "arcane/utils/Iostream.h"
23#include "arcane/utils/String.h"
24#include "arcane/utils/ITraceMng.h"
25#include "arcane/utils/PlatformUtils.h"
26#include "arcane/utils/IStackTraceService.h"
27#include "arcane/utils/MemoryAccessInfo.h"
28#include "arcane/utils/NotImplementedException.h"
29#include "arcane/utils/ScopedPtr.h"
30#include "arcane/utils/StringBuilder.h"
31#include "arcane/utils/MemoryView.h"
32
33#include "arcane/core/ItemGroupObserver.h"
34#include "arcane/core/Variable.h"
35#include "arcane/core/VarRefEnumerator.h"
36#include "arcane/core/IVariableAccessor.h"
37#include "arcane/core/ItemGroup.h"
38#include "arcane/core/IMesh.h"
39#include "arcane/core/IItemFamily.h"
40#include "arcane/core/ISubDomain.h"
41#include "arcane/core/VariableInfo.h"
42#include "arcane/core/ISerializer.h"
43#include "arcane/core/VariableBuildInfo.h"
44#include "arcane/core/VariableComputeFunction.h"
45#include "arcane/core/CommonVariables.h"
46#include "arcane/core/Observable.h"
47#include "arcane/core/IVariableMng.h"
48#include "arcane/core/IDataReader.h"
49#include "arcane/core/IDataWriter.h"
50#include "arcane/core/IParallelMng.h"
51#include "arcane/core/VariableDependInfo.h"
52#include "arcane/core/IParallelReplication.h"
53#include "arcane/core/VariableMetaData.h"
54#include "arcane/core/IMeshMng.h"
55#include "arcane/core/MeshHandle.h"
56#include "arcane/core/VariableComparer.h"
57#include "arcane/core/datatype/DataAllocationInfo.h"
58#include "arcane/core/internal/IItemFamilyInternal.h"
59#include "arcane/core/internal/IVariableMngInternal.h"
60#include "arcane/core/internal/IVariableInternal.h"
61#include "arcane/core/internal/IDataInternal.h"
62#include "arcane/core/internal/IParallelMngInternal.h"
63
64#include <map>
65#include <set>
66#include <atomic>
67
68/*---------------------------------------------------------------------------*/
69/*---------------------------------------------------------------------------*/
70
71namespace Arcane
72{
73
74/*---------------------------------------------------------------------------*/
75/*---------------------------------------------------------------------------*/
76
77const char* IVariable::TAG_POST_PROCESSING = "PostProcessing";
78const char* IVariable::TAG_POST_PROCESSING_AT_THIS_ITERATION = "PostProcessingAtThisIteration";
79
80/*---------------------------------------------------------------------------*/
81/*---------------------------------------------------------------------------*/
82
83/*
84 * \brief Private part of a variable.
85 */
86class VariablePrivate
87: public IVariableInternal
88{
89 public:
90
91 VariablePrivate(const VariableBuildInfo& v, const VariableInfo& vi, Variable* var);
92
93 public:
94
95 static std::atomic<Int64> modified_time_global_value;
96
97 public:
98
99 ISubDomain* m_sub_domain = nullptr;
100 IDataFactoryMng* m_data_factory_mng = nullptr;
106 int m_property = 0;
107 bool m_is_partial = false;
108 bool m_need_property_update = false;
109 bool m_is_used = false;
110 bool m_has_valid_data = false;
112 VariableRef* m_first_reference = nullptr;
120 std::map<String, String> m_tags;
122 bool m_want_shrink = false;
123 Variable* m_variable = nullptr;
124
125 public:
126
134 {
135 switch (sbuf->mode()) {
136 case ISerializer::ModeReserve:
137 sbuf->reserveSpan(eBasicDataType::Byte, HASHID_SIZE);
138 break;
140 sbuf->putSpan(Span<const Byte>(m_hash_id, HASHID_SIZE));
141 break;
143 Byte read_hash_id_buf[HASHID_SIZE];
144 Span<Byte> read_span(read_hash_id_buf, HASHID_SIZE);
145 sbuf->getSpan(read_span);
146 Span<const Byte> ref_span(m_hash_id, HASHID_SIZE);
147 if (ref_span != Span<const Byte>(read_span))
148 ARCANE_FATAL("Bad hashid for variable name='{0}'\n"
149 " expected_hash_id='{1}'\n"
150 " hash_id ='{2}'\n"
151 " This may be due to incoherence in variable list (order) between ranks"
152 " during serialization",
153 m_infos.fullName(), String(ref_span), String(read_span));
154 } break;
155 }
156 }
157
158 public:
159
161 String computeComparisonHashCollective(IHashAlgorithm* hash_algo, IData* sorted_data) override;
162 void changeAllocator(const MemoryAllocationOptions& alloc_info) override;
163 void resize(const VariableResizeArgs& resize_args) override;
167
168 private:
169
170 static const int HASHID_SIZE = 64;
178 Byte m_hash_id[HASHID_SIZE];
179
180 void _setHashId()
181 {
182 constexpr Int64 hashid_hexa_length = 16;
183 constexpr Int64 name_length = HASHID_SIZE - hashid_hexa_length;
184 Span<Byte> hash_id(m_hash_id, HASHID_SIZE);
185 hash_id.fill('~');
186 const String& full_name = m_infos.fullName();
187 Int64 hash_value = IntegerHashFunctionT<StringView>::hashfunc(full_name.view());
188 Convert::toHexaString(hash_value, hash_id);
189 Span<const Byte> bytes = full_name.bytes();
190 if (bytes.size() > name_length)
191 bytes = bytes.subspan(0, name_length);
192 auto hash_id2 = hash_id.subspan(hashid_hexa_length, name_length);
193 hash_id2.copy(bytes);
194 }
195};
196
197/*---------------------------------------------------------------------------*/
198/*---------------------------------------------------------------------------*/
199
200std::atomic<Int64> VariablePrivate::modified_time_global_value = 1;
201
202/*---------------------------------------------------------------------------*/
203/*---------------------------------------------------------------------------*/
204
207{
208 Int64 v = VariablePrivate::modified_time_global_value;
209 ++VariablePrivate::modified_time_global_value;
210 return v;
211}
212
213/*---------------------------------------------------------------------------*/
214/*---------------------------------------------------------------------------*/
215
216VariablePrivate::
217VariablePrivate(const VariableBuildInfo& v, const VariableInfo& vi, Variable* var)
218: m_sub_domain(v._subDomain())
219, m_data_factory_mng(v.dataFactoryMng())
220, m_mesh_handle(v.meshHandle())
221, m_infos(vi)
222, m_property(v.property())
223, m_is_partial(vi.isPartial())
224, m_variable(var)
225{
226 _setHashId();
227 m_infos.setDefaultItemGroupName();
228
229 // For testing only
230 if (!platform::getEnvironmentVariable("ARCANE_NO_RECURSIVE_DEPEND").null())
231 m_has_recursive_depend = false;
232
233 // For memory release testing.
234 {
235 String str = platform::getEnvironmentVariable("ARCANE_VARIABLE_SHRINK_MEMORY");
236 if (str == "1")
237 m_want_shrink = true;
238 }
239}
240
241/*---------------------------------------------------------------------------*/
242/*---------------------------------------------------------------------------*/
243
245class ItemGroupPartialVariableObserver
246: public IItemGroupObserver
247{
248 public:
249
250 explicit ItemGroupPartialVariableObserver(IVariable* var)
251 : m_var(var)
252 {
253 ARCANE_ASSERT((m_var), ("Variable pointer null"));
254
255 if (var->itemGroup().isAllItems())
256 ARCANE_FATAL("No observer should be attached on all items group");
257 }
258
259 void executeExtend(const Int32ConstArrayView* info) override
260 {
261 const Int32ConstArrayView& new_ids = *info;
262 if (new_ids.empty())
263 return;
264 ItemGroup group = m_var->itemGroup();
265 SharedPtrT<GroupIndexTable> id_to_index = group.localIdToIndex();
266
267 const Integer old_size = id_to_index->size();
268 const Integer group_size = group.size();
269 if (group_size != (old_size + new_ids.size()))
270 ARCANE_FATAL("Inconsistent extended size");
271 m_var->resizeFromGroup();
272 //id_to_index->update();
273 }
274
275 void executeReduce(const Int32ConstArrayView* info) override
276 {
277 // Contains the list of local IDs of items removed from the old group
278 const Int32ConstArrayView& removed_lids = *info;
279 if (removed_lids.empty())
280 return;
281 ItemGroup group = m_var->itemGroup();
282 SharedPtrT<GroupIndexTable> id_to_index = group.localIdToIndex();
283
284 const Integer old_size = id_to_index->size();
285 const Integer group_size = group.size();
286
287 if (group_size != (old_size - removed_lids.size()))
288 ARCANE_FATAL("Inconsistent reduced size {0} vs {1}", group_size, old_size);
289 [[maybe_unused]] ItemVectorView view = group.view();
290 Int32UniqueArray source;
291 Int32UniqueArray destination;
292 source.reserve(group_size);
293 destination.reserve(group_size);
294 for (Integer i = 0, index = 0, removed_index = 0; i < old_size; ++i) {
295 if (removed_index < removed_lids.size() &&
296 id_to_index->keyLocalId(i) == removed_lids[removed_index]) {
297 ++removed_index;
298 }
299 else {
300 ARCANE_ASSERT((id_to_index->keyLocalId(i) == view[index].localId()),
301 ("Inconsistent key (pos=%d,key=%d) vs (pos=%d,key=%d)",
302 i, id_to_index->keyLocalId(i), index, view[index].localId()));
303 if (i != index) {
304 destination.add(index);
305 source.add(i);
306 }
307 ++index;
308 }
309 }
310 m_var->copyItemsValues(source, destination);
311 m_var->resizeFromGroup();
312 }
313
314 void executeCompact(const Int32ConstArrayView* info) override
315 {
316 const Int32ConstArrayView& ids = *info;
317 if (ids.empty())
318 return;
319 ItemGroup group = m_var->itemGroup();
320 SharedPtrT<GroupIndexTable> id_to_index = group.localIdToIndex();
321 m_var->compact(*info);
322 //id_to_index->compact(info);
323 }
324
325 void executeInvalidate() override
326 {
327 ItemGroup group = m_var->itemGroup();
328 SharedPtrT<GroupIndexTable> id_to_index = group.localIdToIndex();
329 m_var->resizeFromGroup();
330 //id_to_index->update();
331 }
332
333 bool needInfo() const override { return true; }
334
335 private:
336
337 IVariable* m_var = nullptr;
338};
339
340/*---------------------------------------------------------------------------*/
341/*---------------------------------------------------------------------------*/
342
344Variable(const VariableBuildInfo& v, const VariableInfo& vi)
346, m_p(new VariablePrivate(v, vi, this))
347{
348}
349
350/*---------------------------------------------------------------------------*/
351/*---------------------------------------------------------------------------*/
352
354~Variable()
355{
356 //NOTE: if the variable has a group, it is the IVariableMng
357 // that removes the reference of this variable from the group
358 delete m_p;
359}
360
361/*---------------------------------------------------------------------------*/
362/*---------------------------------------------------------------------------*/
363
364bool Variable::
365_hasReference() const
366{
367 return m_p->m_first_reference;
368}
369
370/*---------------------------------------------------------------------------*/
371/*---------------------------------------------------------------------------*/
372
375{
376 _checkSetProperty(ref);
377 ++m_p->m_nb_reference;
378 ref->setNextReference(m_p->m_first_reference);
379 if (m_p->m_first_reference) {
380 VariableRef* _list = m_p->m_first_reference;
381 if (_list->previousReference())
382 _list->previousReference()->setNextReference(ref);
383 _list->setPreviousReference(ref);
384 }
385 else {
386 ref->setPreviousReference(0);
387 }
388 m_p->m_first_reference = ref;
389}
390
391/*---------------------------------------------------------------------------*/
392/*---------------------------------------------------------------------------*/
393
396{
397 {
398 VariableRef* tmp = ref;
399 if (tmp->previousReference())
401 if (tmp->nextReference())
403 if (m_p->m_first_reference == tmp)
404 m_p->m_first_reference = m_p->m_first_reference->nextReference();
405 }
406 // The reference may be used later, so we must remember to clear the
407 // previous and next references.
408 ref->setNextReference(0);
409 ref->setPreviousReference(0);
410
411 --m_p->m_nb_reference;
412 _checkSetProperty(ref);
413
414 // When there are no more references on this variable, it signals the
415 // variable manager, unless it is a persistent variable
416 if (!_hasReference()) {
417 bool is_persistant = property() & IVariable::PPersistant;
418 if (!is_persistant) {
419 //m_p->m_trace->info() << " REF PROPERTY name=" << name() << " " << ref->referenceProperty();
420 _removeMeshReference();
421 ISubDomain* sd = m_p->m_sub_domain;
422 IVariableMng* vm = sd->variableMng();
423 vm->_internalApi()->removeVariable(this);
424 }
425 }
426}
427
428/*---------------------------------------------------------------------------*/
429/*---------------------------------------------------------------------------*/
430
432firstReference() const
433{
434 return m_p->m_first_reference;
435}
436
437/*---------------------------------------------------------------------------*/
438/*---------------------------------------------------------------------------*/
439
440void Variable::
441_checkSetProperty(VariableRef* ref)
442{
443 // Guarantees that the property is correctly updated with the value
444 // of the single reference.
445 if (!_hasReference()) {
447 m_p->m_need_property_update = false;
448 }
449 else
450 m_p->m_need_property_update = true;
451}
452
453/*---------------------------------------------------------------------------*/
454/*---------------------------------------------------------------------------*/
455
457nbReference() const
458{
459 return m_p->m_nb_reference;
460}
461
462/*---------------------------------------------------------------------------*/
463/*---------------------------------------------------------------------------*/
464
466subDomain()
467{
468 return m_p->m_sub_domain;
469}
470
471/*---------------------------------------------------------------------------*/
472/*---------------------------------------------------------------------------*/
473
475variableMng() const
476{
477 return m_p->m_sub_domain->variableMng();
478}
479
480/*---------------------------------------------------------------------------*/
481/*---------------------------------------------------------------------------*/
482
484name() const
485{
486 return m_p->m_infos.localName();
487}
488
489/*---------------------------------------------------------------------------*/
490/*---------------------------------------------------------------------------*/
491
493fullName() const
494{
495 return m_p->m_infos.fullName();
496}
497
498/*---------------------------------------------------------------------------*/
499/*---------------------------------------------------------------------------*/
500
502itemFamilyName() const
503{
504 return m_p->m_infos.itemFamilyName();
505}
506
507/*---------------------------------------------------------------------------*/
508/*---------------------------------------------------------------------------*/
509
511itemGroupName() const
512{
513 return m_p->m_infos.itemGroupName();
514}
515
516/*---------------------------------------------------------------------------*/
517/*---------------------------------------------------------------------------*/
518
520meshName() const
521{
522 return m_p->m_infos.meshName();
523}
524
525/*---------------------------------------------------------------------------*/
526/*---------------------------------------------------------------------------*/
527
529dataType() const
530{
531 return m_p->m_infos.dataType();
532}
533
534/*---------------------------------------------------------------------------*/
535/*---------------------------------------------------------------------------*/
536
541property() const
542{
543 if (!m_p->m_need_property_update)
544 return m_p->m_property;
545
546 // The variable's properties depend on what each
547 // reference wants, and they must be updated when they change.
548 // For example, if all references are PNoDump but only one is not,
549 // the variable should not be.
550 m_p->m_need_property_update = false;
551
552 bool want_dump = false;
553 bool want_sync = false;
554 bool want_replica_sync = false;
555 bool sub_domain_depend = false;
556 bool execution_depend = false;
557 bool want_private = false;
558 bool want_restore = false;
559 bool want_notemporary = false;
560 bool want_exchange = false;
561 bool want_persistant = false;
562 bool want_shmem = false;
563 bool want_dumpnull = false;
564
565 int property = 0;
566 for (VarRefEnumerator i(this); i.hasNext(); ++i) {
567 VariableRef* vref = *i;
568 int p = vref->referenceProperty();
569 if (!(p & IVariable::PNoDump))
570 want_dump = true;
571 if (!(p & IVariable::PNoNeedSync))
572 want_sync = true;
573 if (!(p & IVariable::PNoReplicaSync))
574 want_replica_sync = true;
576 sub_domain_depend = true;
578 execution_depend = true;
579 if ((p & IVariable::PPersistant))
580 want_persistant = true;
581 if ((p & IVariable::PPrivate))
582 want_private = true;
583 if (!(p & IVariable::PNoRestore))
584 want_restore = true;
585 if (!(p & IVariable::PNoExchange))
586 want_exchange = true;
587 if (!(p & IVariable::PTemporary))
588 want_notemporary = true;
589 if ((p & IVariable::PInShMem))
590 want_shmem = true;
591 if ((p & IVariable::PDumpNull))
592 want_dumpnull = true;
593 }
594
595 if (!want_dump)
596 property |= IVariable::PNoDump;
597 if (!want_sync)
598 property |= IVariable::PNoNeedSync;
599 if (!want_replica_sync)
600 property |= IVariable::PNoReplicaSync;
601 if (sub_domain_depend)
602 property |= IVariable::PSubDomainDepend;
603 if (execution_depend)
604 property |= IVariable::PExecutionDepend;
605 if (want_private)
606 property |= IVariable::PPrivate;
607 if (want_persistant)
608 property |= IVariable::PPersistant;
609 if (!want_restore)
610 property |= IVariable::PNoRestore;
611 if (!want_exchange)
612 property |= IVariable::PNoExchange;
613 if (!want_notemporary)
614 property |= IVariable::PTemporary;
615 if (want_shmem)
616 property |= IVariable::PInShMem;
617 if (want_dumpnull)
618 property |= IVariable::PDumpNull;
619
620 m_p->m_property = property;
621 return m_p->m_property;
622}
623
624/*---------------------------------------------------------------------------*/
625/*---------------------------------------------------------------------------*/
626
629{
630 m_p->m_need_property_update = true;
631}
632
633/*---------------------------------------------------------------------------*/
634/*---------------------------------------------------------------------------*/
635
637setUsed(bool is_used)
638{
639 if (m_p->m_is_used == is_used)
640 return;
641
642 m_p->m_is_used = is_used;
643
644 eItemKind ik = itemKind();
645
646 if (m_p->m_is_used) {
647 if (m_p->m_property & IVariable::PInShMem) {
648 if (m_p->m_property & IVariable::PSubDomainPrivate) {
649 ARCANE_FATAL("Variable with PInShMem property must be in all sub-domains (PSubDomainPrivate property cannot be set with PInShMem)");
650 }
651 if (m_p->m_data->_commonInternal()->numericData() == nullptr) {
652 ARCANE_FATAL("Variable without NumericData cannot change allocator");
653 }
654 // TODO: Even if changeAllocator() with the same allocator already in
655 // place just returns, it's still messy...
656 IParallelMng* pm{};
657 if (m_p->m_mesh_handle.hasMesh()) {
658 pm = m_p->m_mesh_handle.mesh()->parallelMng();
659 }
660 else {
661 pm = subDomain()->parallelMng();
662 }
663 m_p->changeAllocator(pm->_internalApi()->machineShMemWinMemoryAllocator());
664 }
665
666 if (m_p->m_item_group.null() && ik != IK_Unknown) {
667 _checkSetItemFamily();
668 _checkSetItemGroup();
669 // Be careful not to reset the values when they are valid, which
670 // is the case for example after a protection.
671 if (!m_p->m_has_valid_data) {
673 // Historically, we filled the variable with the default constructor
674 // of the data by systematically calling fillDefautt(). However,
675 // this was not the desired behavior, which should be defined by
676 // getGlobalDataInitialisationPolicy() (in DataTypes.h).
677 // We only do this now if the initialization mode is equal
678 // to DIP_Legacy. This mode must eventually disappear.
680 m_p->m_data->fillDefault();
681 m_p->m_has_valid_data = true;
682 }
683 }
684 }
685 else {
686 _removeMeshReference();
687 if (ik == IK_Unknown)
688 resize(0);
689 else
691 // Indicates that the values are no longer valid
692 m_p->m_has_valid_data = false;
693 }
694
695 for (VarRefEnumerator i(this); i.hasNext(); ++i) {
696 VariableRef* ref = *i;
697 ref->internalSetUsed(m_p->m_is_used);
698 }
699}
700
701/*---------------------------------------------------------------------------*/
702/*---------------------------------------------------------------------------*/
703
704void Variable::
705_removeMeshReference()
706{
707 IItemFamily* family = m_p->m_item_family;
708 if (family)
709 family->_internalApi()->removeVariable(this);
710
711 if (isPartial())
713
715 m_p->m_item_family = 0;
716}
717
718/*---------------------------------------------------------------------------*/
719/*---------------------------------------------------------------------------*/
720
722isUsed() const
723{
724 return m_p->m_is_used;
725}
726
727/*---------------------------------------------------------------------------*/
728/*---------------------------------------------------------------------------*/
729
730namespace
731{
732
733 String _buildVariableFullType(const IVariable* var)
734 {
735 StringBuilder full_type_b;
736 full_type_b = dataTypeName(var->dataType());
737 full_type_b += ".";
738 full_type_b += itemKindName(var->itemKind());
739 full_type_b += ".";
740 full_type_b += var->dimension();
741 full_type_b += ".";
742 full_type_b += var->multiTag();
743 if (var->isPartial())
744 full_type_b += ".Partial";
745 return full_type_b.toString();
746 }
747
748} // namespace
749
750/*---------------------------------------------------------------------------*/
751/*---------------------------------------------------------------------------*/
752
753VariableMetaData* Variable::
754_createMetaData() const
755{
756 auto vmd = new VariableMetaData(name(), meshName(), itemFamilyName(),
758 vmd->setFullType(_buildVariableFullType(this));
759 vmd->setMultiTag(String::fromNumber(multiTag()));
760 vmd->setProperty(property());
761 return vmd;
762}
763
764/*---------------------------------------------------------------------------*/
765/*---------------------------------------------------------------------------*/
766
768createMetaData() const
769{
770 return _createMetaData();
771}
772
773/*---------------------------------------------------------------------------*/
774/*---------------------------------------------------------------------------*/
775
777createMetaDataRef() const
778{
779 return makeRef(_createMetaData());
780}
781
782/*---------------------------------------------------------------------------*/
783/*---------------------------------------------------------------------------*/
784
787{
788 //cout << "** SYNC REFERENCE N=" << m_p->m_nb_reference << " F=" << m_p->m_first_reference << '\n';
789 for (VarRefEnumerator i(this); i.hasNext(); ++i) {
790 VariableRef* ref = *i;
791 //cout << "** SYNC REFERENCE V=" << ref << '\n';
792 ref->updateFromInternal();
793 }
794 // It must be done after updating references
795 // because observers may read values via a reference
797}
798
799/*---------------------------------------------------------------------------*/
800/*---------------------------------------------------------------------------*/
801
803checkIfSync(int max_print)
804{
805 VariableComparerArgs compare_args;
806 compare_args.setCompareMode(eVariableComparerCompareMode::Sync);
807 compare_args.setMaxPrint(max_print);
808 compare_args.setCompareGhost(true);
809 VariableComparerResults results = _compareVariable(compare_args);
810 return results.nbDifference();
811}
812
813/*---------------------------------------------------------------------------*/
814/*---------------------------------------------------------------------------*/
815
818{
819 VariableComparerArgs compare_args;
820 compare_args.setCompareMode(eVariableComparerCompareMode::SameOnAllReplica);
821 compare_args.setMaxPrint(max_print);
823 return r.nbDifference();
824}
825
826/*---------------------------------------------------------------------------*/
827/*---------------------------------------------------------------------------*/
828
830checkIfSame(IDataReader* reader, Integer max_print, bool compare_ghost)
831{
832 VariableComparerArgs compare_args;
833 compare_args.setMaxPrint(max_print);
834 compare_args.setCompareGhost(compare_ghost);
835 compare_args.setDataReader(reader);
837 return r.nbDifference();
838}
839
840/*---------------------------------------------------------------------------*/
841/*---------------------------------------------------------------------------*/
842
844mesh() const
845{
846 if (m_p->m_mesh_handle.hasMesh())
847 return m_p->m_mesh_handle.mesh();
848 return nullptr;
849}
850
851/*---------------------------------------------------------------------------*/
852/*---------------------------------------------------------------------------*/
853
855meshHandle() const
856{
857 return m_p->m_mesh_handle;
858}
859
860/*---------------------------------------------------------------------------*/
861/*---------------------------------------------------------------------------*/
862
864itemGroup() const
865{
866 return m_p->m_item_group;
867}
868
869/*---------------------------------------------------------------------------*/
870/*---------------------------------------------------------------------------*/
871
873itemKind() const
874{
875 return m_p->m_infos.itemKind();
876}
877
878/*---------------------------------------------------------------------------*/
879/*---------------------------------------------------------------------------*/
880
882dimension() const
883{
884 return m_p->m_infos.dimension();
885}
886
887/*---------------------------------------------------------------------------*/
888/*---------------------------------------------------------------------------*/
889
891multiTag() const
892{
893 return m_p->m_infos.multiTag();
894}
895
896/*---------------------------------------------------------------------------*/
897/*---------------------------------------------------------------------------*/
898
900isPartial() const
901{
902 return m_p->m_is_partial;
903}
904
905/*---------------------------------------------------------------------------*/
906/*---------------------------------------------------------------------------*/
907
909itemFamily() const
910{
911 return m_p->m_item_family;
912}
913
914/*---------------------------------------------------------------------------*/
915/*---------------------------------------------------------------------------*/
916
919{
920 m_p->m_data = data;
921 if (!data.get()) {
922 ARCANE_FATAL("Invalid data: name={0} datatype={1} dimension={2} multitag={3}",
923 m_p->m_infos.fullName(), m_p->m_infos.dataType(),
924 m_p->m_infos.dimension(), m_p->m_infos.multiTag());
925 }
926 data->setName(m_p->m_infos.fullName());
927}
928
929/*---------------------------------------------------------------------------*/
930/*---------------------------------------------------------------------------*/
931
933_setValidData(bool valid_data)
934{
935 m_p->m_has_valid_data = valid_data;
936}
937
938/*---------------------------------------------------------------------------*/
939/*---------------------------------------------------------------------------*/
940
942_hasValidData() const
943{
944 return m_p->m_has_valid_data;
945}
946
947/*---------------------------------------------------------------------------*/
948/*---------------------------------------------------------------------------*/
949
950void Variable::
951_setProperty(int property)
952{
954}
955
956/*---------------------------------------------------------------------------*/
957/*---------------------------------------------------------------------------*/
958
960dataFactoryMng() const
961{
962 return m_p->m_data_factory_mng;
963}
964
965/*---------------------------------------------------------------------------*/
966/*---------------------------------------------------------------------------*/
967
970{
971 debug(Trace::High) << "Serialize (partial) variable name=" << fullName();
972 m_p->serializeHashId(sbuffer);
973 m_p->m_data->serialize(sbuffer, ids, operation);
974 // In read mode, data is modified
975 if (sbuffer->mode() == ISerializer::ModeGet)
977}
978
979/*---------------------------------------------------------------------------*/
980/*---------------------------------------------------------------------------*/
981
983serialize(ISerializer* sbuffer, IDataOperation* operation)
984{
985 debug(Trace::High) << "Serialize (full) variable name=" << fullName();
986
987 m_p->serializeHashId(sbuffer);
988 m_p->m_data->serialize(sbuffer, operation);
989 // In read mode, data is modified
990 if (sbuffer->mode() == ISerializer::ModeGet)
992}
993
994/*---------------------------------------------------------------------------*/
995/*---------------------------------------------------------------------------*/
996
997void Variable::
998_resize(const VariableResizeArgs& resize_args)
999{
1000 eItemKind ik = itemKind();
1001 if (ik != IK_Unknown) {
1002 ARCANE_FATAL("This call is invalid for item variable. Use resizeFromGroup() instead");
1003 }
1004 _internalResize(resize_args);
1006}
1007
1008/*---------------------------------------------------------------------------*/
1009/*---------------------------------------------------------------------------*/
1010
1012resize(Integer new_size)
1013{
1014 _resize(VariableResizeArgs(new_size));
1015}
1016
1017/*---------------------------------------------------------------------------*/
1018/*---------------------------------------------------------------------------*/
1019
1022{
1023 eItemKind ik = itemKind();
1024 if (ik == IK_Unknown)
1025 return;
1026 Integer new_size = 0;
1027 IItemFamily* family = m_p->m_item_family;
1028 if (family) {
1029 if (m_p->m_item_group.isAllItems())
1030 new_size = m_p->m_item_family->maxLocalId();
1031 else
1032 new_size = m_p->m_item_group.size();
1033 }
1034 else {
1035 ItemGroup group = m_p->m_item_group;
1036 if (!group.null()) {
1037 ARCANE_FATAL("Variable '{0}' has group but no family", fullName());
1038 }
1039 }
1040 debug(Trace::High) << "Variable::resizeFromGroup() var='" << fullName()
1041 << "' with " << new_size << " items "
1042 << " this=" << this;
1043 _internalResize(VariableResizeArgs(new_size, new_size / 20));
1045}
1046
1047/*---------------------------------------------------------------------------*/
1048/*---------------------------------------------------------------------------*/
1049
1050void Variable::
1051_checkSetItemFamily()
1052{
1054 return;
1055
1056 if (m_p->m_mesh_handle.isNull())
1057 m_p->m_mesh_handle = m_p->m_sub_domain->meshMng()->findMeshHandle(m_p->m_infos.meshName());
1058
1060 if (!mesh)
1061 ARCANE_FATAL("No mesh named '{0}' exists for variable '{1}'", m_p->m_infos.meshName(), name());
1062
1063 eItemKind ik = itemKind();
1064
1065 IItemFamily* family = 0;
1066 const String& family_name = m_p->m_infos.itemFamilyName();
1067 if (ik == IK_Particle || ik == IK_DoF) {
1068 if (family_name.null()) {
1069 ARCANE_FATAL("family name not specified for variable {0}", name());
1070 }
1071 family = mesh->findItemFamily(ik, family_name, true);
1072 }
1073 else {
1074 family = mesh->itemFamily(ik);
1075 }
1076
1077 if (family && family->itemKind() != itemKind())
1078 ARCANE_FATAL("Bad family kind '{0}' '{1}'", family->itemKind(), itemKind());
1079
1080 if (family && family->name() != itemFamilyName())
1081 ARCANE_FATAL("Incoherent family name. var={0} from_type={1} given={2}",
1082 name(), family->name(), itemFamilyName());
1083
1084 if (!family)
1085 ARCANE_FATAL("Family not found");
1086
1087 if (isPartial() && !family->hasUniqueIdMap())
1088 ARCANE_FATAL("Cannot have partial variable for a family without unique id map");
1089
1090 m_p->m_item_family = family;
1091 debug(Trace::High) << "Variable::setItemFamily() name=" << name()
1092 << " family=" << family
1093 << " familyname='" << family_name << "'";
1094 family->_internalApi()->addVariable(this);
1095}
1096
1097/*---------------------------------------------------------------------------*/
1098/*---------------------------------------------------------------------------*/
1099
1100void Variable::
1101_checkSetItemGroup()
1102{
1103 if (!m_p->m_item_group.null())
1104 return;
1105 const String& group_name = m_p->m_infos.itemGroupName();
1106 //info() << " CHECK SET GROUP var=" << name() << " group=" << group_name;
1107 if (group_name.null()) {
1108 m_p->m_item_group = m_p->m_item_family->allItems();
1109 }
1110 else
1111 m_p->m_item_group = m_p->m_item_family->findGroup(group_name, true);
1112
1113 ItemGroupImpl* internal = m_p->m_item_group.internal();
1114 // (HP) TODO: should we keep this check inherited from the old addVariable implementation
1115 if (internal->parent() && (mesh()->parallelMng()->isParallel() && internal->isOwn()))
1116 ARCANE_FATAL("Cannot add variable ({0}) on a own group (name={1})",
1117 fullName(), internal->name());
1118 if (isPartial()) {
1119 if (group_name.empty())
1120 ARCANE_FATAL("Cannot create a partial variable with an empty item_group_name");
1121 debug(Trace::High) << "Attach ItemGroupPartialVariableObserver from " << fullName()
1122 << " to " << m_p->m_item_group.name();
1123 internal->attachObserver(this, new ItemGroupPartialVariableObserver(this));
1124 }
1125}
1126
1127/*---------------------------------------------------------------------------*/
1128/*---------------------------------------------------------------------------*/
1129
1132{
1133 return &(m_p->m_write_observable);
1134}
1135
1136/*---------------------------------------------------------------------------*/
1137/*---------------------------------------------------------------------------*/
1138
1141{
1142 return &(m_p->m_read_observable);
1143}
1144
1145/*---------------------------------------------------------------------------*/
1146/*---------------------------------------------------------------------------*/
1147
1150{
1151 return &(m_p->m_on_size_changed_observable);
1152}
1153
1154/*---------------------------------------------------------------------------*/
1155/*---------------------------------------------------------------------------*/
1156
1157/*---------------------------------------------------------------------------*/
1158/*---------------------------------------------------------------------------*/
1159
1161update()
1162{
1163 update(DPT_PreviousTime);
1164}
1165
1166/*---------------------------------------------------------------------------*/
1167/*---------------------------------------------------------------------------*/
1168
1169void Variable::
1170update(Real wanted_time)
1171{
1172 if (m_p->m_last_update_time < wanted_time) {
1173 for (Integer k = 0, n = m_p->m_depends.size(); k < n; ++k) {
1174 VariableDependInfo& vdi = m_p->m_depends[k];
1175 if (vdi.dependType() == DPT_PreviousTime)
1176 vdi.variable()->update(wanted_time);
1177 }
1178 }
1179
1180 if (m_p->m_has_recursive_depend) {
1181 for (Integer k = 0, n = m_p->m_depends.size(); k < n; ++k) {
1182 VariableDependInfo& vdi = m_p->m_depends[k];
1183 if (vdi.dependType() == DPT_CurrentTime)
1184 vdi.variable()->update(m_p->m_last_update_time);
1185 }
1186 }
1187
1188 bool need_update = false;
1189 Int64 modified_time = m_p->m_modified_time;
1190 for (Integer k = 0, n = m_p->m_depends.size(); k < n; ++k) {
1191 VariableDependInfo& vdi = m_p->m_depends[k];
1192 Int64 mt = vdi.variable()->modifiedTime();
1193 if (mt > modified_time) {
1194 need_update = true;
1195 break;
1196 }
1197 }
1198 if (need_update) {
1199 IVariableComputeFunction* cf = m_p->m_compute_function.get();
1200 //msg->info() << "Need Compute For Variable <" << name() << "> " << cf;
1201 if (cf) {
1202 //msg->info() << "Compute For Variable <" << name() << ">";
1203 cf->execute();
1204 }
1205 else {
1206 ARCANE_FATAL("No compute function for variable '{0}'", fullName());
1207 }
1208 }
1209}
1210
1211/*---------------------------------------------------------------------------*/
1212/*---------------------------------------------------------------------------*/
1213
1216{
1217 m_p->m_last_update_time = subDomain()->commonVariables().globalTime();
1218 m_p->m_modified_time = IVariable::incrementModifiedTime();
1219}
1220
1221/*---------------------------------------------------------------------------*/
1222/*---------------------------------------------------------------------------*/
1223
1226{
1227 return m_p->m_modified_time;
1228}
1229
1230/*---------------------------------------------------------------------------*/
1231/*---------------------------------------------------------------------------*/
1232
1235{
1236 m_p->m_depends.add(VariableDependInfo(var, dt, TraceInfo()));
1237}
1238
1239/*---------------------------------------------------------------------------*/
1240/*---------------------------------------------------------------------------*/
1241
1243addDepend(IVariable* var, eDependType dt, const TraceInfo& tinfo)
1244{
1245 m_p->m_depends.add(VariableDependInfo(var, dt, tinfo));
1246}
1247
1248/*---------------------------------------------------------------------------*/
1249/*---------------------------------------------------------------------------*/
1250
1253{
1254 ARCANE_UNUSED(var);
1255 throw NotImplementedException(A_FUNCINFO);
1256}
1257
1258/*---------------------------------------------------------------------------*/
1259/*---------------------------------------------------------------------------*/
1260
1263{
1264 m_p->m_compute_function = v;
1265}
1266
1267/*---------------------------------------------------------------------------*/
1268/*---------------------------------------------------------------------------*/
1269
1272{
1273 return m_p->m_compute_function.get();
1274}
1275
1276/*---------------------------------------------------------------------------*/
1277/*---------------------------------------------------------------------------*/
1278
1281{
1282 for (Integer k = 0, n = m_p->m_depends.size(); k < n; ++k) {
1283 VariableDependInfo& vdi = m_p->m_depends[k];
1284 infos.add(vdi);
1285 }
1286}
1287
1288/*---------------------------------------------------------------------------*/
1289/*---------------------------------------------------------------------------*/
1290
1291/*---------------------------------------------------------------------------*/
1292/*---------------------------------------------------------------------------*/
1293
1295addTag(const String& tagname, const String& tagvalue)
1296{
1297 m_p->m_tags[tagname] = tagvalue;
1298}
1299
1300/*---------------------------------------------------------------------------*/
1301/*---------------------------------------------------------------------------*/
1302
1304removeTag(const String& tagname)
1305{
1306 m_p->m_tags.erase(tagname);
1307}
1308
1309/*---------------------------------------------------------------------------*/
1310/*---------------------------------------------------------------------------*/
1311
1313hasTag(const String& tagname)
1314{
1315 return m_p->m_tags.find(tagname) != m_p->m_tags.end();
1316}
1317
1318/*---------------------------------------------------------------------------*/
1319/*---------------------------------------------------------------------------*/
1320
1322tagValue(const String& tagname)
1323{
1324 std::map<String, String>::const_iterator i = m_p->m_tags.find(tagname);
1325 if (i == m_p->m_tags.end())
1326 return String();
1327 return i->second;
1328}
1329
1330/*---------------------------------------------------------------------------*/
1331/*---------------------------------------------------------------------------*/
1332
1335{
1336 setUpToDate();
1339 _setValidData(true);
1340}
1341
1342/*---------------------------------------------------------------------------*/
1343/*---------------------------------------------------------------------------*/
1344
1350
1351/*---------------------------------------------------------------------------*/
1352/*---------------------------------------------------------------------------*/
1353
1355read(IDataReader* reader)
1356{
1357 reader->read(this, data());
1358 notifyEndRead();
1359}
1360
1361/*---------------------------------------------------------------------------*/
1362/*---------------------------------------------------------------------------*/
1363
1365write(IDataWriter* writer)
1366{
1368 writer->write(this, data());
1369}
1370
1371/*---------------------------------------------------------------------------*/
1372/*---------------------------------------------------------------------------*/
1373
1375changeGroupIds(Int32ConstArrayView old_to_new_ids)
1376{
1377 ARCANE_UNUSED(old_to_new_ids);
1378 // pH: default implementation since this method is not yet official
1379}
1380
1381/*---------------------------------------------------------------------------*/
1382/*---------------------------------------------------------------------------*/
1383
1396{
1397 if (!m_p->m_is_used)
1398 ARCANE_FATAL("Can not swap variable values for unused variable (instance)");
1399 if (!rhs->m_p->m_is_used)
1400 ARCANE_FATAL("Can not swap variable values for unused variable (argument)");
1401 if (isPartial() || rhs->isPartial())
1402 ARCANE_FATAL("Can not swap variable values for partial variables");
1403 if (itemGroup() != rhs->itemGroup())
1404 ARCANE_FATAL("Can not swap variable values for variables from different groups");
1405}
1406
1407/*---------------------------------------------------------------------------*/
1408/*---------------------------------------------------------------------------*/
1409
1410bool Variable::
1411_wantShrink() const
1412{
1413 return m_p->m_want_shrink;
1414}
1415
1416/*---------------------------------------------------------------------------*/
1417/*---------------------------------------------------------------------------*/
1418
1421{
1422 data()->setAllocationInfo(v);
1423 // It is possible that the allocation change modifies the * allocated
1424 // data. Therefore, references must be synchronized.
1426}
1427
1428/*---------------------------------------------------------------------------*/
1429/*---------------------------------------------------------------------------*/
1430
1432allocationInfo() const
1433{
1434 return data()->allocationInfo();
1435}
1436
1437/*---------------------------------------------------------------------------*/
1438/*---------------------------------------------------------------------------*/
1439
1442{
1443 return m_p;
1444}
1445
1446/*---------------------------------------------------------------------------*/
1447/*---------------------------------------------------------------------------*/
1448
1449/*---------------------------------------------------------------------------*/
1450/*---------------------------------------------------------------------------*/
1451
1454 IData* sorted_data)
1455{
1456 ARCANE_CHECK_POINTER(hash_algo);
1457 ARCANE_CHECK_POINTER(sorted_data);
1458
1459 INumericDataInternal* num_data = sorted_data->_commonInternal()->numericData();
1460 if (!num_data)
1461 return {};
1462 if (!m_item_family)
1463 return {};
1464
1465 IParallelMng* pm = m_item_family->parallelMng();
1466 Int32 my_rank = pm->commRank();
1467 Int32 master_rank = pm->masterIORank();
1468 ConstMemoryView memory_view = num_data->memoryView();
1469
1470 UniqueArray<Byte> bytes;
1471
1472 pm->gatherVariable(Arccore::asSpan<Byte>(memory_view.bytes()).smallView(), bytes, master_rank);
1473
1474 String hash_string;
1475 if (my_rank == master_rank) {
1476 HashAlgorithmValue hash_value;
1477 hash_algo->computeHash(asBytes(bytes), hash_value);
1478 hash_string = Convert::toHexaString(asBytes(hash_value.bytes()));
1479 }
1480 return hash_string;
1481}
1482
1483/*---------------------------------------------------------------------------*/
1484/*---------------------------------------------------------------------------*/
1485
1487changeAllocator(const MemoryAllocationOptions& mem_options)
1488{
1489 INumericDataInternal* dx = m_data->_commonInternal()->numericData();
1490 if (dx) {
1491 dx->changeAllocator(mem_options);
1492 m_variable->syncReferences();
1493 }
1494}
1495
1496/*---------------------------------------------------------------------------*/
1497/*---------------------------------------------------------------------------*/
1498
1500resize(const VariableResizeArgs& resize_args)
1501{
1502 return m_variable->_resize(resize_args);
1503}
1504
1505/*---------------------------------------------------------------------------*/
1506/*---------------------------------------------------------------------------*/
1507
1509compareVariable(const VariableComparerArgs& compare_args)
1510{
1511 return m_variable->_compareVariable(compare_args);
1512}
1513
1514/*---------------------------------------------------------------------------*/
1515/*---------------------------------------------------------------------------*/
1516
1518replicaParallelMng() const
1519{
1520 //TODO: check if the variable is used.
1521 IMesh* mesh = m_variable->mesh();
1522 // TODO: should we take the subdomain in this case?
1523 IParallelMng* pm = (mesh) ? mesh->parallelMng() : m_variable->subDomain()->parallelMng();
1525 if (!pr->hasReplication())
1526 return nullptr;
1527 return pr->replicaParallelMng();
1528}
1529
1530/*---------------------------------------------------------------------------*/
1531/*---------------------------------------------------------------------------*/
1532
1533} // End namespace Arcane
1534
1535/*---------------------------------------------------------------------------*/
1536/*---------------------------------------------------------------------------*/
1537
1538#endif
#define ARCANE_CHECK_POINTER(ptr)
Macro returning the pointer ptr if it is not null or throwing an exception if it is null.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Base class for 1D data vectors.
void add(ConstReferenceType val)
Adds element val to the end of the array.
void reserve(Int64 new_capacity)
Reserves memory for new_capacity elements.
Observable that automatically calls IObservable::detachAllObservers() in the destructor.
Real globalTime() const
Current time.
constexpr Integer size() const noexcept
Number of elements in the array.
constexpr bool empty() const noexcept
true if the array is empty (size()==0)
Constant view on a contiguous memory region containing fixed-size elements.
constexpr SpanType bytes() const
View in byte form.
Information on data allocation.
Hash algorithm return value.
Interface of the data factory manager.
virtual INumericDataInternal * numericData()
Generic interface for numeric data (nullptr if the data is not numeric).
Interface of an operation on a data.
Interface for reading variable data.
Definition IDataReader.h:35
virtual void read(IVariable *var, IData *data)=0
Reads the data data of the variable var.
Interface for writing variable data.
Definition IDataWriter.h:45
virtual void write(IVariable *var, IData *data)=0
Writes the data data of the variable var.
Interface of a data item.
Definition IData.h:34
virtual DataAllocationInfo allocationInfo() const =0
Allocation information.
virtual IDataInternal * _commonInternal()=0
virtual void setAllocationInfo(const DataAllocationInfo &v)=0
Sets the allocation information.
Interface of a hashing algorithm.
virtual void computeHash(Span< const std::byte > input, HashAlgorithmValue &value)
Calculates the hash value for the array input.
virtual void addVariable(IVariable *var)=0
Adds a variable to this family.
virtual void removeVariable(IVariable *var)=0
Removes a variable from this family.
Interface of an entity family.
Definition IItemFamily.h:83
virtual bool hasUniqueIdMap() const =0
Indicates if the family has a uniqueId to localId conversion table.
virtual String name() const =0
Family name.
virtual eItemKind itemKind() const =0
Entity kind.
virtual IItemFamilyInternal * _internalApi()=0
Internal Arcane API.
virtual IItemFamily * findItemFamily(eItemKind ik, const String &name, bool create_if_needed=false, bool register_modifier_if_created=false)=0
Returns the family named name.
virtual MeshHandle * findMeshHandle(const String &name, bool throw_exception)=0
Searches for the mesh with name name.
Interface for an 'IData' of a numeric type.
virtual void changeAllocator(const MemoryAllocationOptions &alloc_info)=0
Changes the variable's allocator.
virtual MutableMemoryView memoryView()=0
Memory view of the data.
virtual void notifyAllObservers()=0
Notifies all observers.
virtual MemoryAllocationOptions machineShMemWinMemoryAllocator()=0
Method allowing retrieval of a shared memory allocator.
Interface of the parallelism manager for a subdomain.
virtual void gatherVariable(ConstArrayView< char > send_buf, Array< char > &recv_buf, Int32 rank)=0
Performs an all-gather operation across all processors.
virtual Int32 commRank() const =0
Rank of this instance in the communicator.
virtual IParallelReplication * replication() const =0
Replication information.
virtual Integer masterIORank() const =0
Rank of the instance managing I/O (for which isMasterIO() is true).
virtual IParallelMngInternal * _internalApi()=0
Internal Arcane API.
Brief information on parallel subdomain replication.
virtual bool hasReplication() const =0
Indicates if replication is active.
virtual IParallelMng * replicaParallelMng() const =0
Communicator associated with all replicas representing the same subdomain.
virtual void putSpan(Span< const Real > values)
Add the array values.
virtual eMode mode() const =0
Current operating mode.
virtual void getSpan(Span< Real > values)
Retrieve the array values.
virtual void reserveSpan(eBasicDataType dt, Int64 n)=0
Reserves memory for n values of dt.
Interface of the subdomain manager.
Definition ISubDomain.h:75
virtual const CommonVariables & commonVariables() const =0
Information on standard variables.
virtual IParallelMng * parallelMng()=0
Returns the parallelism manager.
virtual IMeshMng * meshMng() const =0
Returns the mesh manager.
virtual IVariableMng * variableMng()=0
Returns the variable manager.
Interface of the functor class for recalculating a variable.
Internal part of Ivariable.
virtual void removeVariable(IVariable *var)=0
Removes a variable.
Variable manager interface.
virtual IVariableMngInternal * _internalApi()=0
Internal Arcane API.
Interface of a variable.
Definition IVariable.h:40
virtual eDataType dataType() const =0
Data type managed by the variable (Real, Integer, ...).
eDependType
Dependency Type.
Definition IVariable.h:45
@ PSubDomainDepend
Indicates that the variable value is dependent on the subdomain.
Definition IVariable.h:81
@ PNoExchange
Indicates that the variable should not be exchanged.
Definition IVariable.h:130
@ PNoReplicaSync
Indicates that the variable does not necessarily have the same value across replicas.
Definition IVariable.h:147
@ PTemporary
Indicates that the variable is temporary.
Definition IVariable.h:114
@ PInShMem
Indicates that the variable must be allocated in shared memory.
Definition IVariable.h:156
@ PExecutionDepend
Indicates that the variable value is dependent on the execution.
Definition IVariable.h:96
@ PPrivate
Indicates that the variable is private.
Definition IVariable.h:103
@ PPersistant
Indicates that the variable is persistent.
Definition IVariable.h:138
@ PNoRestore
Indicates that the variable should not be restored.
Definition IVariable.h:120
@ PSubDomainPrivate
Indicates that the variable is private to the subdomain.
Definition IVariable.h:89
@ PNoNeedSync
Indicates that the variable is not necessarily synchronized.
Definition IVariable.h:70
@ PNoDump
Indicates that the variable should not be saved.
Definition IVariable.h:62
@ PDumpNull
Indicates that the save will be null for this variable and for this subdomain.
Definition IVariable.h:167
virtual eItemKind itemKind() const =0
Kind of mesh entities on which the variable is based.
virtual bool isPartial() const =0
Indicates if the variable is partial.
virtual Integer dimension() const =0
Dimension of the variable.
virtual IData * data()=0
Data associated with the variable.
virtual ItemGroup itemGroup() const =0
Associated mesh group.
static Int64 incrementModifiedTime()
Increments the modification counter and returns its value before modification.
Definition Variable.cc:206
virtual Integer multiTag() const =0
Indicates if the variable is a multi-sized array.
virtual void update()=0
Recalculates the variable if necessary.
static const char * TAG_POST_PROCESSING
Tag used to indicate if a variable will be post-processed.
Definition IVariable.h:173
static const char * TAG_POST_PROCESSING_AT_THIS_ITERATION
Tag used to indicate if a variable will be post-processed at this iteration.
Definition IVariable.h:176
Functor for a hash function.
void detachObserver(const void *ref)
Detaches an observer.
void executeExtend(const Int32ConstArrayView *info) override
Execute the action associated with the extension.
Definition Variable.cc:259
void executeReduce(const Int32ConstArrayView *info) override
Execute the action associated with the extension.
Definition Variable.cc:275
void executeInvalidate() override
Execute the action associated with invalidation.
Definition Variable.cc:325
void executeCompact(const Int32ConstArrayView *info) override
Executes the action associated with compaction.
Definition Variable.cc:314
bool needInfo() const override
Indicates whether the observer will need transition information.
Definition Variable.cc:333
Mesh entity group.
Definition ItemGroup.h:51
ItemGroupImpl * internal() const
Returns the group implementation.
Definition ItemGroup.h:125
SharedPtrT< GroupIndexTable > localIdToIndex() const
Table of local ids to a position for all entities in the group.
Definition ItemGroup.h:312
ItemVectorView view() const
View of the group entities.
Definition ItemGroup.cc:580
Integer size() const
Number of elements in the group.
Definition ItemGroup.h:93
bool isAllItems() const
Indicates if the group is that of all entities.
Definition ItemGroup.cc:607
bool null() const
true means the group is the null group
Definition ItemGroup.h:75
View on a vector of entities.
Handle on a mesh.
Definition MeshHandle.h:48
bool isNull() const
Indicates if the handle is null (it does not reference any existing mesh or not).
Definition MeshHandle.h:163
IMesh * mesh() const
Associated mesh.
Reference to an instance.
Encapsulation of an automatically destructing pointer.
Definition ScopedPtr.h:44
__host__ __device__ void fill(T o)
Fills the array with the value o.
Definition Span.h:383
View of an array of elements of type T.
Definition Span.h:635
constexpr __host__ __device__ Span< T, DynExtent > subspan(Int64 abegin, Int64 asize) const
Sub-view starting from element abegin and containing asize elements.
Definition Span.h:724
Unicode character string constructor.
String toString() const
Returns the constructed character string.
bool null() const
Returns true if the string is null.
Definition String.cc:306
Span< const Byte > bytes() const
Returns the conversion of the instance into UTF-8 encoding.
Definition String.cc:293
StringView view() const
Returns a view of the current string.
Definition String.cc:369
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium) const
Flow for a debug message.
ITraceMng * traceMng() const
Trace manager.
1D data vector with value semantics (STL style).
Parameters necessary for building a variable.
Arguments for VariableComparer methods.
void setMaxPrint(Int32 v)
Sets the number of errors to display in the listing.
void setCompareGhost(bool v)
Indicates on which entities the comparison is performed.
Results of a comparison operation.
Information about a variable dependency.
IVariable::eDependType dependType() const
Dependency type.
IVariable * variable() const
Variable.
Information characterizing a variable.
const String & itemFamilyName() const
Name of the entity family to which the variable is associated.
const String & meshName() const
Name of the mesh to which the variable is associated.
Metadata on a variable.
void resize(const VariableResizeArgs &resize_args) override
Resizes the variable by adding additional capacity.
Definition Variable.cc:1500
void changeAllocator(const MemoryAllocationOptions &alloc_info) override
Changes the variable's allocator.
Definition Variable.cc:1487
VariableComparerResults compareVariable(const VariableComparerArgs &compare_args) override
Applies the comparison method specified by compare_args.
Definition Variable.cc:1509
bool m_has_recursive_depend
True if dependencies are recursive.
Definition Variable.cc:121
IParallelMng * replicaParallelMng() const
Returns the IParallelMng of the mesh replica associated with the variable.
Definition Variable.cc:1518
VariableInfo m_infos
Characteristic information of the variable.
Definition Variable.cc:105
IItemFamily * m_item_family
Entity family (can be null).
Definition Variable.cc:104
Integer m_nb_reference
First reference on the variable.
Definition Variable.cc:113
UniqueArray< VariableDependInfo > m_depends
List of dependencies for this variable.
Definition Variable.cc:114
int m_property
Properties of the variable.
Definition Variable.cc:106
AutoDetachObservable m_on_size_changed_observable
Resize observable.
Definition Variable.cc:119
Byte m_hash_id[HASHID_SIZE]
Hash of the variable to check serialization consistency.
Definition Variable.cc:178
Real m_last_update_time
Physical time of the last update.
Definition Variable.cc:111
Int64 m_modified_time
Tag of the last modification.
Definition Variable.cc:115
MeshHandle m_mesh_handle
Mesh (can be null).
Definition Variable.cc:101
String computeComparisonHashCollective(IHashAlgorithm *hash_algo, IData *sorted_data) override
Calculates the comparison hash for the variable.
Definition Variable.cc:1453
std::map< String, String > m_tags
List of tags.
Definition Variable.cc:120
ItemGroup m_item_group
Entity group to which the variable is associated.
Definition Variable.cc:103
bool m_is_used
Usage status of the variable.
Definition Variable.cc:109
void serializeHashId(ISerializer *sbuf)
Serializes the hashid.
Definition Variable.cc:133
ScopedPtrT< IVariableComputeFunction > m_compute_function
Calculation function.
Definition Variable.cc:116
AutoDetachObservable m_read_observable
Read observable.
Definition Variable.cc:118
AutoDetachObservable m_write_observable
Write observable.
Definition Variable.cc:117
bool m_has_valid_data
True if the data is valid.
Definition Variable.cc:110
bool m_is_partial
True if the variable is partial.
Definition Variable.cc:107
Variable * m_variable
Associated variable.
Definition Variable.cc:123
Ref< IData > m_data
Variable data.
Definition Variable.cc:102
Reference to a variable.
Definition VariableRef.h:56
virtual void updateFromInternal()
Updates from the internal part.
void setPreviousReference(VariableRef *v)
Sets the previous reference.
VariableRef * previousReference()
Previous reference (or null) to variable().
virtual int referenceProperty() const
Reference properties (internal).
void setNextReference(VariableRef *v)
Sets the next reference.
VariableRef * nextReference()
Next reference (or null) to variable().
Arguments for resizing a variable.
Instance of a variable.
Definition Variable.h:77
void resizeFromGroup() override
Sets the number of elements for a mesh variable.
Definition Variable.cc:1021
String itemGroupName() const final
Name of the associated entity group.
Definition Variable.cc:511
IMesh * mesh() const final
Mesh associated with the variable.
Definition Variable.cc:844
void notifyBeginWrite() override
Notifies of the start of writing data().
Definition Variable.cc:1346
Integer nbReference() const override
Number of references on this variable.
Definition Variable.cc:457
void removeVariableRef(VariableRef *ref) override
Removes a reference to this variable.
Definition Variable.cc:395
void _checkSwapIsValid(Variable *rhs)
Checks if it is possible to swap the values of the instance with those of rhs.
Definition Variable.cc:1395
bool isUsed() const override
Usage state of the variable.
Definition Variable.cc:722
Variable(const VariableBuildInfo &v, const VariableInfo &vi)
Creates a variable linked to the reference v.
Definition Variable.cc:344
void _setData(const Ref< IData > &data)
Positions the data.
Definition Variable.cc:918
void _setValidData(bool valid_data)
Indicates if the variable data is valid.
Definition Variable.cc:933
VariableMetaData * createMetaData() const override
Creates an instance containing the variable's metadata.
Definition Variable.cc:768
IVariableComputeFunction * computeFunction() override
Function used to update the variable.
Definition Variable.cc:1271
Ref< VariableMetaData > createMetaDataRef() const override
Creates an instance containing the variable's metadata.
Definition Variable.cc:777
bool isPartial() const override
Indicates if the variable is partial.
Definition Variable.cc:900
String tagValue(const String &tagname) override
Value of the tag tagname. The string is null if the tag does not exist.
Definition Variable.cc:1322
void notifyReferencePropertyChanged() override
Definition Variable.cc:628
IVariableMng * variableMng() const override
Variable manager associated with the variable.
Definition Variable.cc:475
void removeTag(const String &tagname) override
Removes the tag tagname.
Definition Variable.cc:1304
void addDepend(IVariable *var, eDependType dt) override
Adds var to the list of dependencies.
Definition Variable.cc:1234
String name() const final
Variable name.
Definition Variable.cc:484
IObservable * readObservable() override
Read observable.
Definition Variable.cc:1140
virtual VariableComparerResults _compareVariable(const VariableComparerArgs &compare_args)=0
Comparison of values between variables.
void serialize(ISerializer *sbuffer, IDataOperation *operation) override
Definition Variable.cc:983
ItemGroup itemGroup() const final
Associated mesh group.
Definition Variable.cc:864
IObservable * onSizeChangedObservable() override
Size change observable.
Definition Variable.cc:1149
void notifyEndRead() override
Notifies of external modification of data().
Definition Variable.cc:1334
void read(IDataReader *d) override
Definition Variable.cc:1355
void syncReferences() override
Synchronizes references.
Definition Variable.cc:786
void setUsed(bool v) override
Sets the usage state of the variable.
Definition Variable.cc:637
VariableRef * firstReference() const override
First reference (or null) on this variable.
Definition Variable.cc:432
String fullName() const final
Full variable name (with family prefix).
Definition Variable.cc:493
eItemKind itemKind() const override
Kind of mesh entities on which the variable is based.
Definition Variable.cc:873
ISubDomain * subDomain() override
Subdomain associated with the variable (TODO deprecate end of 2023).
Definition Variable.cc:466
void update() override
Recalculates the variable if necessary.
Definition Variable.cc:1161
Integer dimension() const override
Dimension of the variable.
Definition Variable.cc:882
Int64 modifiedTime() override
Time when the variable was updated.
Definition Variable.cc:1225
void setUpToDate() override
Indicates that the variable has just been updated.
Definition Variable.cc:1215
void addTag(const String &tagname, const String &tagvalue) override
Adds the tag tagname with the value tagvalue.
Definition Variable.cc:1295
Int32 checkIfSame(IDataReader *reader, Integer max_print, bool compare_ghost) final
Checks that the variable is identical to a reference value.
Definition Variable.cc:830
~Variable() override
Frees resources.
Definition Variable.cc:354
bool _hasValidData() const
Indicates if the variable data is valid.
Definition Variable.cc:942
IObservable * writeObservable() override
Write observable.
Definition Variable.cc:1131
void addVariableRef(VariableRef *ref) override
Adds a reference to this variable.
Definition Variable.cc:374
Integer multiTag() const override
Indicates if the variable is a multi-sized array.
Definition Variable.cc:891
void setComputeFunction(IVariableComputeFunction *v) override
Sets the variable's recalculation function.
Definition Variable.cc:1262
void resize(Integer n) override
Sets the number of elements for an array variable.
Definition Variable.cc:1012
IVariableInternal * _internalApi() override
Internal Arcane API.
Definition Variable.cc:1441
IItemFamily * itemFamily() const final
Associated entity family.
Definition Variable.cc:909
eDataType dataType() const override
Data type managed by the variable (Real, Integer, ...).
Definition Variable.cc:529
void write(IDataWriter *d) override
Saves the variable.
Definition Variable.cc:1365
IDataFactoryMng * dataFactoryMng() const final
Data factory associated with the variable.
Definition Variable.cc:960
void changeGroupIds(Int32ConstArrayView old_to_new_ids) override
pH: EXPERIMENTAL
Definition Variable.cc:1375
void removeDepend(IVariable *var) override
Removes var from the list of dependencies.
Definition Variable.cc:1252
VariablePrivate * m_p
Implementation.
Definition Variable.h:237
String itemFamilyName() const final
Name of the associated family (null if none).
Definition Variable.cc:502
Int32 checkIfSync(Integer max_print) final
Checks if the variable is properly synchronized.
Definition Variable.cc:803
DataAllocationInfo allocationInfo() const override
Allocation information.
Definition Variable.cc:1432
int property() const override
Definition Variable.cc:541
Int32 checkIfSameOnAllReplica(Integer max_print) final
Checks if the variable has the same values on all replicas.
Definition Variable.cc:817
void dependInfos(Array< VariableDependInfo > &infos) override
Dependency information.
Definition Variable.cc:1280
bool hasTag(const String &tagname) override
true if the variable has the tag tagname
Definition Variable.cc:1313
void setAllocationInfo(const DataAllocationInfo &v) override
Sets allocation information.
Definition Variable.cc:1420
MeshHandle meshHandle() const final
Mesh associated with the variable.
Definition Variable.cc:855
String meshName() const final
Name of the associated mesh (null if none).
Definition Variable.cc:520
String toHexaString(ByteConstArrayView input)
Converts a byte array to its hexadecimal representation.
String getEnvironmentVariable(const String &name)
Environment variable named name.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
@ DIP_Legacy
Initialization in historical mode.
Definition DataTypes.h:166
std::int64_t Int64
Signed integer type of 64 bits.
eDataInitialisationPolicy getGlobalDataInitialisationPolicy()
Gets the initialization policy for variables.
Definition DataTypes.cc:164
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:482
UniqueArray< Int32 > Int32UniqueArray
Dynamic 1D array of 32-bit integers.
Definition UtilsTypes.h:341
@ SameOnAllReplica
Checks that the variable values are the same on all replicas.
@ Sync
Checks that the variable is synchronized.
eItemKind
Mesh entity type.
@ IK_Particle
Particle mesh entity.
@ IK_Unknown
Unknown or uninitialized mesh entity.
@ IK_DoF
Degree of Freedom mesh entity.
const char * itemKindName(eItemKind kind)
Entity kind name.
double Real
Type representing a real number.
Impl::SpanTypeFromSize< conststd::byte, SizeType >::SpanType asBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converts the view into an array of non-modifiable bytes.
Definition Span.h:1032
unsigned char Byte
Type of a byte.
Definition BaseTypes.h:43
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Creates a reference on a pointer.
eDataType
Data type.
Definition DataTypes.h:41
const char * dataTypeName(eDataType type)
Data type name.
Definition DataTypes.cc:72
std::int32_t Int32
Signed integer type of 32 bits.
Span< DataType > asSpan(Span< std::byte, Extent > bytes)
Converts a Span<std::byte> into a Span<DataType>.
Definition Span.h:1126