14#include "arcane/utils/ITraceMng.h"
15#include "arcane/utils/FatalErrorException.h"
16#include "arcane/utils/PlatformUtils.h"
17#include "arcane/utils/StringBuilder.h"
18#include "arcane/utils/ValueConvert.h"
20#include "arcane/core/IParallelMng.h"
21#include "arcane/core/VariableCollection.h"
22#include "arcane/core/IVariableUtilities.h"
23#include "arcane/core/VerifierService.h"
24#include "arcane/core/ItemGroup.h"
25#include "arcane/core/IVariableMng.h"
26#include "arcane/core/IVariable.h"
27#include "arcane/core/ISubDomain.h"
29#include "arcane/core/IData.h"
30#include "arcane/core/internal/IVariableInternal.h"
32#include "arcane/std/internal/BasicReader.h"
33#include "arcane/std/internal/BasicWriter.h"
40using namespace Arcane::impl;
45class ArcaneBasicVerifierService
46:
public VerifierService
59 IVariable* var = m_variable_mng->findVariableFullyQualified(full_name);
73 : VerifierService(sbi)
85 void _setFormatVersion(
Int32 v)
87 m_wanted_format_version = v;
93 Int32 m_wanted_format_version = 1;
97 void _computeFullFileName(
bool is_read)
99 ARCANE_UNUSED(is_read);
103 if (!sub_dir.
empty()) {
107 m_full_file_name = s;
109 void _doVerifHash(BasicReader* reader,
const VariableCollection& variables);
110 void _writeReferenceFile(
const String& file_name);
116void ArcaneBasicVerifierService::
117_writeReferenceFile(
const String& file_name)
119 ISubDomain* sd = subDomain();
122 auto open_mode = BasicReaderWriterCommon::OpenModeTruncate;
126 Int32 version = m_wanted_format_version;
128 ScopedPtrT<BasicWriter> verif(
new BasicWriter(sd->
application(), pm, file_name,
129 open_mode, version, want_parallel));
131 verif->setSaveValues(
false);
140 bool dump_not_common =
true;
155 _computeFullFileName(
false);
158 _writeReferenceFile(m_full_file_name);
171 _computeFullFileName(
true);
174 reader->initialize();
176 reader->setItemGroupFinder(&group_finder);
178 VariableList read_variables;
186 bool dump_not_common =
true;
188 read_variables = filtered_variables;
191 tm->
info() <<
"Checking (" << m_full_file_name <<
")";
192 reader->beginRead(read_variables);
194 _doVerif(reader.
get(), read_variables, compare_ghost);
196 _doVerifHash(reader.
get(), read_variables);
205 _getHashValueOrNull(
const std::map<String, String>& comparison_hash_map,
const String& name)
207 auto x = comparison_hash_map.find(name);
208 if (x != comparison_hash_map.end())
214void ArcaneBasicVerifierService::
217 ISubDomain* sd = subDomain();
222 info() <<
"Check Verif Hash";
224 IHashAlgorithm* ref_compare_hash_algo = ref_reader->comparisonHashAlgorithm();
225 if (!ref_compare_hash_algo)
230 std::map<String, String> current_comparison_hash_map;
231 ParallelDataWriterList parallel_data_writers;
232 info() <<
"DoVerifHash";
233 for (VariableCollection::Enumerator ivar(variables); ++ivar;) {
234 IVariable* var = *ivar;
235 Ref<IData> allocated_data;
236 IData* data = var->
data();
247 Ref<ParallelDataWriter> writer = parallel_data_writers.getOrCreateWriter(group);
248 allocated_data = writer->getSortedValues(data);
249 data = allocated_data.
get();
252 if (!hash_string.
empty())
253 current_comparison_hash_map.try_emplace(var->
fullName(), hash_string);
256 std::map<String, String> ref_comparison_hash_map;
259 Int32 nb_variable = 0;
260 Int32 nb_compared = 0;
261 Int32 nb_different = 0;
262 for (VariableCollection::Enumerator ivar(variables); ++ivar;) {
263 IVariable* var = *ivar;
264 String var_full_name = var->
fullName();
266 String ref_hash = _getHashValueOrNull(ref_comparison_hash_map, var_full_name);
267 String current_hash = _getHashValueOrNull(current_comparison_hash_map, var_full_name);
268 if (!ref_hash.
empty() && !current_hash.
empty()) {
270 if (ref_hash != current_hash) {
271 info() <<
"Different hash ref_hash=" << ref_hash <<
" current=" << current_hash
272 <<
" var=" << var_full_name;
276 info(4) <<
"Found Hash hash=" << ref_hash <<
" var=" << var_full_name;
279 info() <<
"NbVariable=" << nb_variable <<
" nb_compared=" << nb_compared <<
" nb_different=" << nb_different;
289class ArcaneBasicVerifierService2
290:
public ArcaneBasicVerifierService
295 : ArcaneBasicVerifierService(sbi)
303class ArcaneBasicVerifierServiceV3
304:
public ArcaneBasicVerifierService
309 : ArcaneBasicVerifierService(sbi)
311 _setFormatVersion(3);
313 bool use_hash = (v.value() != 0);
314 info() <<
"ArcaneBasicVerifierServiceV3: using hash?=" << use_hash;
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
This file contains the various service factories and macros for registering services.
#define ARCANE_SERVICE_INTERFACE(ainterface)
Macro to declare an interface when registering a service.
void build() override
Build-level construction of the service.
void doVerifFromReferenceFile(bool parallel_sequential, bool compare_ghost) override
Performs the verification from the reference file.
void writeReferenceFile() override
Writes the reference file.
Template class for converting a type.
virtual ITraceMng * traceMng() const =0
Trace manager.
Interface of the parallelism manager for a subdomain.
virtual bool isMasterIO() const =0
true if the instance is a master I/O manager.
virtual bool isParallel() const =0
Returns true if the execution is parallel.
Interface of the subdomain manager.
virtual IApplication * application()=0
Application.
virtual IParallelMng * parallelMng()=0
Returns the parallelism manager.
virtual IVariableMng * variableMng()=0
Returns the variable manager.
virtual TraceMessage info()=0
Stream for an information message.
virtual String computeComparisonHashCollective(IHashAlgorithm *hash_algo, IData *sorted_data)=0
Calculates the comparison hash for the variable.
Variable manager interface.
virtual IVariableUtilities * utilities() const =0
Interface of associated utility functions.
virtual VariableCollection usedVariables()=0
List of used variables.
virtual void writeVariables(IDataWriter *writer, IVariableFilter *filter=0)=0
Writes the variables.
virtual VariableCollection filterCommonVariables(IParallelMng *pm, VariableCollection input_variables, bool dump_not_common)=0
Filters common variables between multiple ranks.
virtual String fullName() const =0
Full variable name (with family prefix).
virtual IData * data()=0
Data associated with the variable.
virtual ItemGroup itemGroup() const =0
Associated mesh group.
virtual IVariableInternal * _internalApi()=0
Internal Arcane API.
Interface of the data verification service between two executions.
@ Values
Compare all values.
@ HashOnly
Compares only the hashes of the values.
bool null() const
true means the group is the null group
InstanceType * get() const
Associated instance or nullptr if none.
Reference to an instance.
Structure containing the information to create a service.
Service creation properties.
Unicode character string constructor.
Unicode character string.
bool empty() const
True if the string is empty (null or "").
TraceMessage info() const
Flow for an information message.
String fileName() const override
Name of the file containing the reference values.
virtual void _getVariables(VariableList variables, bool parallel_sequential)
Fills the list of variables that need to be reread in variables.
void setCompareMode(eCompareMode v) override
Desired comparison type.
String subDir() const override
Name of the file containing the reference values.
Interface to find the group associated with a variable based on this metadata.
void fillComparisonHash(std::map< String, String > &comparison_hash_map)
Fills the argument with pairs (variable_name, hash_value).
#define ARCANE_REGISTER_SERVICE(aclass, a_service_property,...)
Macro for registering a service.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
@ ST_SubDomain
The service is used at the subdomain level.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Creates a reference on a pointer.
std::int32_t Int32
Signed integer type of 32 bits.