Skip to content

Commit

Permalink
Merge pull request #1683 from arcaneframework/dev/gg-add-statistics-a…
Browse files Browse the repository at this point in the history
…bout-useless-constituent-transform

Add statistics about useless constituent transform computation
  • Loading branch information
grospelliergilles authored Oct 13, 2024
2 parents 293c9bb + 521301b commit 87c8efc
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 41 deletions.
2 changes: 1 addition & 1 deletion arcane/ceapart/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ foreach(test_index 1 2 3 4)
endforeach()
endforeach()
if (ARCANE_HAS_ACCELERATOR_API)
arcane_add_test_sequential(material_heat2_opt15_2small testMaterialHeat-2-small-opt15.arc "-We,ARCANE_DEBUG_MATERIAL_MODIFIER,2")
arcane_add_test_sequential(material_heat2_opt15_2small testMaterialHeat-2-small-opt15.arc "-We,ARCANE_DEBUG_MATERIAL_MODIFIER,2" "-We,ARCANE_PRINT_USELESS_TRANSFORMATION,1")
arcane_add_test_sequential(material_heat2_accelerator
"${ARCANE_TEST_PATH}/testMaterialHeat-2-opt15.arc"
"-We,ARCANE_MATERIALMNG_ADDITIONAL_CAPACITY_RATIO,0.5"
Expand Down
4 changes: 2 additions & 2 deletions arcane/src/arcane/materials/IncrementalComponentModifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ _switchCellsForMaterials(const MeshMaterial* modified_mat,
info(4) << "nb_transformed=" << nb_transformed;
if (nb_transformed==0)
continue;
indexer->transformCellsV2(m_work_info, m_queue);
indexer->computeCellsToTransform(m_work_info, m_queue);
_resetTransformedCells(ids);

auto pure_local_ids = m_work_info.pure_local_ids.view(is_device);
Expand Down Expand Up @@ -366,7 +366,7 @@ _switchCellsForEnvironments(const IMeshEnvironment* modified_env,
<< " env_id=" << env_id
<< " indexer=" << indexer->name() << " nb_item=" << ids.size();

indexer->transformCellsV2(m_work_info, m_queue);
indexer->computeCellsToTransform(m_work_info, m_queue);

SmallSpan<const Int32> pure_local_ids = m_work_info.pure_local_ids.view(is_device);
SmallSpan<const Int32> partial_indexes = m_work_info.partial_indexes.view(is_device);
Expand Down
41 changes: 30 additions & 11 deletions arcane/src/arcane/materials/MeshMaterialMng.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ MeshMaterialMng::
~MeshMaterialMng()
{
//std::cout << "DESTROY MESH MATERIAL MNG this=" << this << '\n';
IEnumeratorTracer* tracer = IEnumeratorTracer::singleton();
if (tracer)
tracer->dumpStats();
_dumpStats();

delete m_mms;
delete m_variable_factory_mng;
Expand All @@ -170,20 +168,16 @@ MeshMaterialMng::
delete e;
m_true_environments.clear();

for( IMeshBlock* b : m_true_blocks )
for (IMeshBlock* b : m_true_blocks)
delete b;

for( MeshMaterialInfo* mmi : m_materials_info )
for (MeshMaterialInfo* mmi : m_materials_info)
delete mmi;

for( MeshMaterialVariableIndexer* mvi : m_variables_indexer_to_destroy )
for (MeshMaterialVariableIndexer* mvi : m_variables_indexer_to_destroy)
delete mvi;

if (m_modifier){
m_modifier->dumpStats();
m_modifier.reset();
}

m_modifier.reset();
m_internal_api.reset();

if (m_allcell_2_allenvcell)
Expand Down Expand Up @@ -1293,6 +1287,31 @@ componentItemSharedInfo(Int32 level) const
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

void MeshMaterialMng::
_dumpStats()
{
IEnumeratorTracer* tracer = IEnumeratorTracer::singleton();
if (tracer)
tracer->dumpStats();

if (m_modifier)
m_modifier->dumpStats();

for (IMeshEnvironment* env : m_environments) {
// N'affiche pas les statistiques si le milieu n'a qu'un seul matériau
// car il utilise le même indexeur que la matériau et les statistiques
// pour ce dernier seront affichées lors du parcours des matériaux.
if (env->nbMaterial() > 1)
env->_internalApi()->variableIndexer()->dumpStats();
}
for (IMeshMaterial* mat : m_materials) {
mat->_internalApi()->variableIndexer()->dumpStats();
}
}

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

} // End namespace Arcane::Materials

/*---------------------------------------------------------------------------*/
Expand Down
41 changes: 25 additions & 16 deletions arcane/src/arcane/materials/MeshMaterialVariableIndexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

namespace Arcane::Materials
{

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

Expand All @@ -58,6 +57,8 @@ MeshMaterialVariableIndexer(ITraceMng* tm, const String& name)
void MeshMaterialVariableIndexer::
_init()
{
if (auto v = Convert::Type<Int32>::tryParseFromEnvironment("ARCANE_PRINT_USELESS_TRANSFORMATION", true))
m_is_print_useless_transform = (v.value() != 0);
}

/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -313,21 +314,9 @@ _changeLocalIdsV2(MeshMaterialVariableIndexer* var_indexer, Int32ConstArrayView
/*---------------------------------------------------------------------------*/

void MeshMaterialVariableIndexer::
transformCellsV2(ConstituentModifierWorkInfo& work_info, RunQueue& queue)
{
_switchBetweenPureAndPartial(work_info, queue, work_info.isAdd());
}

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*!
* \brief Échange des mailles entre pures et partielles.
*/
void MeshMaterialVariableIndexer::
_switchBetweenPureAndPartial(ConstituentModifierWorkInfo& work_info,
RunQueue& queue,
bool is_pure_to_partial)
computeCellsToTransform(ConstituentModifierWorkInfo& work_info, RunQueue& queue)
{
bool is_pure_to_partial = work_info.isAdd();
bool is_device = isAcceleratorPolicy(queue.executionPolicy());

Integer nb = nbItem();
Expand Down Expand Up @@ -387,10 +376,17 @@ _switchBetweenPureAndPartial(ConstituentModifierWorkInfo& work_info,
filterer.applyWithIndex(nb, select_lambda, setter_lambda, A_FUNCINFO);
}

Int32 nb_out = filterer.nbOutputElement();
const Int32 nb_out = filterer.nbOutputElement();
pure_local_ids_modifier.resize(nb_out);
partial_indexes_modifier.resize(nb_out);

++m_nb_transform_called;
if (nb_out == 0) {
++m_nb_useless_transform;
if (m_is_print_useless_transform)
info() << "VarIndex null transformation modified_name=" << name();
}

if (is_pure_to_partial)
m_max_index_in_multiple_array += nb_out;
}
Expand All @@ -414,6 +410,19 @@ checkValid()
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

void MeshMaterialVariableIndexer::
dumpStats() const
{
if (m_nb_transform_called == 0)
return;
Int32 nb_useful_call = m_nb_transform_called - m_nb_useless_transform;
info() << "VariableIndexer name=" << name()
<< " nb_useful_transform=" << nb_useful_call << " nb_useless=" << m_nb_useless_transform;
}

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

} // End namespace Arcane::Materials

/*---------------------------------------------------------------------------*/
Expand Down
2 changes: 1 addition & 1 deletion arcane/src/arcane/materials/internal/MeshMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MeshMaterial
public:
InternalApi(MeshMaterial* mat) : m_material(mat){}
public:
MeshMaterialVariableIndexer* variableIndexer() const override\
MeshMaterialVariableIndexer* variableIndexer() const override
{
return m_material->variableIndexer();
}
Expand Down
1 change: 1 addition & 0 deletions arcane/src/arcane/materials/internal/MeshMaterialMng.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ class MeshMaterialMng
{
return m_all_cells_env_only_synchronizer.get();
}
void _dumpStats();
};

/*---------------------------------------------------------------------------*/
Expand Down
28 changes: 18 additions & 10 deletions arcane/src/arcane/materials/internal/MeshMaterialVariableIndexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,18 @@ class ARCANE_MATERIALS_EXPORT MeshMaterialVariableIndexer
void checkValid();
//! Vrai si cet indexeur est celui d'un milieu.
bool isEnvironment() const { return m_is_environment; }
void dumpStats() const;

public:

// Méthodes publiques car utilisées sur accélérateurs
void endUpdateAdd(const ComponentItemListBuilder& builder, RunQueue& queue);
void endUpdateRemoveV2(ConstituentModifierWorkInfo& work_info, Integer nb_remove, RunQueue& queue);
void computeCellsToTransform(ConstituentModifierWorkInfo& args, RunQueue& queue);

private:

//! Fonctions publiques mais réservées aux classes de Arcane.
//! Fonctions privées mais accessibles aux classes 'friend'.
//@{
void endUpdate(const ComponentItemListBuilderOld& builder);
Array<MatVarIndex>& matvarIndexesArray() { return m_matvar_indexes; }
Expand All @@ -106,8 +108,6 @@ class ARCANE_MATERIALS_EXPORT MeshMaterialVariableIndexer

private:

void transformCellsV2(ConstituentModifierWorkInfo& args, RunQueue& queue);

private:

//! Index de cette instance dans la liste des indexeurs.
Expand All @@ -122,7 +122,7 @@ class ARCANE_MATERIALS_EXPORT MeshMaterialVariableIndexer
//! Liste des mailles de cet indexer
CellGroup m_cells;

//! Liste des indexes pour les variables matériaux.
//! Liste des indexs pour les variables matériaux.
UniqueArray<MatVarIndex> m_matvar_indexes;

/*!
Expand All @@ -138,17 +138,25 @@ class ARCANE_MATERIALS_EXPORT MeshMaterialVariableIndexer
//! Vrai si l'indexeur est associé à un milieu.
bool m_is_environment = false;

//! Nombre d'appels aux méthodes de transformation
Int32 m_nb_transform_called = 0;

/*!
* \brief Nombre d'appels inutiles aux méthodes de transformation.
*
* Un appel est inutile si la liste des entités modifiées en sortie
* est vide.
*/
Int32 m_nb_useless_transform = 0;

//! Indique si on affiche un message lors d'une transformation inutile
bool m_is_print_useless_transform = false;

private:

static void _changeLocalIdsV2(MeshMaterialVariableIndexer* var_indexer,
Int32ConstArrayView old_to_new_ids);
void _init();

public:

void _switchBetweenPureAndPartial(ConstituentModifierWorkInfo& work_info,
RunQueue& queue,
bool is_pure_to_partial);
};

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

0 comments on commit 87c8efc

Please sign in to comment.