14#include "arcane/core/VariableScalar.h"
16#include "arcane/utils/NotSupportedException.h"
17#include "arcane/utils/ArgumentException.h"
18#include "arcane/utils/FatalErrorException.h"
19#include "arcane/utils/TraceInfo.h"
20#include "arcane/utils/Ref.h"
21#include "arcane/utils/ITraceMng.h"
23#include "arcane/core/VariableDiff.h"
24#include "arcane/core/VariableBuildInfo.h"
25#include "arcane/core/VariableInfo.h"
26#include "arcane/core/IApplication.h"
27#include "arcane/core/IVariableMng.h"
28#include "arcane/core/IItemFamily.h"
29#include "arcane/core/IVariableSynchronizer.h"
30#include "arcane/core/IDataReader.h"
31#include "arcane/core/ItemGroup.h"
32#include "arcane/core/IDataFactoryMng.h"
33#include "arcane/core/IParallelMng.h"
34#include "arcane/core/IMesh.h"
35#include "arcane/core/VariableComparer.h"
36#include "arcane/core/internal/IVariableInternal.h"
37#include "arcane/core/internal/IVariableMngInternal.h"
39#include "arcane/core/datatype/DataStorageBuildInfo.h"
50template <
class DataType>
65 const bool compare_ghost = compare_args.isCompareGhost();
78 bool compare_failed =
false;
81 const Item& item = *i;
82 if (!item.
isOwn() && !compare_ghost)
85 if (group_index_table) {
86 index = (*group_index_table)[index];
91 DataType diff = DataType();
92 if (index >= ref_size) {
94 compare_failed =
true;
97 DataType dref = ref[index];
98 DataType dcurrent = current[index];
99 if (VarDataTypeTraits::verifDifferent(dref, dcurrent, diff,
true)) {
100 this->m_diffs_info.add(DiffInfo(dcurrent, dref, diff, item, NULL_ITEM_ID));
105 if (compare_failed) {
108 msg->
pinfo() <<
"Processor " << sid <<
" : "
109 <<
" Unable to compare : elements numbers are different !"
110 <<
" for the variable " << var_name <<
" ref_size=" << ref_size;
113 this->_sortAndDump(var, pm, compare_args);
119 checkReplica(
IVariable* var,
const DataType& var_value,
125 const int max_print = compare_args.maxPrint();
129 if constexpr (std::is_same<TrueType, ReduceType>::value)
130 return _checkReplica2(replica_pm, var_value);
131 ARCANE_UNUSED(replica_pm);
133 ARCANE_UNUSED(var_value);
134 ARCANE_UNUSED(max_print);
141 _checkReplica2(
IParallelMng* pm,
const DataType& var_value)
151 DataType diff = DataType();
152 if (VarDataTypeTraits::verifDifferent(min_value, max_value, diff,
true)) {
153 this->m_diffs_info.add(DiffInfo(min_value, max_value, diff, 0, NULL_ITEM_ID));
173 String storage_full_type =
info.storageTypeInfo().fullName();
174 Ref<IData> data = df->createSimpleDataRef(storage_full_type, storage_build_info);
175 m_value =
dynamic_cast<ValueDataType*
>(
data.get());
185 ThatClass* true_ptr = 0;
189 true_ptr =
dynamic_cast<ThatClass*
>(var);
191 true_ptr =
new ThatClass(vb, vi);
194 ARCANE_CHECK_PTR(true_ptr);
206 ThatClass* true_ptr =
dynamic_cast<ThatClass*
>(var);
208 ARCANE_FATAL(
"Can not build a reference from variable {0}", var->name());
221 _checkIfSameOnAllReplicaHelper(
IVariable* var,
const T& value,
225 return csa.checkReplica(var, value, compare_args);
230 _checkIfSameOnAllReplicaHelper(
IVariable* var,
const Byte& value,
235 return csa.checkReplica(var, int_value, compare_args);
245 switch (compare_args.compareMode()) {
255 reader->
read(
this, ref_data.
get());
256 ref = ref_data->value();
270 ARCANE_FATAL(
"Invalid value for compare mode '{0}'", (
int)compare_args.compareMode());
277print(std::ostream& o)
const
279 o << m_value->value();
298 ARCANE_UNUSED(local_ids);
307 return static_cast<Real>(
sizeof(T));
316 ARCANE_UNUSED(source);
317 ARCANE_UNUSED(destination);
328 ARCANE_UNUSED(first_source);
329 ARCANE_UNUSED(second_source);
330 ARCANE_UNUSED(destination);
339 ARCANE_UNUSED(new_to_old_ids);
356 ARCANE_UNUSED(group);
362template <
typename DataType>
void
366 _checkSwapIsValid(&rhs);
367 m_value->swapValues(rhs.m_value);
370 rhs.syncReferences();
376ARCANE_INTERNAL_INSTANTIATE_TEMPLATE_FOR_NUMERIC_DATATYPE(VariableScalarT);
377template class VariableScalarT<String>;
#define ARCANE_CHECK_POINTER(ptr)
Macro returning the pointer ptr if it is not null or throwing an exception if it is null.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Exception when an argument is invalid.
Constant view of an array of type T.
constexpr Integer size() const noexcept
Number of elements in the array.
Information to construct an instance of 'IData'.
Base class of a hash table between group items and their positions in the table.
Interface of the data factory manager.
Interface for reading variable data.
virtual void read(IVariable *var, IData *data)=0
Reads the data data of the variable var.
Interface of the parallelism manager for a subdomain.
virtual Int32 commRank() const =0
Rank of this instance in the communicator.
virtual Int32 commSize() const =0
Number of instances in the communicator.
virtual char reduce(eReduceType rt, char v)=0
Performs a reduction of type rt on the real v and returns the value.
virtual TraceMessage pinfo()=0
Stream for a parallel information message.
virtual IParallelMng * replicaParallelMng() const =0
Returns the IParallelMng of the mesh replica associated with the variable.
virtual void addVariable(IVariable *var)=0
Adds a variable.
Variable manager interface.
virtual IVariable * checkVariable(const VariableInfo &infos)=0
Checks a variable.
virtual IVariableMngInternal * _internalApi()=0
Internal Arcane API.
virtual bool isPartial() const =0
Indicates if the variable is partial.
virtual ItemGroup itemGroup() const =0
Associated mesh group.
virtual String name() const =0
Variable name.
virtual IVariableInternal * _internalApi()=0
Internal Arcane API.
SharedPtrT< GroupIndexTable > localIdToIndex() const
Table of local ids to a position for all entities in the group.
bool null() const
true means the group is the null group
IMesh * mesh() const
Mesh to which this group belongs (0 for the null group).
Base class for a mesh element.
constexpr Int32 localId() const
Local identifier of the entity in the processor subdomain.
constexpr bool isOwn() const
true if the entity belongs to the subdomain
Exception when an operation is not supported.
InstanceType * get() const
Associated instance or nullptr if none.
Reference to an instance.
Unicode character string.
TraceMessage info() const
Flow for an information message.
Parameters necessary for building a variable.
Arguments for VariableComparer methods.
Results of a comparison operation.
Template class for information about a variable type.
Base class for value comparisons between two variables.
Information characterizing a variable.
IData * data() override
Data associated with the variable.
void copyItemsValues(Int32ConstArrayView source, Int32ConstArrayView destination) override
Copies the values of entities numbered source into entities numbered destination.
VariableScalarT(const VariableBuildInfo &v, const VariableInfo &vi)
Constructs a variable based on the reference v.
void setIsSynchronized() override
Indicates that the variable is synchronized.
void synchronize() override
Synchronizes the variable.
void copyItemsMeanValues(Int32ConstArrayView first_source, Int32ConstArrayView second_source, Int32ConstArrayView destination) override
Copies the mean values of entities numbered first_source and second_source into entities numbered des...
VariableComparerResults _compareVariable(const VariableComparerArgs &compare_args) final
Comparison of values between variables.
void print(std::ostream &o) const override
Prints the variable's values to the stream o.
void compact(Int32ConstArrayView new_to_old_ids) override
Compresses the variable's values.
Real allocatedMemory() const override
Memory size (in Bytes) used by the variable.
Variable(const VariableBuildInfo &v, const VariableInfo &vi)
Creates a variable linked to the reference v.
void _setData(const Ref< IData > &data)
Positions the data.
eItemKind itemKind() const override
Kind of mesh entities on which the variable is based.
@ ReduceMin
Minimum of values.
@ ReduceMax
Maximum of values.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
@ SameOnAllReplica
Checks that the variable values are the same on all replicas.
@ Same
Compares with a reference.
@ Sync
Checks that the variable is synchronized.
@ IK_Particle
Particle mesh entity.
double Real
Type representing a real number.
unsigned char Byte
Type of a byte.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Creates a reference on a pointer.
std::int32_t Int32
Signed integer type of 32 bits.