14#include "arcane/utils/NotSupportedException.h"
15#include "arcane/utils/HashTableMap.h"
16#include "arcane/utils/Collection.h"
18#include "arcane/core/VariableTypes.h"
20#include "arcane/core/ItemPrinter.h"
21#include "arcane/core/ISerializer.h"
22#include "arcane/core/IItemFamily.h"
23#include "arcane/core/ItemVector.h"
24#include "arcane/core/MeshToMeshTransposer.h"
25#include "arcane/core/ItemFamilySerializeArgs.h"
26#include "arcane/core/IParallelMng.h"
28#include "arcane/core/IMesh.h"
29#include "arcane/core/IVariableMng.h"
30#include "arcane/core/ISubDomain.h"
32#include "arcane/mesh/ItemFamilyVariableSerializer.h"
46class ItemFamilyExchange;
57 const Integer VARIABLE_MAGIC_NUMBER = 0x3a9e4324;
62ItemFamilyVariableSerializer::
63ItemFamilyVariableSerializer(IItemFamily* family)
64: TraceAccessor(family->traceMng())
65, m_item_family(family)
72ItemFamilyVariableSerializer::
73~ItemFamilyVariableSerializer()
80void ItemFamilyVariableSerializer::
93 family_to_exchange.
add(m_item_family);
96 family_to_exchange.
add(child_family);
98 for (
Integer i = 0; i < family_to_exchange.
size(); ++i) {
99 IItemFamily* current_family = family_to_exchange[i];
100 info(4) <<
" Serializing family " << current_family->
fullName();
104 for (VariableCollection::Enumerator i_var(used_vars); ++i_var;) {
116 if (var_family == current_family) {
131void ItemFamilyVariableSerializer::
134 switch (sbuf->
mode()) {
135 case ISerializer::ModeReserve:
137 sbuf->reserveInteger(1);
138 sbuf->reserveInteger(1);
142 sbuf->
put(VARIABLE_MAGIC_NUMBER);
148 if (magic_number != VARIABLE_MAGIC_NUMBER)
149 ARCANE_FATAL(
"Internal error: bad magic number expected={0} found={1}",
150 VARIABLE_MAGIC_NUMBER, magic_number);
154 if (local_ids.
size() != nb_item) {
158 ARCANE_FATAL(
"Bad value for received_items family={0} n={1} expected={2}",
159 m_item_family->name(), local_ids, nb_item);
171void ItemFamilyVariableSerializer::
175 switch (sbuf->
mode()) {
176 case ISerializer::ModeReserve:
181 sbuf->
put(var_full_name);
185 sbuf->
get(expected_name);
186 if (expected_name != var_full_name)
187 ARCANE_FATAL(
"Incoherent variable var={0} expected={1}",
188 var_full_name, expected_name);
200void ItemFamilyVariableSerializer::
207 String mode_str = (is_recv) ?
"recv" :
"send";
210 Int32 owner_rank = (is_recv) ? m_item_family->parallelMng()->commRank() : args.
rank();
215 info(4) <<
"-- Serializing variable " << var->fullName()
216 <<
" group=" << var->itemGroup().name()
217 <<
" (n=" << var->itemGroup().size() <<
")"
218 <<
" mode=" << (int)sbuf->
mode()
219 <<
" target_rank=" << args.
rank();
230 if (var->itemFamily() != m_item_family) {
234 m_item_family->
view(local_ids),
239 Int32 lid = iitem.localId();
240 if (lid != NULL_ITEM_LOCAL_ID && iitem->owner() == owner_rank) {
246 if (var->isPartial())
249 var->serialize(sbuf, dest_lids);
252 if (var->isPartial())
255 var->serialize(sbuf, local_ids);
280void ItemFamilyVariableSerializer::
288 case ISerializer::ModeReserve:
292 std::set<Int32> items_to_send;
293 for (
Integer i = 0, n = local_ids.
size(); i < n; ++i) {
294 items_to_send.insert(local_ids[i]);
297 if (items_to_send.find(iitem.itemLocalId()) != items_to_send.end()) {
298 indexes_to_send.
add(iitem.index());
299 unique_ids_to_send.
add((*iitem).uniqueId());
303 if (mode == ISerializer::ModeReserve) {
310 sbuf->
putSpan(unique_ids_to_send);
323 unique_ids.
resize(nb_item);
328 unique_ids_to_index.
nocheckAdd((*iitem).uniqueId(), iitem.index());
331 for (
Integer i = 0; i < nb_item; ++i) {
338 ARCANE_FATAL(
"Can not find item with unique_id={0} index={1}", unique_ids[i], i);
339 indexes[i] = data->value();
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Integer size() const
Number of elements in the vector.
void resize(Int64 s)
Changes the number of elements in the array to s.
void add(ConstReferenceType val)
Adds element val to the end of the array.
void reserve(Int64 new_capacity)
Reserves memory for new_capacity elements.
constexpr Integer size() const noexcept
Number of elements in the array.
Hash table for associative arrays.
void nocheckAdd(KeyTypeConstRef id, const ValueType &value)
Adds the value value corresponding to the key id.
Data * lookup(KeyTypeConstRef id)
Searches for the value corresponding to key id.
Interface of an entity family.
virtual String fullName() const =0
Full family name (with the mesh's name).
virtual ItemVectorView view(Int32ConstArrayView local_ids)=0
View on the entities.
void reserveInt64(Int64 n)
Reserve for n Int64.
virtual void reserve(eBasicDataType dt, Int64 n)=0
Reserves memory for n objects of type dt.
virtual Integer getInteger()=0
Retrieve a size.
eMode
Serializer operating mode.
@ ModePut
The serializer expects reserve().
@ ModeGet
The serializer expects get().
virtual Int64 getInt64()=0
Retrieve a size.
virtual void put(Span< const Real > values)=0
Add the array values.
virtual void putSpan(Span< const Real > values)
Add the array values.
virtual eMode mode() const =0
Current operating mode.
virtual void getSpan(Span< Real > values)
Retrieve the array values.
virtual void get(ArrayView< Real > values)=0
Retrieve the array values.
virtual void reserveSpan(eBasicDataType dt, Int64 n)=0
Reserves memory for n values of dt.
virtual void putInt64(Int64 value)=0
Add the integer value.
Variable manager interface.
virtual VariableCollection usedVariables()=0
List of used variables.
virtual String fullName() const =0
Full variable name (with family prefix).
@ PNoExchange
Indicates that the variable should not be exchanged.
virtual int property() const =0
Returns the properties of the variable.
virtual ItemGroup itemGroup() const =0
Associated mesh group.
virtual void serialize(ISerializer *sbuffer, IDataOperation *operation=0)=0
virtual IItemFamily * itemFamily() const =0
Associated entity family.
Arguments for the serialization callbacks of entity families.
Int32 rank() const
Rank of the source or destination.
Int32ConstArrayView localIds() const
Local indices of the entities. During serialization, these are the local indices of the entities sent...
ISerializer * serializer() const
Associated serializer.
Integer size() const
Number of elements in the group.
Utility class for printing information about an entity.
Int32 size() const
Number of elements in the vector.
static ItemVector transpose(IMesh *meshA, IMesh *meshB, ItemVectorView itemsA, bool do_fatal=false)
Transpose itemsA from meshB to items on meshB.
Unicode character string.
TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium) const
Flow for a debug message.
TraceMessage info() const
Flow for an information message.
1D data vector with value semantics (STL style).
void _serializePartialVariable(IVariable *var, ISerializer *sbuf, Int32ConstArrayView local_ids)
Serialise une variable partielle.
void _checkSerializationVariable(ISerializer *sbuf, IVariable *var)
Serializes the variable name to verify that deserialization is correct.
void _checkSerialization(ISerializer *sbuf, Int32ConstArrayView local_ids)
Serializes a magic number and the number of entities to verify that deserialization is correct.
UniqueArray< IVariable * > m_variables_to_exchange
List of variables to exchange.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
UniqueArray< Int64 > Int64UniqueArray
Dynamic 1D array of 64-bit integers.
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
@ Int64
64-bit integer data type
Collection< IItemFamily * > IItemFamilyCollection
Collection of item families.
bool arcaneIsDebug()
True if the ARCANE_DEBUG macro is defined.
UniqueArray< Int32 > Int32UniqueArray
Dynamic 1D array of 32-bit integers.
std::int32_t Int32
Signed integer type of 32 bits.