Skip to content

Commit

Permalink
Merge pull request #1682 from arcaneframework/dev/gg-use-modified-env…
Browse files Browse the repository at this point in the history
…s-to-filter-some-operations

Remove some computation of index list of an environment if it is not impacted by a modification
  • Loading branch information
grospelliergilles authored Oct 12, 2024
2 parents ab21b6b + 01fb34c commit 293c9bb
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 30 deletions.
47 changes: 37 additions & 10 deletions arcane/src/arcane/materials/ConstituentConnectivityList.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

namespace Arcane::Materials
{

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

Expand Down Expand Up @@ -95,7 +94,7 @@ class ConstituentConnectivityList::ConstituentContainer
{
public:

View(ConstituentContainer& c)
explicit View(ConstituentContainer& c)
: nb_components_view(c.m_nb_component_as_array.view())
, component_indexes_view(c.m_component_index_as_array.view())
, component_list_view(c.m_component_list_as_array.view())
Expand Down Expand Up @@ -180,7 +179,7 @@ class ConstituentConnectivityList::ConstituentContainer

private:

//! Nombre de milieu par maille (dimensionné au nombre de mailles)
//! Nombre de milieux par maille (dimensionné au nombre de mailles)
VariableArrayInt16 m_nb_component;
//! Indice dans \a m_component_list (Dimensionné au nombre de mailles)
VariableArrayInt32 m_component_index;
Expand Down Expand Up @@ -214,12 +213,15 @@ class ConstituentConnectivityList::NumberOfMaterialComputer
{
public:

NumberOfMaterialComputer(ConstituentConnectivityList::ConstituentContainer::View view,
NumberOfMaterialComputer(ConstituentContainer::View view,
SmallSpan<const Int16> environment_for_materials)
: m_view(view)
, m_environment_for_materials(environment_for_materials)
{
}

public:

ARCCORE_HOST_DEVICE Int16 cellNbMaterial(Int32 cell_local_id, Int16 env_id) const
{
auto mats = m_view.components(cell_local_id);
Expand All @@ -234,7 +236,7 @@ class ConstituentConnectivityList::NumberOfMaterialComputer

private:

ConstituentConnectivityList::ConstituentContainer::View m_view;
ConstituentContainer::View m_view;
//! Vue indiquant le milieu associé aux matériaux
SmallSpan<const Int16> m_environment_for_materials;
};
Expand Down Expand Up @@ -620,25 +622,50 @@ fillCellsIsPartial(SmallSpan<const Int32> cells_local_id, Int16 env_id,

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*!
* \brief Affiche les constituants d'une liste d'entités
* @param cells_local_id Liste des numéros locaux des entitiés
*/
void ConstituentConnectivityList::
printConstituents(SmallSpan<const Int32> cells_local_id) const
{
const ConstituentContainer::View materials_view(m_container->m_material);
const ConstituentContainer::View environments_view(m_container->m_environment);

for (Int32 i = 0, n = cells_local_id.size(); i < n; ++i) {
Int32 lid = cells_local_id[i];
info() << "Cell index=" << i << " lid=" << lid
<< " materials=" << materials_view.components(lid)
<< " environments=" << environments_view.components(lid);
}
}

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*!
* \brief Remplit les constituants concernés par les mailles \a cells_local_id.
*
* Met à \a true les valeurs de \a is_modified_materials et \a is_modified_environments
* s'ils sont dans une des mailles de \a cells_local_id.
*/
void ConstituentConnectivityList::
fillModifiedConstituents(SmallSpan<const Int32> cells_local_id,
SmallSpan<bool> is_modified_materials,
SmallSpan<bool> is_modified_environments,
RunQueue& queue)
const RunQueue& queue) const
{
const Int32 n = cells_local_id.size();
if (n<=0)
if (n <= 0)
return;

ConstituentContainer::View materials_view(m_container->m_material);
ConstituentContainer::View environments_view(m_container->m_environment);
const ConstituentContainer::View materials_view(m_container->m_material);
const ConstituentContainer::View environments_view(m_container->m_environment);
auto command = makeCommand(queue);

command << RUNCOMMAND_LOOP1(iter, n)
{
auto [i] = iter();
Int32 local_id = cells_local_id[i];
const Int32 local_id = cells_local_id[i];
SmallSpan<const Int16> cell_mats(materials_view.components(local_id));
for( Int16 x : cell_mats )
is_modified_materials[x] = true;
Expand Down
23 changes: 14 additions & 9 deletions arcane/src/arcane/materials/IncrementalComponentModifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ IncrementalComponentModifier(AllEnvData* all_env_data, const RunQueue& queue)
/*---------------------------------------------------------------------------*/

void IncrementalComponentModifier::
initialize()
initialize(bool is_debug)
{
m_is_debug = is_debug;
Int32 max_local_id = m_material_mng->mesh()->cellFamily()->maxLocalId();
Int32 nb_mat = m_material_mng->materials().size();
Int32 nb_env = m_material_mng->environments().size();
m_work_info.initialize(max_local_id, nb_mat, nb_env, m_queue);
m_work_info.is_verbose = traceMng()->verbosityLevel() >= 5;
m_work_info.is_verbose = is_debug || (traceMng()->verbosityLevel() >= 5);
}

/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -103,7 +104,7 @@ apply(MaterialModifierOperation* operation)

const IMeshEnvironment* env = mat->environment();
MeshEnvironment* true_env = true_mat->trueEnvironment();
Integer nb_mat = env->nbMaterial();
const Integer nb_mat = env->nbMaterial();

ConstituentConnectivityList* connectivity = m_all_env_data->componentConnectivityList();
const bool check_if_present = !m_queue.isAcceleratorPolicy();
Expand All @@ -120,6 +121,8 @@ apply(MaterialModifierOperation* operation)
auto mat_modifier = m_work_info.m_is_materials_modified.modifier(is_device);
auto env_modifier = m_work_info.m_is_environments_modified.modifier(is_device);
connectivity->fillModifiedConstituents(orig_ids, mat_modifier.view(), env_modifier.view(), m_queue);
if (m_is_debug)
connectivity->printConstituents(orig_ids);
}

if (nb_mat != 1) {
Expand Down Expand Up @@ -330,7 +333,7 @@ _switchCellsForEnvironments(const IMeshEnvironment* modified_env,
{
const bool is_add = m_work_info.isAdd();
const bool is_device = m_queue.isAcceleratorPolicy();
SmallSpan<const bool> is_environments_modified = m_work_info.m_is_materials_modified.view(false);
SmallSpan<const bool> is_environments_modified = m_work_info.m_is_environments_modified.view(false);

// Ne copie pas les valeurs partielles des milieux vers les valeurs globales
// en cas de suppression de mailles, car cela sera fait avec la valeur matériau
Expand All @@ -347,9 +350,10 @@ _switchCellsForEnvironments(const IMeshEnvironment* modified_env,
// Ne traite pas le milieu en cours de modification.
if (env == modified_env)
continue;
const Int32 env_id = env->id();

//if (!is_environments_modified[env->id()])
//continue;
if (!is_environments_modified[env_id])
continue;

if (!is_device) {
m_work_info.pure_local_ids.clearHost();
Expand All @@ -359,16 +363,17 @@ _switchCellsForEnvironments(const IMeshEnvironment* modified_env,
MeshMaterialVariableIndexer* indexer = env->variableIndexer();

info(4) << "TransformCells (V2) is_add?=" << is_add
<< " env_id=" << env_id
<< " indexer=" << indexer->name() << " nb_item=" << ids.size();

indexer->transformCellsV2(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);
const Int32 nb_pure = pure_local_ids.size();

info(4) << "NB_ENV_TRANSFORM nb_pure=" << pure_local_ids.size()
<< " name=" << env->name()
<< " is_modified=" << is_environments_modified[env->id()];
info(4) << "NB_ENV_TRANSFORM nb_pure=" << nb_pure << " name=" << env->name()
<< " is_modified=" << is_environments_modified[env_id];

if (is_copy) {
CopyBetweenPartialAndGlobalArgs copy_args(indexer->index(), pure_local_ids,
Expand Down
6 changes: 4 additions & 2 deletions arcane/src/arcane/materials/MeshMaterialModifierImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ MeshMaterialModifierImpl(MeshMaterialMng* mm)
_setLocalVerboseLevel(4);
if (auto v = Convert::Type<Int32>::tryParseFromEnvironment("ARCANE_DEBUG_MATERIAL_MODIFIER", true)) {
Int32 value = v.value();
if (value > 0)
if (value > 0) {
_setLocalVerboseLevel(3);
m_is_debug = true;
}
if (value > 1)
m_print_component_list = true;
}
Expand Down Expand Up @@ -262,7 +264,7 @@ _endUpdate()
m_incremental_modifier = std::make_unique<IncrementalComponentModifier>(all_env_data, m_queue);
}
if (is_optimization_active && m_use_incremental_recompute) {
m_incremental_modifier->initialize();
m_incremental_modifier->initialize(m_is_debug);
m_incremental_modifier->setDoCopyBetweenPartialAndPure(m_do_copy_between_partial_and_pure);
m_incremental_modifier->setDoInitNewItems(m_do_init_new_items);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,12 @@ class ConstituentConnectivityList
void fillCellsIsPartial(SmallSpan<const Int32> cells_local_id, Int16 env_id,
SmallSpan<bool> cells_is_partial, RunQueue& queue);

/*!
* \brief Remplit les constituant concernés par les mailles \a cells_local_id.
*
* Met à \a true les valeurs de \a is_modified_materials et \a is_modified_environments
* s'ils sont dans une des mailles de \a cells_local_id.
*/
void fillModifiedConstituents(SmallSpan<const Int32> cells_local_id,
SmallSpan<bool> is_modified_materials,
SmallSpan<bool> is_modified_environments,
RunQueue& queue);
const RunQueue& queue) const;

void printConstituents(SmallSpan<const Int32> cells_local_id) const;

/*!
* \brief Indique si l'instance est activée.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ARCANE_MATERIALS_EXPORT IncrementalComponentModifier

public:

void initialize();
void initialize(bool is_debug);
void apply(MaterialModifierOperation* operation);
void finalize();
void setDoCopyBetweenPartialAndPure(bool v) { m_do_copy_between_partial_and_pure = v; }
Expand All @@ -62,7 +62,7 @@ class ARCANE_MATERIALS_EXPORT IncrementalComponentModifier
RunQueue m_queue;
bool m_do_copy_between_partial_and_pure = true;
bool m_do_init_new_items = true;

bool m_is_debug = false;
//! 1 ou 2 si on utilise une version générique pour les copies entre pure et partiel
Int32 m_use_generic_copy_between_pure_and_partial = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class MeshMaterialModifierImpl
bool m_do_init_new_items = true;
bool m_is_keep_work_buffer = true;

bool m_is_debug = false;

private:

void _endUpdate();
Expand Down

0 comments on commit 293c9bb

Please sign in to comment.