14#include "arcane/materials/MeshMaterialVariable.h"
16#include "arcane/utils/NotImplementedException.h"
17#include "arcane/utils/ScopedPtr.h"
18#include "arcane/utils/ITraceMng.h"
19#include "arcane/utils/NumericTypes.h"
20#include "arcane/utils/CheckedConvert.h"
22#include "arcane/materials/MaterialVariableBuildInfo.h"
23#include "arcane/materials/IMeshMaterial.h"
24#include "arcane/materials/MatItemEnumerator.h"
25#include "arcane/materials/MeshMaterialVariableSynchronizerList.h"
26#include "arcane/materials/ItemMaterialVariableBaseT.H"
27#include "arcane/materials/IMeshMaterialVariableSynchronizer.h"
28#include "arcane/materials/internal/MeshMaterialVariablePrivate.h"
30#include "arcane/core/IItemFamily.h"
31#include "arcane/core/IMesh.h"
32#include "arcane/core/IParallelMng.h"
33#include "arcane/core/ISubDomain.h"
34#include "arcane/core/IApplication.h"
35#include "arcane/core/IDataFactoryMng.h"
36#include "arcane/core/IParallelExchanger.h"
37#include "arcane/core/ISerializer.h"
38#include "arcane/core/ISerializeMessage.h"
39#include "arcane/core/internal/IVariableInternal.h"
40#include "arcane/core/materials/internal/IMeshComponentInternal.h"
41#include "arcane/core/VariableInfo.h"
42#include "arcane/core/VariableRefArray.h"
43#include "arcane/core/MeshVariable.h"
44#include "arcane/core/VariableArray.h"
45#include "arcane/core/ItemPrinter.h"
46#include "arcane/core/IVariableSynchronizer.h"
47#include "arcane/core/internal/IDataInternal.h"
48#include "arcane/core/Timer.h"
49#include "arcane/core/parallel/IStat.h"
50#include "arcane/core/datatype/DataTypeTraits.h"
51#include "arcane/core/datatype/DataStorageBuildInfo.h"
64template<
typename DataType>
void
67 Array<ContainerViewType>& cviews)
69 ConstArrayView<ArrayView<DataType>> views = cviews;
70 auto* true_data =
dynamic_cast<ValueDataType*
>(data);
72 ContainerType& values = true_data->_internal()->_internalDeprecatedValue();
75 values.add(views[mvi.arrayIndex()][mvi.valueIndex()]);
85template <
typename DataType>
void
87copyTo(SmallSpan<const DataType> input, SmallSpan<const Int32> input_indexes,
88 SmallSpan<DataType> output, SmallSpan<const Int32> output_indexes,
89 const RunQueue& queue)
92 Integer nb_value = input_indexes.size();
101 output[output_indexes[i]] = input[input_indexes[i]];
108template<
typename DataType>
void
115 container.resize(dim1_size,DataType());
121template<
typename DataType>
void
128 Int32 nb_add =
static_cast<Int32>(dim1_size * reserve_ratio);
129 var->_internalApi()->resize(VariableResizeArgs(dim1_size, nb_add,
true));
137 PrivatePartType* global_var,
139: BaseClass(v,global_var,global_var_ref,mvs)
160template<
typename DataType>
void
161ItemMaterialVariableScalar<DataType>::
169 setValue(mvi,values[index]);
188template<
typename DataType>
void
189ItemMaterialVariableScalar<DataType>::
195 for(
Integer i=0; i<nb_index; ++i ){
197 setValue(mvi,values[i]);
215template<
typename DataType>
void
216ItemMaterialVariableScalar<DataType>::
223 values[index] = this->operator[](mvi);
242template<
typename DataType>
void
243ItemMaterialVariableScalar<DataType>::
248 for(
Integer i=0; i<nb_index; ++i ){
250 values[i] = this->operator[](mvi);
259template<
typename DataType>
void
260ItemMaterialVariableScalar<DataType>::
261fillPartialValues(
const DataType& value)
265 Integer nb_var = m_vars.size();
266 for(
Integer i=1; i<nb_var; ++i ){
268 m_vars[i]->fill(value);
275template<
typename DataType>
Int32
279 return (
Int32)
sizeof(DataType);
285template<
typename DataType>
void
293 for(
Integer z=0; z<value_size; ++z ){
294 values[z] = this->operator[](matvar_indexes[z]);
301template<
typename DataType>
void
302ItemMaterialVariableScalar<DataType>::
303copyToBuffer(ConstArrayView<MatVarIndex> matvar_indexes,ByteArrayView bytes)
const
305 auto* ptr =
reinterpret_cast<std::byte*
>(bytes.data());
306 return _copyToBufferLegacy(matvar_indexes,{ptr,bytes.size()});
312template<
typename DataType>
void
313ItemMaterialVariableScalar<DataType>::
314_copyFromBufferLegacy(SmallSpan<const MatVarIndex> matvar_indexes,Span<const std::byte> bytes)
318 const Int32 value_size = CheckedConvert::toInt32(bytes.size() /
sizeof(DataType));
319 ConstArrayView<DataType> values(value_size,
reinterpret_cast<const DataType*
>(bytes.data()));
320 for( Integer z=0; z<value_size; ++z ){
321 setValue(matvar_indexes[z],values[z]);
328template<
typename DataType>
void
329ItemMaterialVariableScalar<DataType>::
330copyFromBuffer(ConstArrayView<MatVarIndex> matvar_indexes,ByteConstArrayView bytes)
332 auto* ptr =
reinterpret_cast<const std::byte*
>(bytes.data());
333 return _copyFromBufferLegacy(matvar_indexes,{ptr,bytes.size()});
339template<
typename DataType>
void
340ItemMaterialVariableScalar<DataType>::
343 IParallelMng* pm = m_p->materialMng()->mesh()->parallelMng();
345 Int64 message_size = 0;
348 message_size = _synchronize2();
356template<
typename DataType>
Int64
360 Int64 message_size = 0;
361 Integer sync_version = m_p->materialMng()->synchronizeVariableVersion();
367 if (sync_version>=6){
371 message_size = mmvsl.totalMessageSize();
373 else if (sync_version==5 || sync_version==4 || sync_version==3){
376 else if (sync_version==2){
387template<
typename DataType>
void
388ItemMaterialVariableScalar<DataType>::
389synchronize(MeshMaterialVariableSynchronizerList& sync_list)
391 Integer sync_version = m_p->materialMng()->synchronizeVariableVersion();
392 if (sync_version>=6){
402template<
typename DataType>
void
403ItemMaterialVariableScalar<DataType>::
423 IMeshMaterialMng* material_mng = m_p->materialMng();
424 IMesh* mesh = material_mng->mesh();
427 IItemFamily* family = mesh->cellFamily();
428 IParallelMng* pm = mesh->parallelMng();
429 if (!pm->isParallel())
431 ItemGroup all_items = family->allItems();
433 UniqueArray<DataType> saved_values;
436 ConstArrayView<DataType> var_values = m_global_variable->valueView();
437 saved_values.resize(var_values.size());
438 saved_values.copy(var_values);
442 IMeshEnvironment* env = *ienv;
444 IMeshMaterial* mat = *imat;
447 ArrayView<DataType> var_values = m_global_variable->valueView();
450 MatCell mc = *imatcell;
451 Cell c = mc.globalCell();
452 MatVarIndex mvi = mc._varIndex();
453 var_values[c.localId()] = this->operator[](mvi);
456 m_global_variable->synchronize();
458 ConstArrayView<DataType> var_values = m_global_variable->valueView();
461 MatCell mc = *imatcell;
462 Cell c = mc.globalCell();
463 MatVarIndex mvi = mc._varIndex();
464 setValue(mvi,var_values[c.localId()]);
472 ArrayView<DataType> var_values = m_global_variable->valueView();
475 EnvCell ec = *ienvcell;
476 Cell c = ec.globalCell();
477 MatVarIndex mvi = ec._varIndex();
478 var_values[c.localId()] = this->operator[](mvi);
481 m_global_variable->synchronize();
483 ConstArrayView<DataType> var_values = m_global_variable->valueView();
486 EnvCell ec = *ienvcell;
487 Cell c = ec.globalCell();
488 MatVarIndex mvi = ec._varIndex();
489 setValue(mvi,var_values[c.localId()]);
496 ArrayView<DataType> var_values = m_global_variable->valueView();
497 var_values.copy(saved_values);
499 m_global_variable->synchronize();
505template<
typename DataType>
void
506ItemMaterialVariableScalar<DataType>::
526 IMeshMaterialMng* material_mng = m_p->materialMng();
527 IMesh* mesh = material_mng->mesh();
530 IItemFamily* family = mesh->cellFamily();
531 IParallelMng* pm = mesh->parallelMng();
532 if (!pm->isParallel())
534 ItemGroup all_items = family->allItems();
535 ITraceMng* tm = pm->traceMng();
536 tm->info(4) <<
"MAT_SYNCHRONIZE_V2 name=" << this->name();
537 IDataFactoryMng* df = m_global_variable->dataFactoryMng();
539 DataStorageTypeInfo storage_type_info(VariableInfo::_internalGetStorageTypeInfo(m_global_variable->dataType(),2,0));
540 DataStorageBuildInfo storage_build_info(tm);
541 String storage_full_type = storage_type_info.fullName();
543 Ref<IData> xdata(df->createSimpleDataRef(storage_full_type,storage_build_info));
544 auto* data =
dynamic_cast< IArray2DataT<DataType>*
>(xdata.get());
548 ConstArrayView<MeshMaterialVariableIndexer*> indexers = material_mng->_internalApi()->variablesIndexer();
549 Integer nb_indexer = indexers.size();
550 data->_internal()->_internalDeprecatedValue().resize(family->maxLocalId(),nb_indexer+1);
551 Array2View<DataType> values(data->view());
554 for( MeshMaterialVariableIndexer* indexer : indexers ){
555 ConstArrayView<MatVarIndex> matvar_indexes = indexer->matvarIndexes();
556 ConstArrayView<Int32> local_ids = indexer->localIds();
557 for( Integer j=0, n=matvar_indexes.size(); j<n; ++j ){
558 MatVarIndex mvi = matvar_indexes[j];
559 values[local_ids[j]][mvi.arrayIndex()] = this->operator[](mvi);
562 family->allItemsSynchronizer()->synchronizeData(data);
565 for( MeshMaterialVariableIndexer* indexer : indexers ){
566 ConstArrayView<MatVarIndex> matvar_indexes = indexer->matvarIndexes();
567 ConstArrayView<Int32> local_ids = indexer->localIds();
568 for( Integer j=0, n=matvar_indexes.size(); j<n; ++j ){
569 MatVarIndex mvi = matvar_indexes[j];
570 setValue(mvi,values[local_ids[j]][mvi.arrayIndex()]);
574 m_global_variable->synchronize();
580template<
typename DataType>
void
581ItemMaterialVariableScalar<DataType>::
592 IMeshMaterialMng* material_mng = m_p->materialMng();
594 IMeshMaterialVariableSynchronizer* mmvs = material_mng->_internalApi()->allCellsMatEnvSynchronizer();
595 IVariableSynchronizer* var_syncer = mmvs->variableSynchronizer();
596 IParallelMng* pm = var_syncer->parallelMng();
598 if (!pm->isParallel())
601 mmvs->checkRecompute();
604 ITraceMng* tm = pm->traceMng();
605 tm->info(4) <<
"MAT_SYNCHRONIZE_V5 name=" << this->name();
610 Integer nb_rank = ranks.size();
611 std::vector< UniqueArray<DataType> > shared_values(nb_rank);
612 std::vector< UniqueArray<DataType> > ghost_values(nb_rank);
614 UniqueArray<Parallel::Request> requests;
618 for( Integer i=0; i<nb_rank; ++i ){
619 Int32 rank = ranks[i];
620 ConstArrayView<MatVarIndex> ghost_matcells(mmvs->ghostItems(i));
621 Integer total = ghost_matcells.size();
622 ghost_values[i].resize(total);
623 Integer total_byte = CheckedConvert::multiply(total,data_type_size);
624 ByteArrayView bytes(total_byte,(Byte*)(ghost_values[i].unguardedBasePointer()));
625 requests.add(pm->recv(bytes,rank,
false));
629 for( Integer i=0; i<nb_rank; ++i ){
630 Int32 rank = ranks[i];
631 ConstArrayView<MatVarIndex> shared_matcells(mmvs->sharedItems(i));
632 Integer total = shared_matcells.size();
633 shared_values[i].resize(total);
634 ArrayView<DataType> values(shared_values[i]);
635 for( Integer z=0; z<total; ++z ){
636 values[z] = this->operator[](shared_matcells[z]);
638 Integer total_byte = CheckedConvert::multiply(total,data_type_size);
639 ByteArrayView bytes(total_byte,(Byte*)(values.unguardedBasePointer()));
640 requests.add(pm->send(bytes,rank,
false));
643 pm->waitAllRequests(requests);
646 for( Integer i=0; i<nb_rank; ++i ){
647 ConstArrayView<MatVarIndex> ghost_matcells(mmvs->ghostItems(i));
648 Integer total = ghost_matcells.size();
649 ConstArrayView<DataType> values(ghost_values[i].constView());
650 for( Integer z=0; z<total; ++z ){
651 setValue(ghost_matcells[z],values[z]);
660template<
typename DataType>
void
661ItemMaterialVariableScalar<DataType>::
664 ostr <<
"Dumping values for material variable name=" << this->
name() <<
'\n';
667 ostr <<
"Cell uid=" <<
ItemPrinter(all_env_cell.
globalCell()) <<
" v=" << value(all_env_cell._varIndex()) <<
'\n';
670 ostr <<
"env_value=" << value(evi) <<
", mvi=" << evi <<
'\n';
673 ostr <<
"mat_value=" << value(mvi) <<
", mvi=" << mvi <<
'\n';
682template<
typename DataType>
void
683ItemMaterialVariableScalar<DataType>::
684dumpValues(std::ostream& ostr)
686 ostr <<
"Dumping values for material variable name=" << this->
name() <<
'\n';
687 IItemFamily* family = m_global_variable->itemFamily();
697template<
typename DataType>
void
698ItemMaterialVariableScalar<DataType>::
701 IItemFamily* family = m_global_variable->itemFamily();
711 switch(sbuf->
mode()){
712 case ISerializer::ModeReserve:
720 nb_val += envcell.nbMaterial();
723 tm->
info() <<
"RESERVE: nb_value=" << 1 <<
" size=" << (nb_val*nb_count);
733 values.
add(value(ienvcell._varIndex()));
736 values.
add(value(imatcell._varIndex()));
743 tm->
info() <<
"PUT: nb_value=" << nb_value <<
" size=" << basic_values.
size();
752 basic_values.
resize(nb_value*nb_count);
759 setValue(ienvcell._varIndex(),data_values[index]);
763 setValue(imatcell._varIndex(),data_values[index]);
782template<
typename ItemType,
typename DataType>
787, m_true_global_variable_ref(global_var_ref)
794template<
typename ItemType,
typename DataType>
806#define ARCANE_INSTANTIATE_MAT(type) \
807 template class ItemMaterialVariableBase< MaterialVariableScalarTraits<type> >;\
808 template class ItemMaterialVariableScalar<type>;\
809 template class MeshMaterialVariableScalar<Cell,type>;\
810 template class MeshMaterialVariableCommonStaticImpl<MeshMaterialVariableScalar<Cell,type>>
812ARCANE_INSTANTIATE_MAT(
Byte);
813ARCANE_INSTANTIATE_MAT(
Int8);
814ARCANE_INSTANTIATE_MAT(Int16);
815ARCANE_INSTANTIATE_MAT(Int32);
816ARCANE_INSTANTIATE_MAT(Int64);
817ARCANE_INSTANTIATE_MAT(BFloat16);
818ARCANE_INSTANTIATE_MAT(
Float16);
819ARCANE_INSTANTIATE_MAT(
Float32);
820ARCANE_INSTANTIATE_MAT(
Real);
821ARCANE_INSTANTIATE_MAT(Real2);
822ARCANE_INSTANTIATE_MAT(Real3);
823ARCANE_INSTANTIATE_MAT(Real2x2);
824ARCANE_INSTANTIATE_MAT(Real3x3);
#define ARCANE_CHECK_ACCESSIBLE_POINTER(queue_or_runner_or_policy, ptr)
Macro qui vérifie en mode check si ptr est accessible pour une RunQueue ou un Runner.
#define ARCANE_CHECK_POINTER(ptr)
Macro retournant le pointeur ptr s'il est non nul ou lancant une exception s'il est nul.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
#define RUNCOMMAND_LOOP1(iter_name, x1,...)
Boucle sur accélérateur avec arguments supplémentaires pour les réductions.
Integer size() const
Nombre d'éléments du vecteur.
Vue modifiable d'un tableau d'un type T.
void resize(Int64 s)
Change le nombre d'éléments du tableau à s.
void add(ConstReferenceType val)
Ajoute l'élément val à la fin du tableau.
const T * data() const
Accès à la racine du tableau hors toute protection.
Vue constante d'un tableau de type T.
constexpr Integer size() const noexcept
Nombre d'éléments du tableau.
Interface d'une famille d'entités.
virtual ItemGroup allItems() const =0
Groupe de toutes les entités.
virtual ITraceMng * traceMng() const =0
Gestionnaire de trace associé
virtual ItemVectorView view(Int32ConstArrayView local_ids)=0
Vue sur les entités.
Interface du gestionnaire de parallélisme pour un sous-domaine.
virtual IStat * stat()=0
Gestionnaire des statistiques.
virtual ITimerMng * timerMng() const =0
Gestionnaire de timers.
Interface d'un sérialiseur.
virtual void reserve(eBasicDataType dt, Int64 n)=0
Réserve de la mémoire pour n objets de type dt.
@ ModePut
Le sérialiseur attend des reserve()
@ ModeGet
Le sérialiseur attend des get()
virtual Int64 getInt64()=0
Récupère une taille.
virtual void putSpan(Span< const Real > values)
Ajoute le tableau values.
virtual eMode mode() const =0
Mode de fonctionnement actuel.
virtual void getSpan(Span< Real > values)
Récupère le tableau values.
virtual void reserveSpan(eBasicDataType dt, Int64 n)=0
Réserve de la mémoire pour n valeurs de dt.
virtual void putInt64(Int64 value)=0
Ajoute l'entier value.
Interface du gestionnaire de traces.
virtual TraceMessage info()=0
Flot pour un message d'information.
Classe utilitaire pour imprimer les infos sur une entité.
Vue sur un vecteur d'entités.
Maille arcane avec info matériaux et milieux.
Enumérateur sur les constituants d'une maille.
Cell globalCell() const
Maille globale.
Maille arcane d'un milieu.
Interface d'un composant (matériau ou milieu) d'un maillage.
virtual IMeshComponentInternal * _internalApi()=0
API interne.
Interface du gestionnaire des matériaux et des milieux d'un maillage.
virtual AllEnvCellVectorView view(const CellGroup &cells)=0
Vue sur les mailles milieux correspondant au groupe cells.
Interface d'un matériau d'un maillage.
ARCANE_MATERIALS_EXPORT void dumpValues(std::ostream &ostr) override
Affiche les valeurs de la variable sur le flot ostr.
Représente un matériau d'une maille multi-matériau.
Représente un index sur les variables matériaux et milieux.
Caractéristiques pour une variable matériaux scalaire.
Synchronisation d'une liste de variables matériaux.
String name() const override
Nom de la variable.
MatVarSpace space() const override
Espace de définition de la variable (matériau+milieu ou milieu uniquement)
virtual void add(const String &name, double elapsed_time, Int64 msg_size)=0
Ajoute une statistique.
Vue d'un tableau d'éléments de type T.
constexpr __host__ __device__ SizeType size() const noexcept
Retourne la taille du tableau.
constexpr __host__ __device__ pointer data() const noexcept
Pointeur sur le début de la vue.
Vue d'un tableau d'éléments de type T.
Sentinelle pour le timer. La sentinelle associée à un timer permet de déclancher celui-ci au moment d...
@ TimerReal
Timer utilisant le temps réel.
Real lastActivationTime() const
Retourne le temps (en secondes) passé lors de la dernière activation du timer.
Vecteur 1D de données avec sémantique par valeur (style STL).
RunCommand makeCommand(const RunQueue &run_queue)
Créé une commande associée à la file run_queue.
Active toujours les traces dans les parties Arcane concernant les matériaux.
MatVarSpace
Espace de définition d'une variable matériau.
@ Environment
Variable ayant des valeurs uniquement sur les milieux.
std::int8_t Int8
Type entier signé sur 8 bits.
Integer arcaneCheckArraySize(unsigned long long size)
Vérifie que size peut être converti dans un 'Integer' pour servir de taille à un tableau....
ArrayView< Byte > ByteArrayView
Equivalent C d'un tableau à une dimension de caractères.
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
ConstArrayView< Int32 > Int32ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
@ Float16
Donnée de type Float16.
UniqueArray< Int32 > Int32UniqueArray
Tableau dynamique à une dimension d'entiers 32 bits.
double Real
Type représentant un réel.
unsigned char Byte
Type d'un octet.
float Float32
Type flottant IEEE-753 simple précision.
eDataType
Type d'une donnée.
@ DT_Int64
Donnée de type entier 64 bits.
std::int32_t Int32
Type entier signé sur 32 bits.