14#include "arcane/core/internal/ItemGroupInternal.h"
16#include "arcane/utils/PlatformUtils.h"
17#include "arcane/utils/ITraceMng.h"
18#include "arcane/utils/ArrayUtils.h"
19#include "arcane/utils/ArgumentException.h"
20#include "arcane/utils/Convert.h"
22#include "arcane/core/ItemGroupObserver.h"
23#include "arcane/core/IItemFamily.h"
24#include "arcane/core/IMesh.h"
25#include "arcane/core/ItemPrinter.h"
26#include "arcane/core/MeshPartInfo.h"
28#include "arcane/core/internal/IDataInternal.h"
42, m_sub_parts_by_type(this)
51ItemGroupInternal(IItemFamily* family,
const String& name)
53, m_mesh(family->mesh())
54, m_item_family(family)
55, m_variable_name(String(
"GROUP_") + family->name() + name)
57, m_kind(family->itemKind())
59, m_sub_parts_by_type(this)
68ItemGroupInternal(IItemFamily* family, ItemGroupImpl* parent,
const String& name)
70, m_mesh(parent->mesh())
71, m_item_family(family)
73, m_variable_name(String(
"GROUP_") + m_item_family->name() + name)
75, m_kind(family->itemKind())
77, m_sub_parts_by_type(this)
90 for (
const auto& i : m_observers) {
93 delete m_variable_items_local_id;
94 delete m_compute_functor;
100void ItemGroupInternal::
104 m_full_name = m_item_family->fullName() +
"_" + m_name;
108 if (m_mesh && !m_parent) {
109 int property = IVariable::PSubDomainDepend | IVariable::PPrivate;
110 VariableBuildInfo vbi(m_mesh, m_variable_name, property);
112 m_items_local_id = &m_variable_items_local_id->_internalTrueData()->_internalDeprecatedValue();
117 if (
auto v = Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_CHECK_SIMDPADDING",
true)) {
118 m_is_check_simd_padding = (v.value() > 0);
119 m_is_print_check_simd_padding = (v.value() > 1);
122 if (
auto v = Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_PRINT_APPLYSIMDPADDING",
true)) {
123 m_is_print_apply_simd_padding = (v.value() > 0);
124 m_is_print_stack_apply_simd_padding = (v.value() > 1);
127 if (
auto v = Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_USE_LOCK_FOR_ITEMGROUP_UPDATE",
true)) {
129 m_check_need_update_mutex.create();
140 return m_item_family->itemsInternal();
141 return m_mesh->itemsInternal(m_kind);
147Int32 ItemGroupInternal::
150 return m_item_family->maxLocalId();
156ItemInfoListView ItemGroupInternal::
157itemInfoListView()
const
160 return m_item_family->itemInfoListView();
161 return m_mesh->itemFamily(m_kind)->itemInfoListView();
167void ItemGroupInternal::
171 ARCANE_FATAL(
"Call to _resetSubGroups() is only valid for group of AllItems");
173 m_own_group =
nullptr;
174 m_ghost_group =
nullptr;
175 m_interface_group =
nullptr;
176 m_node_group =
nullptr;
177 m_edge_group =
nullptr;
178 m_face_group =
nullptr;
179 m_cell_group =
nullptr;
180 m_inner_face_group =
nullptr;
181 m_outer_face_group =
nullptr;
182 m_active_cell_group =
nullptr;
183 m_own_active_cell_group =
nullptr;
184 m_active_face_group =
nullptr;
185 m_own_active_face_group =
nullptr;
186 m_inner_active_face_group =
nullptr;
187 m_outer_active_face_group =
nullptr;
188 m_level_cell_group.clear();
189 m_own_level_cell_group.clear();
190 m_sub_parts_by_type.clear();
191 m_sub_groups.clear();
197void ItemGroupInternal::
198notifyExtendObservers(
const Int32ConstArrayView* info)
200 ARCANE_ASSERT((!m_need_recompute || m_is_all_items), (
"Operation on invalid group"));
201 for (
const auto& i : m_observers) {
202 IItemGroupObserver* obs = i.second;
203 obs->executeExtend(info);
205 if (m_group_index_table.isUsed())
206 m_group_index_table->update();
212void ItemGroupInternal::
213notifyReduceObservers(
const Int32ConstArrayView* info)
215 ARCANE_ASSERT((!m_need_recompute || m_is_all_items), (
"Operation on invalid group"));
216 for (
const auto& i : m_observers) {
217 IItemGroupObserver* obs = i.second;
218 obs->executeReduce(info);
220 if (m_group_index_table.isUsed())
221 m_group_index_table->update();
227void ItemGroupInternal::
228notifyCompactObservers(
const Int32ConstArrayView* info)
230 ARCANE_ASSERT((!m_need_recompute || m_is_all_items), (
"Operation on invalid group"));
231 for (
const auto& i : m_observers) {
232 IItemGroupObserver* obs = i.second;
233 obs->executeCompact(info);
235 if (m_group_index_table.isUsed())
236 m_group_index_table->compact(info);
242void ItemGroupInternal::
243notifyInvalidateObservers()
245#ifndef NO_USER_WARNING
246#warning "(HP) Assertion need fix"
250 for (
const auto& i : m_observers) {
251 IItemGroupObserver* obs = i.second;
252 obs->executeInvalidate();
254 if (m_group_index_table.isUsed())
255 m_group_index_table->update();
264void ItemGroupInternal::
267 m_is_contiguous =
false;
270 m_is_contiguous =
false;
273 Int32 first_lid = lids[0];
276 for (Integer i = 0, n = lids.size(); i < n; ++i) {
277 if (lids[i] != (first_lid + i)) {
283 m_is_contiguous =
true;
289void ItemGroupInternal::
292 if (m_is_print_apply_simd_padding) {
294 if (m_is_print_stack_apply_simd_padding)
295 stack = String(
" stack=") + platform::getStackTrace();
296 ITraceMng* tm = m_item_family->traceMng();
297 tm->info() <<
"ApplySimdPadding group_name=" << m_name << stack;
301 m_internal_api.notifySimdPaddingDone();
302 Arcane::applySimdPadding(mutableItemsLocalId());
334void ItemGroupInternal::
335checkUpdateSimdPadding()
337 if (m_simd_timestamp >= timestamp()) {
339 if (m_is_check_simd_padding) {
340 if (m_is_print_check_simd_padding && m_item_family) {
341 ITraceMng* tm = m_item_family->traceMng();
342 tm->info() <<
"check padding name=" << fullName()
343 <<
" timestamp=" << timestamp()
344 <<
" simd_timestamp=" << m_simd_timestamp
345 <<
" size=" << mutableItemsLocalId().size()
346 <<
" capacity=" << mutableItemsLocalId().capacity();
348 ArrayUtils::checkSimdPadding(itemsLocalId());
352 this->applySimdPadding();
358void ItemGroupInternal::
359_removeItems(SmallSpan<const Int32> items_local_id)
361 if (!((!m_need_recompute && !isAllItems()) || (m_transaction_mode && isAllItems())))
364 if (m_compute_functor && !m_transaction_mode)
365 ARCANE_FATAL(
"Cannot remove items on computed group ({0})", name());
367 IMesh* amesh = mesh();
369 throw ArgumentException(A_FUNCINFO,
"null group");
371 ITraceMng* trace = amesh->traceMng();
372 if (isOwn() && amesh->meshPartInfo().nbPart() != 1)
373 ARCANE_THROW(NotSupportedException,
"Cannot remove items if isOwn() is true");
375 Int32 nb_item_to_remove = items_local_id.size();
378 UniqueArray<Int32> removed_local_ids;
380 if (nb_item_to_remove != 0) {
382 Int32Array& items_lid = mutableItemsLocalId();
383 const Int32 old_size = items_lid.size();
384 bool has_removed =
false;
393 for (Integer i = 0, n = nb_item_to_remove; i < n; ++i) {
394 Int32 removed_local_id = items_local_id[i];
395 Int32 index = m_items_index_in_all_group[removed_local_id];
397 Int32 moved_local_id = items_lid[nb_item];
398 items_lid[index] = moved_local_id;
399 m_items_index_in_all_group[moved_local_id] = index;
401 items_lid.resize(nb_item);
408 UniqueArray<bool> remove_flags(maxLocalId(),
false);
409 for (Int32 i = 0; i < nb_item_to_remove; ++i)
410 remove_flags[items_local_id[i]] =
true;
413 Int32 next_index = 0;
414 for (Int32 i = 0; i < old_size; ++i) {
415 Int32 lid = items_lid[i];
416 if (remove_flags[lid]) {
417 removed_local_ids.add(lid);
420 items_lid[next_index] = lid;
423 if (next_index != old_size) {
425 items_lid.resize(next_index);
432 trace->info(5) <<
"ItemGroupImpl::removeItems() group <" << name() <<
"> "
433 <<
" old_size=" << old_size
434 <<
" new_size=" << nbItem()
435 <<
" removed?=" << has_removed;
441 notifyReduceObservers(&observation_info);
447void ItemGroupInternal::
450 ITraceMng* msg = mesh()->traceMng();
451 if (m_need_recompute && m_compute_functor) {
452 msg->debug(Trace::High) <<
"ItemGroupImpl::checkValid on " << name() <<
" : skip group to recompute";
459 UniqueArray<bool> presence_checks(maxLocalId());
460 presence_checks.fill(0);
464 Integer items_size = items.size();
467 for (Integer i = 0, is = items_lid.size(); i < is; ++i) {
469 if (lid >= items_size) {
471 msg->error() <<
"Wrong local index lid=" << lid <<
" max=" << items_size
472 <<
" var_max_size=" << maxLocalId();
477 ItemInternal* item = items[lid];
478 if (item->isSuppressed()) {
480 msg->error() <<
"Item " << ItemPrinter(item) <<
" in group "
481 << name() <<
" does not exist anymore";
485 if (presence_checks[lid]) {
487 msg->error() <<
"Item " << ItemPrinter(item) <<
" in group "
488 << name() <<
" was found twice or more";
492 presence_checks[lid] =
true;
495 for (Integer i = 0, n = items_lid.size(); i < n; ++i) {
496 Int32 local_id = items_lid[i];
497 Int32 index_in_all_group = m_items_index_in_all_group[local_id];
498 if (index_in_all_group != i) {
500 msg->error() << A_FUNCINFO
502 <<
": incoherence between 'local_id' and index in the group 'All' "
504 <<
" local_id=" << local_id
505 <<
" index=" << index_in_all_group;
512 String parent_name =
"none";
514 parent_name = m_parent->name();
515 ARCANE_FATAL(
"Error in group name='{0}' parent='{1}' nb_error={2}",
516 name(), parent_name, nb_error);
523void ItemGroupInternal::
524_notifyDirectRemoveItems(SmallSpan<const Int32> removed_ids, Int32 nb_remaining)
526 mutableItemsLocalId().resize(nb_remaining);
533 notifyReduceObservers(&observation_info);
542void ItemGroupImplInternal::
543setAsConstituentGroup()
545 m_p->m_is_constituent_group =
true;
551SmallSpan<Int32> ItemGroupImplInternal::
554 return m_p->itemsLocalId();
560void ItemGroupImplInternal::
561notifyDirectRemoveItems(SmallSpan<const Int32> removed_ids, Int32 nb_remaining)
563 m_p->_notifyDirectRemoveItems(removed_ids, nb_remaining);
569void ItemGroupImplInternal::
570notifySimdPaddingDone()
572 m_p->m_simd_timestamp = m_p->timestamp();
578void ItemGroupImplInternal::
579setMemoryRessourceForItemLocalId(eMemoryRessource mem)
583 VariableUtils::experimentalChangeAllocator(v->variable(), mem);
#define ARCANE_THROW(exception_class,...)
Macro pour envoyer une exception avec formattage.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Fonctions utilitaires sur les variables.
VariableRefArrayT< Int32 > VariableArrayInt32
Variable tableau de type entier 32 bits.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
bool arcaneIsCheck()
Vrai si on est en mode vérification.
Int32 Integer
Type représentant un entier.
ConstArrayView< Int32 > Int32ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
ConstArrayView< ItemInternal * > ItemInternalList
Type de la liste interne des entités.
const char * itemKindName(eItemKind kind)
Nom du genre d'entité.
Array< Int32 > Int32Array
Tableau dynamique à une dimension d'entiers 32 bits.