Skip to content

Commit

Permalink
Merge pull request #1624 from arcaneframework/dev/gg-continue-cleanup…
Browse files Browse the repository at this point in the history
…-iteminternalmap

Deprecate methods 'lookupAdd', 'lookupValue' and 'buckets' of 'ItemInternalMap'
  • Loading branch information
grospelliergilles authored Sep 11, 2024
2 parents 351b8d2 + 389a555 commit 63218e0
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 72 deletions.
25 changes: 19 additions & 6 deletions arcane/src/arcane/mesh/DoFFamily.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,28 @@
namespace Arcane::mesh
{

Int64 DoFUids::
getMaxItemUid(IItemFamily* family)
{
Int64 max_uid = 0;
// This method can be used within IItemFamily::endUpdate when new items have been created but the groups are not yet updated.
// Therefore we use internal map enumeration instead of group enumeration
ItemFamily* item_family = ARCANE_CHECK_POINTER(dynamic_cast<ItemFamily*>(family));
item_family->itemsMap().eachItem([&](Item item) {
if (max_uid < item.uniqueId().asInt64())
max_uid = item.uniqueId().asInt64();
});
Int64 pmax_uid = family->mesh()->parallelMng()->reduce(Parallel::ReduceMax, max_uid);
return pmax_uid;
}

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

DoFFamily::
DoFFamily(IMesh* mesh, const String& name)
: ItemFamily(mesh,IK_DoF,name)
, m_shared_info(0)
, m_shared_info(nullptr)
{}

/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -157,23 +172,21 @@ _printInfos(Integer nb_added)
info() << "DoFFamily: added=" << nb_added
<< " nb_internal=" << infos().m_internals.size()
<< " nb_free=" << infos().m_free_internals.size()
<< " map_nb_bucket=" << itemsMap().buckets().size()
<< " map_nb_bucket=" << itemsMap().nbBucket()
<< " map_size=" << nb_in_map;
}

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

void
DoFFamily::
void DoFFamily::
preAllocate(Integer nb_item)
{
// Copy paste de particle, pas utilise pour l'instant
Integer nb_hash = itemsMap().buckets().size();
Integer nb_hash = itemsMap().nbBucket();
Integer wanted_size = 2*(nb_item+infos().nbItem());
if (nb_hash<wanted_size)
itemsMap().resize(wanted_size,true);

}

/*---------------------------------------------------------------------------*/
Expand Down
27 changes: 7 additions & 20 deletions arcane/src/arcane/mesh/DoFFamily.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
/*---------------------------------------------------------------------------*/
/* DoFFamily.h (C) 2000-2024 */
/* */
/* Famille de degres de liberte (DoF) */
/* Famille de degrés de liberté (DoF) */
/*---------------------------------------------------------------------------*/
#ifndef ARCANE_MESH_DOFFAMILY_H
#define ARCANE_MESH_DOFFAMILY_H
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

#include "arcane/ItemTypes.h"
#include "arcane/IMesh.h"
#include "arcane/IParallelMng.h"
#include "arcane/IDoFFamily.h"
#include "arcane/core/ItemTypes.h"
#include "arcane/core/IMesh.h"
#include "arcane/core/IParallelMng.h"
#include "arcane/core/IDoFFamily.h"

#include "arcane/mesh/ItemFamily.h"

Expand All @@ -34,7 +34,7 @@ class DynamicMesh;
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

