14#include "arcane/core/internal/ItemGroupInternal.h"
16#include "arcane/utils/ValueConvert.h"
17#include "arcane/utils/PlatformUtils.h"
18#include "arcane/utils/ITraceMng.h"
19#include "arcane/utils/ArrayUtils.h"
20#include "arcane/utils/ArgumentException.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"
29#include "arcane/core/internal/ItemGroupImplInternal.h"
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())
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())
88 for(
const auto& i : m_observers ) {
91 delete m_variable_items_local_id;
92 delete m_compute_functor;
98void ItemGroupInternal::
102 m_full_name = m_item_family->fullName() +
"_" + m_name;
106 if (m_mesh && !m_parent){
107 int property = IVariable::PSubDomainDepend | IVariable::PPrivate;
108 VariableBuildInfo vbi(m_mesh,m_variable_name,property);
110 m_items_local_id = &m_variable_items_local_id->_internalTrueData()->_internalDeprecatedValue();
115 if (
auto v = Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_APPLYOPERATION_VERSION",
true))
116 m_use_v2_for_apply_operation = (v.value()==2);
118 if (
auto v = Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_DEBUG_APPLYOPERATION",
true))
119 m_is_debug_apply_operation = (v.value()>0);
122 if (
auto v = Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_CHECK_SIMDPADDING",
true)){
123 m_is_check_simd_padding = (v.value()>0);
124 m_is_print_check_simd_padding = (v.value()>1);
127 if (
auto v = Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_PRINT_APPLYSIMDPADDING",
true)){
128 m_is_print_apply_simd_padding = (v.value()>0);
129 m_is_print_stack_apply_simd_padding = (v.value()>1);
132 if (
auto v = Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_USE_LOCK_FOR_ITEMGROUP_UPDATE",
true)) {
134 m_check_need_update_mutex.create();
145 return m_item_family->itemsInternal();
146 return m_mesh->itemsInternal(m_kind);
152Int32 ItemGroupInternal::
155 return m_item_family->maxLocalId();
161ItemInfoListView ItemGroupInternal::
162itemInfoListView()
const
165 return m_item_family->itemInfoListView();
166 return m_mesh->itemFamily(m_kind)->itemInfoListView();
172void ItemGroupInternal::
176 ARCANE_FATAL(
"Call to _resetSubGroups() is only valid for group of AllItems");
178 m_own_group =
nullptr;
179 m_ghost_group =
nullptr;
180 m_interface_group =
nullptr;
181 m_node_group =
nullptr;
182 m_edge_group =
nullptr;
183 m_face_group =
nullptr;
184 m_cell_group =
nullptr;
185 m_inner_face_group =
nullptr;
186 m_outer_face_group =
nullptr;
187 m_active_cell_group =
nullptr;
188 m_own_active_cell_group =
nullptr;
189 m_active_face_group =
nullptr;
190 m_own_active_face_group =
nullptr;
191 m_inner_active_face_group =
nullptr;
192 m_outer_active_face_group =
nullptr;
193 m_level_cell_group.clear();
194 m_own_level_cell_group.clear();
195 m_children_by_type.clear();
196 m_children_by_type_ids.clear();
197 m_sub_groups.clear();
203void ItemGroupInternal::
204notifyExtendObservers(
const Int32ConstArrayView * info)
206 ARCANE_ASSERT((!m_need_recompute || m_is_all_items),(
"Operation on invalid group"));
207 for(
const auto& i : m_observers ) {
208 IItemGroupObserver * obs = i.second;
209 obs->executeExtend(info);
211 if (m_group_index_table.isUsed())
212 m_group_index_table->update();
218void ItemGroupInternal::
219notifyReduceObservers(
const Int32ConstArrayView * info)
221 ARCANE_ASSERT((!m_need_recompute || m_is_all_items),(
"Operation on invalid group"));
222 for(
const auto& i : m_observers ) {
223 IItemGroupObserver * obs = i.second;
224 obs->executeReduce(info);
226 if (m_group_index_table.isUsed())
227 m_group_index_table->update();
233void ItemGroupInternal::
234notifyCompactObservers(
const Int32ConstArrayView * info)
236 ARCANE_ASSERT((!m_need_recompute || m_is_all_items),(
"Operation on invalid group"));
237 for(
const auto& i : m_observers ) {
238 IItemGroupObserver * obs = i.second;
239 obs->executeCompact(info);
241 if (m_group_index_table.isUsed())
242 m_group_index_table->compact(info);
248void ItemGroupInternal::
249notifyInvalidateObservers()
251#ifndef NO_USER_WARNING
252#warning "(HP) Assertion need fix"
256 for(
const auto& i : m_observers ) {
257 IItemGroupObserver * obs = i.second;
258 obs->executeInvalidate();
260 if (m_group_index_table.isUsed())
261 m_group_index_table->update();
269void ItemGroupInternal::
272 m_is_contiguous =
false;
275 m_is_contiguous =
false;
278 Int32 first_lid = lids[0];
281 for( Integer i=0, n=lids.size(); i<n; ++i ){
282 if (lids[i]!=(first_lid+i)){
288 m_is_contiguous =
true;
294void ItemGroupInternal::
297 if (m_is_print_apply_simd_padding){
299 if (m_is_print_stack_apply_simd_padding)
300 stack = String(
" stack=") + platform::getStackTrace();
301 ITraceMng* tm = m_item_family->traceMng();
302 tm->info() <<
"ApplySimdPadding group_name=" << m_name << stack;
306 m_internal_api.notifySimdPaddingDone();
307 Arcane::applySimdPadding(mutableItemsLocalId());
338void ItemGroupInternal::
339checkUpdateSimdPadding()
341 if (m_simd_timestamp >= timestamp()){
343 if (m_is_check_simd_padding){
344 if (m_is_print_check_simd_padding && m_item_family){
345 ITraceMng* tm = m_item_family->traceMng();
346 tm->info() <<
"check padding name=" << fullName()
347 <<
" timestamp=" << timestamp()
348 <<
" simd_timestamp=" << m_simd_timestamp
349 <<
" size=" << mutableItemsLocalId().size()
350 <<
" capacity=" << mutableItemsLocalId().capacity();
352 ArrayUtils::checkSimdPadding(itemsLocalId());
356 this->applySimdPadding();
362void ItemGroupInternal::
363_removeItems(SmallSpan<const Int32> items_local_id)
365 if ( !((!m_need_recompute && !isAllItems()) || (m_transaction_mode && isAllItems())) )
368 if (m_compute_functor && !m_transaction_mode)
369 ARCANE_FATAL(
"Cannot remove items on computed group ({0})", name());
371 IMesh* amesh = mesh();
373 throw ArgumentException(A_FUNCINFO,
"null group");
375 ITraceMng* trace = amesh->traceMng();
376 if (isOwn() && amesh->meshPartInfo().nbPart()!=1)
377 ARCANE_THROW(NotSupportedException,
"Cannot remove items if isOwn() is true");
379 Int32 nb_item_to_remove = items_local_id.size();
382 UniqueArray<Int32> removed_local_ids;
384 if (nb_item_to_remove!=0) {
386 Int32Array& items_lid = mutableItemsLocalId();
387 const Int32 old_size = items_lid.size();
388 bool has_removed =
false;
397 for( Integer i=0, n=nb_item_to_remove; i<n; ++i ){
398 Int32 removed_local_id = items_local_id[i];
399 Int32 index = m_items_index_in_all_group[removed_local_id];
401 Int32 moved_local_id = items_lid[nb_item];
402 items_lid[index] = moved_local_id;
403 m_items_index_in_all_group[moved_local_id] = index;
405 items_lid.resize(nb_item);
412 UniqueArray<bool> remove_flags(maxLocalId(),
false);
413 for( Int32 i=0; i<nb_item_to_remove; ++i )
414 remove_flags[items_local_id[i]] =
true;
417 Int32 next_index = 0;
418 for( Int32 i=0; i<old_size; ++i ){
419 Int32 lid = items_lid[i];
420 if (remove_flags[lid]) {
421 removed_local_ids.add(lid);
424 items_lid[next_index] = lid;
427 if (next_index!=old_size) {
429 items_lid.resize(next_index);
436 trace->info(5) <<
"ItemGroupImpl::removeItems() group <" << name() <<
"> "
437 <<
" old_size=" << old_size
438 <<
" new_size=" << nbItem()
439 <<
" removed?=" << has_removed;
445 notifyReduceObservers(&observation_info);
451void ItemGroupInternal::
454 ITraceMng* msg = mesh()->traceMng();
455 if (m_need_recompute && m_compute_functor) {
456 msg->debug(Trace::High) <<
"ItemGroupImpl::checkValid on " << name() <<
" : skip group to recompute";
463 UniqueArray<bool> presence_checks(maxLocalId());
464 presence_checks.fill(0);
468 Integer items_size = items.size();
471 for( Integer i=0, is=items_lid.size(); i<is; ++i ){
473 if (lid>=items_size){
475 msg->error() <<
"Wrong local index lid=" << lid <<
" max=" << items_size
476 <<
" var_max_size=" << maxLocalId();
481 ItemInternal* item = items[lid];
482 if (item->isSuppressed()){
484 msg->error() <<
"Item " << ItemPrinter(item) <<
" in group "
485 << name() <<
" does not exist anymore";
489 if (presence_checks[lid]){
491 msg->error() <<
"Item " << ItemPrinter(item) <<
" in group "
492 << name() <<
" was found twice or more";
496 presence_checks[lid] =
true;
499 for( Integer i=0, n=items_lid.size(); i<n; ++i ){
500 Int32 local_id = items_lid[i];
501 Int32 index_in_all_group = m_items_index_in_all_group[local_id];
502 if (index_in_all_group!=i){
504 msg->error() << A_FUNCINFO
506 <<
": incoherence between 'local_id' and index in the group 'All' "
508 <<
" local_id=" << local_id
509 <<
" index=" << index_in_all_group;
516 String parent_name =
"none";
518 parent_name = m_parent->name();
519 ARCANE_FATAL(
"Error in group name='{0}' parent='{1}' nb_error={2}",
520 name(),parent_name,nb_error);
527void ItemGroupInternal::
528_notifyDirectRemoveItems(SmallSpan<const Int32> removed_ids, Int32 nb_remaining)
530 mutableItemsLocalId().resize(nb_remaining);
537 notifyReduceObservers(&observation_info);
546void ItemGroupImplInternal::
547setAsConstituentGroup()
549 m_p->m_is_constituent_group =
true;
555SmallSpan<Int32> ItemGroupImplInternal::
558 return m_p->itemsLocalId();
564void ItemGroupImplInternal::
565notifyDirectRemoveItems(SmallSpan<const Int32> removed_ids, Int32 nb_remaining)
567 m_p->_notifyDirectRemoveItems(removed_ids, nb_remaining);
573void ItemGroupImplInternal::
574notifySimdPaddingDone()
576 m_p->m_simd_timestamp = m_p->timestamp();
582void ItemGroupImplInternal::
583setMemoryRessourceForItemLocalId(eMemoryRessource mem)
587 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.