Skip to content

Commit

Permalink
[arcane,mesh] Ajoute possibilité d'utiliser 'std::unordered_map' comm…
Browse files Browse the repository at this point in the history
…e tableau associatif pour 'ItemInternalMap'.

Cela n'est pas actif par défaut. Cela permettra d'avoir une implémentation
plus performante que la version actuelle pour gérer les conversions
uniqueId -> ItemInternal.
  • Loading branch information
grospelliergilles committed Sep 13, 2024
1 parent 659b429 commit 9f0edd8
Show file tree
Hide file tree
Showing 4 changed files with 284 additions and 51 deletions.
6 changes: 3 additions & 3 deletions arcane/src/arcane/mesh/DynamicMeshKindInfos.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ class ARCANE_MESH_EXPORT DynamicMeshKindInfos
if (!m_has_unique_id_map)
_badUniqueIdMap();
#endif
ItemInternalMapData* item_data = m_items_map._lookupAdd(uid, 0, is_alloc);
ItemInternalMap::LookupData item_data = m_items_map._lookupAdd(uid, 0, is_alloc);
if (is_alloc){
bool need_alloc;
item_data->setValue(_allocOne(need_alloc));
item_data.setValue(_allocOne(need_alloc));
}
return item_data->value();
return item_data.value();
}

//! Recherche l'entité de numéro unique \a uid
Expand Down
2 changes: 1 addition & 1 deletion arcane/src/arcane/mesh/ItemFamily.cc
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ _endUpdate(bool need_check_remove)

_resizeVariables(false);
info(4) << "ItemFamily:endUpdate(): " << fullName()
<< " hashmapsize=" << itemsMap().buckets().size()
<< " hashmapsize=" << itemsMap().nbBucket()
<< " nb_group=" << m_item_groups.count();

_updateGroups(need_check_remove);
Expand Down
104 changes: 91 additions & 13 deletions arcane/src/arcane/mesh/ItemInternalMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

#include "arcane/mesh/ItemInternalMap.h"

#include "arcane/utils/ArrayView.h"
#include "arcane/utils/Iterator.h"
#include "arcane/utils/FatalErrorException.h"
#include "arcane/utils/NotSupportedException.h"

#include "arcane/core/Item.h"

Expand Down Expand Up @@ -46,23 +46,40 @@ ItemInternalMap()
void ItemInternalMap::
notifyUniqueIdsChanged()
{
if (arcaneIsCheck()){
if (arcaneIsCheck()) {
// Vérifie qu'on n'a pas deux fois la même clé.
std::unordered_set<Int64> uids;
this->eachItem([&](Item item) {
Int64 uid = item.uniqueId().asInt64();
if (uids.find(uid)!=uids.end())
ARCANE_FATAL("Duplicated uniqueId '{0}'",uid);
if (uids.find(uid) != uids.end())
ARCANE_FATAL("Duplicated uniqueId '{0}'", uid);
uids.insert(uid);
});
}

ENUMERATE_ITEM_INTERNAL_MAP_DATA2(nbid, m_impl)
{
nbid->setKey(nbid->value()->uniqueId().asInt64());
if constexpr (UseNewImpl) {
Int64 nb_item = m_new_impl.size();
UniqueArray<ItemInternal*> items(nb_item);
Int64 index = 0;
for (auto& x : m_new_impl) {
items[index] = x.second;
++index;
}
m_new_impl.clear();
for (index = 0; index < nb_item; ++index) {
ItemInternal* item = items[index];
m_new_impl.insert(std::make_pair(item->uniqueId(), item));
}
}
else {
ENUMERATE_ITEM_INTERNAL_MAP_DATA2 (nbid, m_impl) {
nbid->setKey(nbid->value()->uniqueId().asInt64());
}

m_impl.rehash();
m_impl.rehash();
}

checkValid();
}

/*---------------------------------------------------------------------------*/
Expand All @@ -72,12 +89,73 @@ void ItemInternalMap::
_changeLocalIds(ArrayView<ItemInternal*> items_internal,
ConstArrayView<Int32> old_to_new_local_ids)
{
ENUMERATE_ITEM_INTERNAL_MAP_DATA2(nbid, m_impl)
{
ItemInternal* item = nbid->value();
Int32 current_local_id = item->localId();
nbid->setValue(items_internal[old_to_new_local_ids[current_local_id]]);
checkValid();

if constexpr (UseNewImpl) {
for (auto& iter : m_new_impl) {
ItemInternal* old_ii = iter.second;
Int32 current_local_id = old_ii->localId();
ItemInternal* new_ii = items_internal[old_to_new_local_ids[current_local_id]];
iter.second = new_ii;
}
}
else {
ENUMERATE_ITEM_INTERNAL_MAP_DATA2 (nbid, m_impl) {
ItemInternal* old_ii = nbid->value();
Int32 current_local_id = old_ii->localId();
ItemInternal* new_ii = items_internal[old_to_new_local_ids[current_local_id]];
nbid->setValue(new_ii);
}
}
}

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

void ItemInternalMap::
checkValid() const
{
if (!arcaneIsCheck())
return;

if constexpr (UseNewImpl) {
for (auto& x : m_new_impl) {
if (x.first != x.second->uniqueId())
ARCANE_FATAL("Incoherent uid key={0} item_internal={1}", x.first, x.second->uniqueId());
}
}
else {
ENUMERATE_ITEM_INTERNAL_MAP_DATA2(nbid, m_impl)
{
if (nbid->key() != nbid->value()->uniqueId())
ARCANE_FATAL("Incoherent uid key={0} item_internal={1}", nbid->key(), nbid->value()->uniqueId());
}
}
}

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

void ItemInternalMap::
_throwNotFound(Int64 key) const
{
ARCANE_FATAL("ERROR: can not find key={0}", key);
}

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

void ItemInternalMap::
_throwNotSupported(const char* func_name) const
{
ARCANE_THROW(NotSupportedException, func_name);
}

void ItemInternalMap::
_checkValid(Int64 uid, ItemInternal* v) const
{
if (v->uniqueId() != uid)
ARCANE_FATAL("Bad found uniqueId found={0} expected={1}", v->uniqueId(), uid);
}

/*---------------------------------------------------------------------------*/
Expand Down
Loading

0 comments on commit 9f0edd8

Please sign in to comment.