class DoFUids
class ARCANE_MESH_EXPORT DoFUids
{
/*!
* Utilitaire d'obtention d'identifiant unique. Version triviale pour experimentation.
Expand All @@ -54,20 +54,7 @@ class DoFUids
} // very temporary solution...

// utilities
static Int64 getMaxItemUid(IItemFamily* family)
{
Int64 max_uid = 0;
// This method can be used within IItemFamily::endUpdate when new items have been created but the groups are not yet updated.
// Therefore we use internal map enumeration instead of group enumeration
ItemFamily* item_family = static_cast<ItemFamily*>(family);
ENUMERATE_ITEM_INTERNAL_MAP_DATA(item, item_family->itemsMap())
{
if (max_uid < item->value()->uniqueId().asInt64())
max_uid = item->value()->uniqueId().asInt64();
}
Int64 pmax_uid = family->mesh()->parallelMng()->reduce(Parallel::ReduceMax, max_uid);
return pmax_uid;
}
static Int64 getMaxItemUid(IItemFamily* family);
};

/*---------------------------------------------------------------------------*/
Expand Down
12 changes: 4 additions & 8 deletions arcane/src/arcane/mesh/DynamicMeshKindInfos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ itemsUniqueIdToLocalId(ArrayView<Int64> ids,bool do_fatal) const
if (do_fatal){
for( Integer i=0, s=ids.size(); i<s; ++i ){
Int64 unique_id = ids[i];
ids[i] =m_items_map.lookupValue(unique_id)->localId();
ids[i] = m_items_map.findLocalId(unique_id);
}
}
else{
Expand Down Expand Up @@ -236,7 +236,7 @@ itemsUniqueIdToLocalId(Int32ArrayView local_ids,
if (do_fatal){
for( Integer i=0, s=unique_ids.size(); i<s; ++i ){
Int64 unique_id = unique_ids[i];
local_ids[i] = (unique_id==NULL_ITEM_UNIQUE_ID) ? NULL_ITEM_LOCAL_ID : m_items_map.lookupValue(unique_id)->localId();
local_ids[i] = (unique_id == NULL_ITEM_UNIQUE_ID) ? NULL_ITEM_LOCAL_ID : m_items_map.findLocalId(unique_id);
}
}
else{
Expand Down Expand Up @@ -280,7 +280,7 @@ itemsUniqueIdToLocalId(Int32ArrayView local_ids,
if (do_fatal){
for( Integer i=0, s=unique_ids.size(); i<s; ++i ){
Int64 unique_id = unique_ids[i];
local_ids[i] = m_items_map.lookupValue(unique_id)->localId();
local_ids[i] = m_items_map.findLocalId(unique_id);
}
}
else{
Expand Down Expand Up @@ -651,11 +651,7 @@ finishCompactItems(ItemFamilyCompactInfos& compact_infos)
// IMPORTANT: Cette opération doit toujours être la dernière car ensuite
// on perd la relation entre les anciens local_ids et les nouveaux à
// travers cette structure
ENUMERATE_ITEM_INTERNAL_MAP_DATA(nbid,m_items_map){
ItemInternal* item = nbid->value();
Integer current_local_id = item->localId();
nbid->setValue(m_internals[ old_to_new_local_ids[ current_local_id ] ]);
}
m_items_map._changeLocalIds(m_internals, old_to_new_local_ids);

if (m_is_verbose){
info() << "DumpItemsBefore:";
Expand Down
2 changes: 1 addition & 1 deletion arcane/src/arcane/mesh/DynamicMeshKindInfos.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class ARCANE_MESH_EXPORT DynamicMeshKindInfos
if (!m_has_unique_id_map)
_badUniqueIdMap();
#endif
ItemInternalMapData* item_data = m_items_map.lookupAdd(uid,0,is_alloc);
ItemInternalMapData* item_data = m_items_map._lookupAdd(uid, 0, is_alloc);
if (is_alloc){
bool need_alloc;
item_data->setValue(_allocOne(need_alloc));
Expand Down
2 changes: 1 addition & 1 deletion arcane/src/arcane/mesh/GhostLayerBuilder2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ _addGhostLayer(Integer current_layer,Int32ConstArrayView node_layer)
++index;
Int64 nb_cell = recv_infos[index];
++index;
Node current_node(nodes_map.lookupValue(node_uid));
Node current_node(nodes_map.findItem(node_uid));
if (is_verbose)
info() << "NODE uid=" << node_uid << " nb_cell=" << nb_cell << " idx=" << (index-2);
my_cells.clear();
Expand Down
25 changes: 24 additions & 1 deletion arcane/src/arcane/mesh/ItemInternalMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
namespace Arcane::mesh
{

#define ENUMERATE_ITEM_INTERNAL_MAP_DATA2(iter, item_list) \
for (auto __i__##iter : item_list.buckets()) \
for (auto* iter = __i__##iter; iter; iter = iter->next())

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

Expand Down Expand Up @@ -55,15 +59,34 @@ notifyUniqueIdsChanged()
});
}

ENUMERATE_ITEM_INTERNAL_MAP_DATA(nbid,c){
ENUMERATE_ITEM_INTERNAL_MAP_DATA2(nbid, c)
{
nbid->setKey(nbid->value()->uniqueId().asInt64());
}

this->rehash();
}

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

void ItemInternalMap::
_changeLocalIds(ArrayView<ItemInternal*> items_internal,
ConstArrayView<Int32> old_to_new_local_ids)
{
ItemInternalMap& c = *this;

ENUMERATE_ITEM_INTERNAL_MAP_DATA2(nbid, c)
{
ItemInternal* item = nbid->value();
Int32 current_local_id = item->localId();
nbid->setValue(items_internal[old_to_new_local_ids[current_local_id]]);
}
}

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

} // End namespace Arcane::mesh

/*---------------------------------------------------------------------------*/
Expand Down
77 changes: 68 additions & 9 deletions arcane/src/arcane/mesh/ItemInternalMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,13 @@ class ItemInternalMap

public:

using Data ARCANE_DEPRECATED_REASON("Data type is internal to Arcane") = BaseClass::Data;
using Data ARCANE_DEPRECATED_REASON("Y2024: Data type is internal to Arcane") = BaseClass::Data;

public:

using BaseClass::add;
using BaseClass::buckets;
using BaseClass::clear;
using BaseClass::count;
using BaseClass::lookupAdd;
using BaseClass::lookupValue;
using BaseClass::remove;
using BaseClass::operator[];
using BaseClass::hasKey;
Expand Down Expand Up @@ -93,14 +90,16 @@ class ItemInternalMap
template <class Lambda> void
eachItem(const Lambda& lambda)
{
ConstArrayView<BaseData*> b = buckets();
ConstArrayView<BaseData*> b = BaseClass::buckets();
for (Int32 k = 0, n = b.size(); k < n; ++k) {
BaseData* nbid = b[k];
for (; nbid; nbid = nbid->next()) {
lambda(Arcane::impl::ItemBase(nbid->value()));
}
}
}
//! Nombre de buckets
Int32 nbBucket() const { return BaseClass::buckets().size(); }

public:

Expand All @@ -117,6 +116,26 @@ class ItemInternalMap
return (d ? d->value()->localId() : NULL_ITEM_LOCAL_ID);
}

/*!
* \brief Retourne l'entité de numéro unique \a uid.
*
* Lève une exception si l'entité n'est pas dans la table.
*/
impl::ItemBase findItem(Int64 uid) const
{
return impl::ItemBase(BaseClass::lookupValue(uid));
}

/*!
* \brief Retourne le numéro local de l'entité de numéro unique \a uid.
*
* Lève une exception si l'entité n'est pas dans la table.
*/
Int32 findLocalId(Int64 uid) const
{
return BaseClass::lookupValue(uid)->localId();
}

private:

//! Retourne l'entité associée à \a key si trouvé ou nullptr sinon
Expand All @@ -126,25 +145,65 @@ class ItemInternalMap
return (d ? d->value() : nullptr);
}

private:
public:

ARCANE_DEPRECATED_REASON("This method is internal to Arcane")
ARCANE_DEPRECATED_REASON("Y2024: This method is internal to Arcane")
Data* lookup(Int64 key)
{
return BaseClass::lookup(key);
}

ARCANE_DEPRECATED_REASON("This method is internal to Arcane")
ARCANE_DEPRECATED_REASON("Y2024: This method is internal to Arcane")
const Data* lookup(Int64 key) const
{
return BaseClass::lookup(key);
}

ARCANE_DEPRECATED_REASON("Y2024: This method is internal to Arcane")
ConstArrayView<BaseData*> buckets() const { return BaseClass::buckets(); }

ARCANE_DEPRECATED_REASON("This method is internal to Arcane")
BaseData* lookupAdd(Int64 id, ItemInternal* value, bool& is_add)
{
return BaseClass::lookupAdd(id, value, is_add);
}

ARCANE_DEPRECATED_REASON("Y2024: This method is internal to Arcane")
BaseData* lookupAdd(Int64 uid)
{
return BaseClass::lookupAdd(uid);
}

ARCANE_DEPRECATED_REASON("Y2024: Use findItem() instead")
ItemInternal* lookupValue(Int64 uid) const
{
return BaseClass::lookupValue(uid);
}

private:

/*!
* \brief Change la valeurs des localId(0.
*
* Cette méthode ne doit être appelée que par DynamicMeshKindInfos.
*/
void _changeLocalIds(ArrayView<ItemInternal*> items_internal,
ConstArrayView<Int32> old_to_new_local_ids);

BaseData* _lookupAdd(Int64 id, ItemInternal* value, bool& is_add)
{
return BaseClass::lookupAdd(id, value, is_add);
}
};

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

//! Macro pour itérer sur les valeurs d'un ItemInternalMap
/*!
* \brief Macro pour itérer sur les valeurs d'un ItemInternalMap.
*
* \deprecated Utiliser ItemInternalMap::eachItem() à la place.
*/
#define ENUMERATE_ITEM_INTERNAL_MAP_DATA(iter,item_list) \
for( auto __i__##iter : item_list .buckets() ) \
for (auto* iter = __i__##iter; iter; iter = iter->next())
Expand Down
Loading

0 comments on commit 63218e0

Please sign in to comment.