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"
21#include "arcane/core/ItemGroupObserver.h"
22#include "arcane/core/IItemFamily.h"
23#include "arcane/core/IMesh.h"
24#include "arcane/core/ItemPrinter.h"
25#include "arcane/core/MeshPartInfo.h"
27#include "arcane/core/internal/IDataInternal.h"
41, m_sub_parts_by_type(this)
50ItemGroupInternal(IItemFamily* family,
const String& name)
52, m_mesh(family->mesh())
53, m_item_family(family)
54, m_variable_name(String(
"GROUP_") + family->name() + name)
56, m_kind(family->itemKind())
58, m_sub_parts_by_type(this)
67ItemGroupInternal(IItemFamily* family, ItemGroupImpl* parent,
const String& name)
69, m_mesh(parent->mesh())
70, m_item_family(family)
72, m_variable_name(String(
"GROUP_") + m_item_family->name() + name)
74, m_kind(family->itemKind())
76, m_sub_parts_by_type(this)
89 for (
const auto& i : m_observers) {
92 delete m_variable_items_local_id;
93 delete m_compute_functor;
99void ItemGroupInternal::
103 m_full_name = m_item_family->fullName() +
"_" + m_name;
107 if (m_mesh && !m_parent) {
108 int property = IVariable::PSubDomainDepend | IVariable::PPrivate;
109 VariableBuildInfo vbi(m_mesh, m_variable_name, property);
111 m_items_local_id = &m_variable_items_local_id->_internalTrueData()->_internalDeprecatedValue();
116 if (
auto v = Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_CHECK_SIMDPADDING",
true)) {
117 m_is_check_simd_padding = (v.value() > 0);
118 m_is_print_check_simd_padding = (v.value() > 1);
121 if (
auto v = Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_PRINT_APPLYSIMDPADDING",
true)) {
122 m_is_print_apply_simd_padding = (v.value() > 0);
123 m_is_print_stack_apply_simd_padding = (v.value() > 1);
126 if (
auto v = Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_USE_LOCK_FOR_ITEMGROUP_UPDATE",
true)) {
128 m_check_need_update_mutex.create();
139 return m_item_family->itemsInternal();
140 return m_mesh->itemsInternal(m_kind);
146Int32 ItemGroupInternal::
149 return m_item_family->maxLocalId();
155ItemInfoListView ItemGroupInternal::
156itemInfoListView()
const
159 return m_item_family->itemInfoListView();
160 return m_mesh->itemFamily(m_kind)->itemInfoListView();
166void ItemGroupInternal::
170 ARCANE_FATAL(
"Call to _resetSubGroups() is only valid for group of AllItems");
172 m_own_group =
nullptr;
173 m_ghost_group =
nullptr;
174 m_interface_group =
nullptr;
175 m_node_group =
nullptr;
176 m_edge_group =
nullptr;
177 m_face_group =
nullptr;
178 m_cell_group =
nullptr;
179 m_inner_face_group =
nullptr;
180 m_outer_face_group =
nullptr;
181 m_active_cell_group =
nullptr;
182 m_own_active_cell_group =
nullptr;
183 m_active_face_group =
nullptr;
184 m_own_active_face_group =
nullptr;
185 m_inner_active_face_group =
nullptr;
186 m_outer_active_face_group =
nullptr;
187 m_level_cell_group.clear();
188 m_own_level_cell_group.clear();
189 m_sub_parts_by_type.clear();
190 m_sub_groups.clear();
196void ItemGroupInternal::
197notifyExtendObservers(
const Int32ConstArrayView* info)
199 ARCANE_ASSERT((!m_need_recompute || m_is_all_items), (
"Operation on invalid group"));
200 for (
const auto& i : m_observers) {
201 IItemGroupObserver* obs = i.second;
202 obs->executeExtend(info);
204 if (m_group_index_table.isUsed())
205 m_group_index_table->update();
211void ItemGroupInternal::
212notifyReduceObservers(
const Int32ConstArrayView* info)
214 ARCANE_ASSERT((!m_need_recompute || m_is_all_items), (
"Operation on invalid group"));
215 for (
const auto& i : m_observers) {
216 IItemGroupObserver* obs = i.second;
217 obs->executeReduce(info);
219 if (m_group_index_table.isUsed())
220 m_group_index_table->update();
226void ItemGroupInternal::
227notifyCompactObservers(
const Int32ConstArrayView* info)
229 ARCANE_ASSERT((!m_need_recompute || m_is_all_items), (
"Operation on invalid group"));
230 for (
const auto& i : m_observers) {
231 IItemGroupObserver* obs = i.second;
232 obs->executeCompact(info);
234 if (m_group_index_table.isUsed())
235 m_group_index_table->compact(info);
241void ItemGroupInternal::
242notifyInvalidateObservers()
244#ifndef NO_USER_WARNING
245#warning "(HP) Assertion need fix"
249 for (
const auto& i : m_observers) {
250 IItemGroupObserver* obs = i.second;
251 obs->executeInvalidate();
253 if (m_group_index_table.isUsed())
254 m_group_index_table->update();
263void ItemGroupInternal::
266 m_is_contiguous =
false;
269 m_is_contiguous =
false;
272 Int32 first_lid = lids[0];
275 for (Integer i = 0, n = lids.size(); i < n; ++i) {
276 if (lids[i] != (first_lid + i)) {
282 m_is_contiguous =
true;
288void ItemGroupInternal::
291 if (m_is_print_apply_simd_padding) {
293 if (m_is_print_stack_apply_simd_padding)
294 stack = String(
" stack=") + platform::getStackTrace();
295 ITraceMng* tm = m_item_family->traceMng();
296 tm->info() <<
"ApplySimdPadding group_name=" << m_name << stack;
300 m_internal_api.notifySimdPaddingDone();
301 Arcane::applySimdPadding(mutableItemsLocalId());
331void ItemGroupInternal::
332checkUpdateSimdPadding()
334 if (m_simd_timestamp >= timestamp()) {
336 if (m_is_check_simd_padding) {
337 if (m_is_print_check_simd_padding && m_item_family) {
338 ITraceMng* tm = m_item_family->traceMng();
339 tm->info() <<
"check padding name=" << fullName()
340 <<
" timestamp=" << timestamp()
341 <<
" simd_timestamp=" << m_simd_timestamp
342 <<
" size=" << mutableItemsLocalId().size()
343 <<
" capacity=" << mutableItemsLocalId().capacity();
345 ArrayUtils::checkSimdPadding(itemsLocalId());
349 this->applySimdPadding();
355void ItemGroupInternal::
356_removeItems(SmallSpan<const Int32> items_local_id)
358 if (!((!m_need_recompute && !isAllItems()) || (m_transaction_mode && isAllItems())))
361 if (m_compute_functor && !m_transaction_mode)
362 ARCANE_FATAL(
"Cannot remove items on computed group ({0})", name());
364 IMesh* amesh = mesh();
366 throw ArgumentException(A_FUNCINFO,
"null group");
368 ITraceMng* trace = amesh->traceMng();
369 if (isOwn() && amesh->meshPartInfo().nbPart() != 1)
370 ARCANE_THROW(NotSupportedException,
"Cannot remove items if isOwn() is true");
372 Int32 nb_item_to_remove = items_local_id.size();
375 UniqueArray<Int32> removed_local_ids;
377 if (nb_item_to_remove != 0) {
379 Int32Array& items_lid = mutableItemsLocalId();
380 const Int32 old_size = items_lid.size();
381 bool has_removed =
false;
390 for (Integer i = 0, n = nb_item_to_remove; i < n; ++i) {
391 Int32 removed_local_id = items_local_id[i];
392 Int32 index = m_items_index_in_all_group[removed_local_id];
394 Int32 moved_local_id = items_lid[nb_item];
395 items_lid[index] = moved_local_id;
396 m_items_index_in_all_group[moved_local_id] = index;
398 items_lid.resize(nb_item);
405 UniqueArray<bool> remove_flags(maxLocalId(),
false);
406 for (Int32 i = 0; i < nb_item_to_remove; ++i)
407 remove_flags[items_local_id[i]] =
true;
410 Int32 next_index = 0;
411 for (Int32 i = 0; i < old_size; ++i) {
412 Int32 lid = items_lid[i];
413 if (remove_flags[lid]) {
414 removed_local_ids.add(lid);
417 items_lid[next_index] = lid;
420 if (next_index != old_size) {
422 items_lid.resize(next_index);
429 trace->info(5) <<
"ItemGroupImpl::removeItems() group <" << name() <<
"> "
430 <<
" old_size=" << old_size
431 <<
" new_size=" << nbItem()
432 <<
" removed?=" << has_removed;
438 notifyReduceObservers(&observation_info);
444void ItemGroupInternal::
447 ITraceMng* msg = mesh()->traceMng();
448 if (m_need_recompute && m_compute_functor) {
449 msg->debug(Trace::High) <<
"ItemGroupImpl::checkValid on " << name() <<
" : skip group to recompute";
456 UniqueArray<bool> presence_checks(maxLocalId());
457 presence_checks.fill(0);
461 Integer items_size = items.size();
464 for (Integer i = 0, is = items_lid.size(); i < is; ++i) {
466 if (lid >= items_size) {
468 msg->error() <<
"Wrong local index lid=" << lid <<
" max=" << items_size
469 <<
" var_max_size=" << maxLocalId();
474 ItemInternal* item = items[lid];
475 if (item->isSuppressed()) {
477 msg->error() <<
"Item " << ItemPrinter(item) <<
" in group "
478 << name() <<
" does not exist anymore";
482 if (presence_checks[lid]) {
484 msg->error() <<
"Item " << ItemPrinter(item) <<
" in group "
485 << name() <<
" was found twice or more";
489 presence_checks[lid] =
true;
492 for (Integer i = 0, n = items_lid.size(); i < n; ++i) {
493 Int32 local_id = items_lid[i];
494 Int32 index_in_all_group = m_items_index_in_all_group[local_id];
495 if (index_in_all_group != i) {
497 msg->error() << A_FUNCINFO
499 <<
": incoherence between 'local_id' and index in the group 'All' "
501 <<
" local_id=" << local_id
502 <<
" index=" << index_in_all_group;
509 String parent_name =
"none";
511 parent_name = m_parent->name();
512 ARCANE_FATAL(
"Error in group name='{0}' parent='{1}' nb_error={2}",
513 name(), parent_name, nb_error);
520void ItemGroupInternal::
521_notifyDirectRemoveItems(SmallSpan<const Int32> removed_ids, Int32 nb_remaining)
523 mutableItemsLocalId().resize(nb_remaining);
530 notifyReduceObservers(&observation_info);
539void ItemGroupImplInternal::
540setAsConstituentGroup()
542 m_p->m_is_constituent_group =
true;
548SmallSpan<Int32> ItemGroupImplInternal::
551 return m_p->itemsLocalId();
557void ItemGroupImplInternal::
558notifyDirectRemoveItems(SmallSpan<const Int32> removed_ids, Int32 nb_remaining)
560 m_p->_notifyDirectRemoveItems(removed_ids, nb_remaining);
566void ItemGroupImplInternal::
567notifySimdPaddingDone()
569 m_p->m_simd_timestamp = m_p->timestamp();
575void ItemGroupImplInternal::
576setMemoryRessourceForItemLocalId(eMemoryRessource mem)
580 VariableUtils::experimentalChangeAllocator(v->variable(), mem);
#define ARCANE_THROW(exception_class,...)
Macro for throwing an exception with formatting.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Utility functions for variables.
VariableRefArrayT< Int32 > VariableArrayInt32
Array variable of 32-bit integer type.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
bool arcaneIsCheck()
True if running in check mode.
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
ConstArrayView< ItemInternal * > ItemInternalList
Type of the internal list of entities.
const char * itemKindName(eItemKind kind)
Entity kind name.
Array< Int32 > Int32Array
Dynamic one-dimensional array of 32-bit integers.