14#include "arcane/materials/internal/ConstituentItemVectorImpl.h" 
   16#include "arcane/utils/PlatformUtils.h" 
   17#include "arcane/utils/FatalErrorException.h" 
   19#include "arcane/core/materials/IMeshMaterialMng.h" 
   21#include "arcane/core/materials/internal/IMeshComponentInternal.h" 
   22#include "arcane/core/materials/internal/IMeshMaterialMngInternal.h" 
   24#include "arcane/accelerator/core/RunQueue.h" 
   27#include "arcane/accelerator/Partitioner.h" 
   39ConstituentItemVectorImpl::
 
   41: m_material_mng(component->materialMng())
 
   42, m_component(component)
 
   49  if (component->isMaterial())
 
   50    level = LEVEL_MATERIAL;
 
   51  else if (component->isEnvironment())
 
   52    level = LEVEL_ENVIRONMENT;
 
   55  m_component_shared_info = m_material_mng->_internalApi()->componentItemSharedInfo(level);
 
   56  m_constituent_list = std::make_unique<ConstituentItemLocalIdList>(m_component_shared_info, String());
 
   57  m_part_data->setRecomputeFunctor(&m_recompute_part_data_functor);
 
   63ConstituentItemVectorImpl::
 
   64ConstituentItemVectorImpl(
const ComponentItemVectorView& rhs)
 
   65: ConstituentItemVectorImpl(rhs.component())
 
   67  RunQueue& queue = m_material_mng->_internalApi()->runQueue();
 
   68  m_constituent_list->copy(rhs._constituentItemListView());
 
   69  m_matvar_indexes.copy(rhs._matvarIndexes());
 
   70  m_items_local_id.copy(rhs._internalLocalIds());
 
   71  m_part_data->_setFromMatVarIndexes(rhs._matvarIndexes(), queue);
 
   86  explicit SetItemHelper(
bool use_new_impl)
 
   87  : m_use_new_impl(use_new_impl)
 
   92  template <
