14#include "arcane/impl/internal/ArrayData.h"
16#include "arcane/utils/NotSupportedException.h"
17#include "arcane/utils/Real2.h"
18#include "arcane/utils/Real2x2.h"
19#include "arcane/utils/Real3.h"
20#include "arcane/utils/Real3x3.h"
21#include "arcane/utils/IHashAlgorithm.h"
22#include "arcane/utils/NotImplementedException.h"
23#include "arcane/utils/IndexOutOfRangeException.h"
24#include "arcane/utils/ArgumentException.h"
25#include "arcane/utils/FatalErrorException.h"
26#include "arcane/utils/ITraceMng.h"
27#include "arcane/utils/CheckedConvert.h"
28#include "arcane/utils/MemoryAllocator.h"
31#include "arcane/core/datatype/DataStorageBuildInfo.h"
32#include "arcane/core/datatype/IDataOperation.h"
34#include "arcane/core/ISerializer.h"
36#include "arcane/impl/SerializedData.h"
45 inline constexpr Int64 SERIALIZE_MAGIC_NUMBER = 0x456ff989;
51template <
typename DataType> ArrayDataT<DataType>::
52ArrayDataT(ITraceMng* trace)
53: m_value(AlignedMemoryAllocator::Simd())
55, m_internal(new Impl(this))
63template <
typename DataType> ArrayDataT<DataType>::
64ArrayDataT(
const ArrayDataT<DataType>& rhs)
65: m_value(AlignedMemoryAllocator::Simd())
67, m_internal(new Impl(this))
69, m_allocation_info(rhs.m_allocation_info)
71 m_value = rhs.m_value.constSpan();
77template <
typename DataType> ArrayDataT<DataType>::
78ArrayDataT(
const DataStorageBuildInfo& dsbi)
79: m_value(dsbi.memoryAllocator())
80, m_trace(dsbi.traceMng())
81, m_internal(new Impl(this))
89template <
typename DataType> ArrayDataT<DataType>::
101template <
typename DataType> DataStorageTypeInfo ArrayDataT<DataType>::
102staticStorageTypeInfo()
104 typedef DataTypeTraitsT<DataType> TraitsType;
106 Int32 nb_basic_type = TraitsType::nbBasicType();
109 return DataStorageTypeInfo(bdt, nb_basic_type, dimension, multi_tag);
118 return staticStorageTypeInfo();
170 m_shape =
sdata->shape();
173 sdata->setWritableBytes(buffer);
182 ARCANE_UNUSED(
sdata);
197 switch (
sbuf->mode()) {
198 case ISerializer::ModeReserve: {
199 Int64
nb_value = m_value.largeSize();
201 m_trace->
debug(
Trace::High) <<
" ArrayDataT::serialize (full) reserve datatype="
203 sbuf->reserveInt64(2);
206 case ISerializer::ModePut: {
207 Int64
nb_value = m_value.largeSize();
209 m_trace->
debug(
Trace::High) <<
" ArrayDataT::serialize (full) put datatype="
212 for (Int64 i = 0; i <
nb_value; ++i)
220 case ISerializer::ModeGet: {
225 ARCANE_FATAL(
"Internal errror: bad magic number for serialisation expected={0} current={1}",
233 switch (
sbuf->readMode()) {
234 case ISerializer::ReadReplace: {
241 operation->applySpan(m_value, data_value);
243 for (Int64 i = 0; i <
nb_value; ++i)
245 << data_value[i] <<
" transformed value=" << m_value[i];
251 for (Int64 i = 0; i <
nb_value; ++i)
255 case ISerializer::ReadAdd: {
263 for (Int64 i = 0; i <
nb_value; ++i)
278 _serialize(
sbuf, ids, operation);
295 switch (
sbuf->mode()) {
296 case ISerializer::ModeReserve: {
297 m_trace->
debug(
Trace::High) <<
" ArrayDataT::serialize (partial) reserve datatype="
299 sbuf->reserveInt64(2);
302 case ISerializer::ModePut: {
303 m_trace->
debug(
Trace::High) <<
" ArrayDataT::serialize (partial) put datatype="
304 << data_type <<
" ids=" << nb_value <<
" totalsize=" << total_size;
307 for (Integer i = 0, max_value = m_value.size(); i < nb_value; ++i)
308 if (ids[i] > max_value)
309 throw IndexOutOfRangeException(A_FUNCINFO,
310 String::format(
" put,serialize : bad sizes i={0} ids[i]={1} nb_value={2} this={3}",
311 i, ids[i], max_value,
this),
315 UniqueArray<BasicType> base_value;
316 base_value.reserve(total_size);
317 for (
Int64 i = 0; i < nb_value; ++i) {
319 m_trace->debug(
Trace::Highest) <<
"Put i=" << i <<
" index=" << ids[i] <<
" value=" << m_value[ids[i]];
321 ConstArrayView<BasicType> current_value(nb_count,
reinterpret_cast<BasicType*
>(&m_value[ids[i]]));
322 base_value.addRange(current_value);
324 sbuf->
putInt64(SERIALIZE_MAGIC_NUMBER);
328 case ISerializer::ModeGet: {
329 m_trace->debug(
Trace::High) <<
" ArrayDataT::serialize (partial) get mode=" << sbuf->
readMode()
330 <<
" datatype=" << data_type
331 <<
" ids=" << nb_value <<
" totalsize=" << total_size;
334 for (Integer i = 0, max_value = m_value.size(); i < nb_value; ++i)
335 if (ids[i] > max_value)
336 throw IndexOutOfRangeException(A_FUNCINFO,
337 String::format(
" put,serialize : bad sizes i={0} ids[i]={1} nb_value={2} this={3}",
338 i, ids[i], max_value,
this),
343 case ISerializer::ReadReplace: {
347 if (saved_magic_number != SERIALIZE_MAGIC_NUMBER)
348 ARCANE_FATAL(
"Internal errror: bad magic number for serialisation expected={0} current={1}",
349 SERIALIZE_MAGIC_NUMBER, saved_magic_number);
351 if (saved_nb_value != nb_value)
352 ARCANE_FATAL(
"Internal errror: bad size for serialisation expected={0} found={1}",
353 nb_value, saved_nb_value);
355 UniqueArray<BasicType> base_value(total_size);
358 Span<DataType> data_value(
reinterpret_cast<DataType*
>(base_value.data()), nb_value);
359 UniqueArray<DataType> current_value;
360 Span<DataType> transformed_value;
362 if (operation && nb_value != 0) {
363 current_value.resize(ids.size());
365 transformed_value = current_value.view();
366 operation->applySpan(transformed_value, data_value);
369 transformed_value = data_value;
374 for (
Int64 i = 0; i < nb_value; ++i)
376 <<
" value=" << data_value[i] <<
" transformed value=" << transformed_value[i];
378 for (
Int64 i = 0; i < nb_value; ++i)
379 m_trace->debug(
Trace::Highest) <<
"Get i=" << i <<
" index=" << ids[i]
380 <<
" value=" << data_value[i];
383 for (
Int64 i = 0; i < nb_value; ++i) {
384 m_value[ids[i]] = transformed_value[i];
387 case ISerializer::ReadAdd:
388 ARCANE_THROW(NotImplementedException,
"ArrayData::serialize : Cannot deserialize with ReadAdd mode");
401 m_value.fill(DataType());
410 m_value.setDebugName(name);
421 const Byte*
ptr =
reinterpret_cast<const Byte*
>(m_value.data());
433 hash_info.context()->updateHash(asBytes(m_value.span()));
472template <
typename DataType>
void ArrayDataT<DataType>::
475 m_shape.setNbDimension(1);
476 m_shape.setDimension(0, 1);
485 if (m_allocation_info == v)
487 m_allocation_info = v;
488 m_value.setMemoryLocationHint(v.memoryLocationHint());
503 MemoryUtils::copy(
new_value.span(), m_value.constSpan());
506 m_allocation_info.setMemoryLocationHint(
alloc_info.memoryLocationHint());
#define ARCANE_THROW(exception_class,...)
Macro pour envoyer une exception avec formattage.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Fonctions de gestion mémoire et des allocateurs.
Donnée tableau d'un type T.
Tableau d'items de types quelconques.
Informations sur l'allocation d'une donnée.
Informations pour le calcul du hash d'une donnée.
Informations de type pour un conteneur de données.
Interface d'une opération sur une donnée.
Interface d'un algorithme de hashage.
Interface d'une donnée sérialisée.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Exception lorsqu'un argument est invalide.
Vue constante d'un tableau de type T.
Interface d'un sérialiseur.
virtual void putSpan(Span< const Real > values)
Ajoute le tableau values.
virtual void getSpan(Span< Real > values)
Récupère le tableau values.
virtual Int64 getInt64()=0
Récupère une taille.
virtual eReadMode readMode() const =0
Mode de lecture.
virtual void putInt64(Int64 value)=0
Ajoute l'entier value.
Options pour configurer les allocations.
Exception lorsqu'une fonction n'est pas implémentée.
Chaîne de caractères unicode.
TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium) const
Flot pour un message de debug.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Ref< ISerializedData > arcaneCreateSerializedDataRef(eDataType data_type, Int64 memory_size, Integer nb_dim, Int64 nb_element, Int64 nb_base_element, bool is_multi_size, Int64ConstArrayView dimensions)
Créé des données sérialisées.
bool arcaneIsDebug()
Vrai si la macro ARCANE_DEBUG est définie.
eDataType
Type d'une donnée.
@ Highest
Niveau le plus élevé
eBasicDataType
Type d'une donnée de base.
void sampleSpan(Span< const DataType > values, Span< const Int64 > indexes, Span< DataType > result)
Extrait un sous-tableau à à partir d'une liste d'index.