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();
262void ItemGroupInternal::
265 m_is_contiguous =
false;
268 m_is_contiguous =
false;
271 Int32 first_lid = lids[0];
275 if (lids[i]!=(first_lid+i)){
281 m_is_contiguous =
true;
287void ItemGroupInternal::
290 if (m_is_print_apply_simd_padding){
292 if (m_is_print_stack_apply_simd_padding)
295 tm->
info() <<
"ApplySimdPadding group_name=" <<
m_name << stack;
299 m_internal_api.notifySimdPaddingDone();
300 Arcane::applySimdPadding(mutableItemsLocalId());
331void ItemGroupInternal::
332checkUpdateSimdPadding()
339 tm->
info() <<
"check padding name=" << fullName()
340 <<
" timestamp=" << timestamp()
342 <<
" size=" << mutableItemsLocalId().size()
343 <<
" capacity=" << mutableItemsLocalId().capacity();
345 ArrayUtils::checkSimdPadding(itemsLocalId());
355void ItemGroupInternal::
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());
372 Int32 nb_item_to_remove = items_local_id.
size();
377 if (nb_item_to_remove!=0) {
379 Int32Array& items_lid = mutableItemsLocalId();
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;
551 return m_p->itemsLocalId();
557void ItemGroupImplInternal::
560 m_p->_notifyDirectRemoveItems(removed_ids, nb_remaining);
566void ItemGroupImplInternal::
567notifySimdPaddingDone()
569 m_p->m_simd_timestamp = m_p->timestamp();
575void ItemGroupImplInternal::
580 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.
Integer size() const
Nombre d'éléments du vecteur.
Exception lorsqu'un argument est invalide.
void resize(Int64 s)
Change le nombre d'éléments du tableau à s.
void add(ConstReferenceType val)
Ajoute l'élément val à la fin du tableau.
constexpr Integer size() const noexcept
Nombre d'éléments du tableau.
constexpr bool empty() const noexcept
true si le tableau est vide (size()==0)
virtual ITraceMng * traceMng()=0
Gestionnaire de message associé
virtual const MeshPartInfo & meshPartInfo() const =0
Informations sur les parties du maillage.
Interface du gestionnaire de traces.
virtual TraceMessage info()=0
Flot pour un message d'information.
bool m_is_check_simd_padding
Vrai si les localIds sont consécutifs.
void applySimdPadding()
Applique le padding pour la vectorisation.
IItemFamily * m_item_family
Famille associée.
Int64 m_simd_timestamp
Temps de la derniere modification pour le calcul des infos SIMD.
String m_name
Nom du groupe.
Exception lorsqu'une opération n'est pas supportée.
Vue d'un tableau d'éléments de type T.
constexpr __host__ __device__ SizeType size() const noexcept
Retourne la taille du tableau.
Chaîne de caractères unicode.
Vecteur 1D de données avec sémantique par valeur (style STL).
IVariable * variable() const
Variable associée.
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é.
Arcane::eMemoryResource eMemoryRessource
Typedef pour la version Arcane historique (avec 2's')
Array< Int32 > Int32Array
Tableau dynamique à une dimension d'entiers 32 bits.
std::int32_t Int32
Type entier signé sur 32 bits.