typename ConstituentGetterLambda>
 
   93  void setItems(ConstituentItemVectorImpl* vector_impl,
 
   94                ConstituentGetterLambda constituent_getter_lambda,
 
   99  bool m_use_new_impl = 
true;
 
 
  105template <
typename ConstituentGetterLambda> 
void 
  106ConstituentItemVectorImpl::SetItemHelper::
 
  107setItems(ConstituentItemVectorImpl* vector_impl, ConstituentGetterLambda constituent_getter_lambda,
 
  114  const bool is_env = vector_impl->m_component->
isEnvironment();
 
  115  const Int32 component_id = vector_impl->m_component->
id();
 
  117  const Int32 nb_pure = vector_impl->m_nb_pure;
 
  119  Int32 pure_index = 0;
 
  120  Int32 impure_index = nb_pure;
 
  126  auto setter_unselected = [=] ARCCORE_HOST_DEVICE(
Int32, 
Int32) {
 
  128  auto generic_setter_lambda = [=] ARCCORE_HOST_DEVICE(
Int32 index, ComponentCell cc) {
 
  131    item_indexes[index] = cii;
 
  132    matvar_indexes[index] = idx;
 
  137  if (m_use_new_impl) {
 
  139    auto select_pure = [=] ARCCORE_HOST_DEVICE(
Int32 index) {
 
  140      ComponentCell cc = constituent_getter_lambda(index);
 
  146    auto select_impure = [=] ARCCORE_HOST_DEVICE(Int32 index) {
 
  147      ComponentCell cc = constituent_getter_lambda(index);
 
  150      return (cc._varIndex().arrayIndex() != 0);
 
  152    auto setter_lambda = [=] ARCCORE_HOST_DEVICE(Int32 index, Int32 output_index) {
 
  153      ComponentCell cc = constituent_getter_lambda(index);
 
  155        generic_setter_lambda(output_index, cc);
 
  157    auto setter_pure = [=] ARCCORE_HOST_DEVICE(Int32 index, Int32 output_index) {
 
  158      setter_lambda(index, output_index);
 
  160    auto setter_impure = [=] ARCCORE_HOST_DEVICE(Int32 index, Int32 output_index) {
 
  161      setter_lambda(index, output_index + nb_pure);
 
  164    generic_partitioner.applyWithIndex(nb_id, setter_pure, setter_impure, setter_unselected,
 
  165                                       select_pure, select_impure, A_FUNCINFO);
 
  173        AllEnvCell all_env_cell = *iallenvcell;
 
  174        for (EnvCell ec : all_env_cell.subEnvItems()) {
 
  175          if (ec.componentId() == component_id) {
 
  176            MatVarIndex idx = ec._varIndex();
 
  177            ConstituentItemIndex cii = ec._constituentItemIndex();
 
  178            Int32& base_index = (idx.arrayIndex() == 0) ? pure_index : impure_index;
 
  179            item_indexes[base_index] = cii;
 
  180            matvar_indexes[base_index] = idx;
 
  181            items_local_id[base_index] = all_env_cell.globalCellId();
 
  190        AllEnvCell all_env_cell = *iallenvcell;
 
  191        for (EnvCell env_cell : all_env_cell.subEnvItems()) {
 
  192          for (MatCell mc : env_cell.subMatItems()) {
 
  193            if (mc.componentId() == component_id) {
 
  194              MatVarIndex idx = mc._varIndex();
 
  195              ConstituentItemIndex cii = mc._constituentItemIndex();
 
  196              Int32& base_index = (idx.arrayIndex() == 0) ? pure_index : impure_index;
 
  197              item_indexes[base_index] = cii;
 
  198              matvar_indexes[base_index] = idx;
 
  199              items_local_id[base_index] = all_env_cell.globalCellId();
 
  217void ConstituentItemVectorImpl::
 
  220  const bool do_new_impl = m_material_mng->_internalApi()->isUseAcceleratorForConstituentItemVector();
 
  223  RunQueue queue = m_material_mng->_internalApi()->runQueue(exec_policy);
 
  226    _computeNbPureAndImpure(local_ids, queue);
 
  230  const Int32 nb_pure = m_nb_pure;
 
  231  const Int32 nb_impure = m_nb_impure;
 
  232  const Int32 total_nb_pure_and_impure = nb_pure + nb_impure;
 
  239  m_constituent_list->resize(total_nb_pure_and_impure);
 
  245  m_matvar_indexes.resize(total_nb_pure_and_impure);
 
  246  m_items_local_id.resize(total_nb_pure_and_impure);
 
  248  const bool is_env = m_component->isEnvironment();
 
  250  const Int32 component_id = m_component->id();
 
  253  auto env_component_getter_lambda = [=] ARCCORE_HOST_DEVICE(
Int32 index) -> ComponentCell {
 
  254    AllEnvCell all_env_cell = all_env_cell_view[index];
 
  256      if (ec.componentId() == component_id)
 
  263  auto mat_component_getter_lambda = [=] ARCCORE_HOST_DEVICE(
Int32 index) -> ComponentCell {
 
  264    AllEnvCell all_env_cell = all_env_cell_view[index];
 
  266      for (
MatCell mc : ec.subMatItems())
 
  267        if (mc.componentId() == component_id)
 
  276      helper.setItems(
this, env_component_getter_lambda, local_ids, queue);
 
  278      helper.setItems(
this, mat_component_getter_lambda, local_ids, queue);
 
  282  const bool do_lazy_evaluation = 
true;
 
  283  if (do_lazy_evaluation)
 
  284    m_part_data->setNeedRecompute();
 
  286    _recomputePartData();
 
 
  292void ConstituentItemVectorImpl::
 
  298  const Int32 component_id = m_component->id();
 
  308      for (
EnvCell ec : all_env_cell.subEnvItems()) {
 
  309        if (ec.componentId() == component_id) {
 
  314            nb_impure.combine(1);
 
  322      for (EnvCell env_cell : all_env_cell.subEnvItems()) {
 
  323        for (MatCell mc : env_cell.subMatItems()) {
 
  324          if (mc.componentId() == component_id) {
 
  325            MatVarIndex idx = mc._varIndex();
 
  326            if (idx.arrayIndex() == 0)
 
  329              nb_impure.combine(1);
 
  336  m_nb_pure = nb_pure.reducedValue();
 
  337  m_nb_impure = nb_impure.reducedValue();
 
  345void ConstituentItemVectorImpl::
 
  351  const Int32 component_id = m_component->id();
 
  361        if (ec.componentId() == component_id) {
 
  375        for (
MatCell mc : env_cell.subMatItems()) {
 
  376          if (mc.componentId() == component_id) {
 
  389  m_nb_impure = nb_impure;
 
 
  395void ConstituentItemVectorImpl::
 
  399  auto mvi_pure_view = m_matvar_indexes.subView(0, m_nb_pure);
 
  400  auto mvi_impure_view = m_matvar_indexes.subView(m_nb_pure, m_nb_impure);
 
  401  m_part_data->_setFromMatVarIndexes(mvi_pure_view, mvi_impure_view);
 
  410  return { m_component, m_matvar_indexes,
 
  411           m_constituent_list->view(), m_items_local_id };
 
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Types et fonctions pour gérer les synchronisations sur les accélérateurs.
Types et macros pour gérer les boucles sur les accélérateurs.
Types et macros pour gérer les énumérations des matériaux et milieux sur les accélérateurs.
#define RUNCOMMAND_MAT_ENUMERATE(ConstituentItemNameType, iter_name, env_or_mat_container,...)
Macro pour itérer sur un matériau ou un milieu.
Algorithme générique de partitionnement d'une liste.
Classe pour effectuer une réduction 'somme'.
File d'exécution pour un accélérateur.
SmallSpan< const T > smallSpan() const
Vue immutable sur ce tableau.
Vue sur une liste de mailles avec infos sur les milieux.
Maille arcane avec info matériaux et milieux.
__host__ __device__ CellEnvCellEnumerator subEnvItems() const
Enumérateur sur les mailles milieux de cette maille.
Vue sur un vecteur sur les entités d'un composant.
Index d'une entité constituant dans la liste des entités constituants.
Helper pour positionner les entités du vecteur.
Implémentation de ComponentItemVector.
void _computeNbPureAndImpureLegacy(SmallSpan< const Int32 > local_ids)
Calcul du nombre de mailles pures et impures sans API accélérateur.
__host__ __device__ CellLocalId globalCellId() const
localId() de la maille globale
__host__ __device__ bool null() const
Indique s'il s'agit de la maille nulle.
__host__ __device__ ConstituentItemIndex _constituentItemIndex() const
__host__ __device__ MatVarIndex _varIndex() const
Maille arcane d'un milieu.
Interface d'un composant (matériau ou milieu) d'un maillage.
virtual Int32 id() const =0
Identifiant du composant.
virtual bool isEnvironment() const =0
Vrai si le composant est un milieu.
virtual AllEnvCellVectorView view(const CellGroup &cells)=0
Vue sur les mailles milieux correspondant au groupe cells.
Représente un matériau d'une maille multi-matériau.
Représente un index sur les variables matériaux et milieux.
constexpr __host__ __device__ Int32 arrayIndex() const
Retourne l'indice du tableau de valeur dans la liste des variables.
Données d'une partie (pure ou partielle) d'un constituant.
Vue d'un tableau d'éléments de type T.
constexpr __host__ __device__ SizeType size() const noexcept
Retourne la taille du tableau.
RunCommand makeCommand(const RunQueue &run_queue)
Créé une commande associée à la file run_queue.
eExecutionPolicy
Politique d'exécution pour un Runner.
Active toujours les traces dans les parties Arcane concernant les matériaux.
IMemoryAllocator * getDefaultDataAllocator()
Allocateur par défaut pour les données.
std::int32_t Int32
Type entier signé sur 32 bits.