14#include "arcane/core/VerifierService.h"
16#include "arcane/utils/List.h"
17#include "arcane/utils/ITraceMng.h"
18#include "arcane/utils/OStringStream.h"
20#include "arcane/core/ServiceBuildInfo.h"
21#include "arcane/core/ISubDomain.h"
22#include "arcane/core/IVariable.h"
23#include "arcane/core/IParallelMng.h"
24#include "arcane/core/IVariableMng.h"
25#include "arcane/core/ArcaneException.h"
26#include "arcane/core/CommonVariables.h"
27#include "arcane/core/SerializeBuffer.h"
28#include "arcane/core/VariableCollection.h"
29#include "arcane/core/IMesh.h"
30#include "arcane/core/VariableComparer.h"
46, m_sub_domain(sbi.subDomain())
47, m_service_info(sbi.serviceInfo())
72 for (VariableCollection::Enumerator i(used_vars); ++i;) {
74 if (parallel_sequential) {
87 if (
mesh->parallelMng() != pm_sd)
93 variables.add(variable);
100template <
typename ReaderType>
void VerifierService::
101_doVerif2(ReaderType reader,
const VariableList& variables,
bool compare_ghost)
111 typedef std::map<String, DiffInfo> MapDiffInfos;
112 typedef std::map<String, DiffInfo>::value_type MapDiffInfosValues;
113 MapDiffInfos diff_infos;
117 compare_args.setComputeDifferenceMethod(m_compute_diff_method);
120 for (VariableList::Enumerator i(variables); ++i;) {
126 nb_diff = r.nbDifference();
129 catch (
const ReaderWriterException& rw) {
132 trace->
pinfo() <<
"Impossible to compare the variable '" << var_name <<
"'\n"
133 <<
"(Exception: " << ostr.str() <<
")";
134 not_compared_str() <<
' ' << var_name;
137 diff_infos.insert(MapDiffInfosValues(var_name, DiffInfo(var_name, nb_diff)));
140 if (nb_not_compared != 0) {
141 trace->
warning() <<
"Impossible to compare " << nb_not_compared <<
" variable(s): "
142 << not_compared_str.str();
144 if (nb_compared == 0) {
145 trace->
pfatal() <<
"No variable has been compared";
148 Int32 nb_sub_domain = pm->
commSize();
149 bool is_master = sid == 0;
153 for (Integer i = 0; i < nb_sub_domain; ++i) {
156 SerializeBuffer sbuf;
157 pm->recvSerializer(&sbuf, i);
158 sbuf.setMode(ISerializer::ModeGet);
161 Int64 n = sbuf.getInt64();
163 for (Integer z = 0; z < n; ++z) {
164 Int64 nb_var_diff = sbuf.getInt64();
166 String uvar_name(var_name);
167 trace->
debug() <<
"RECEIVE: "
168 <<
" varname=" << var_name
169 <<
" nbdiff=" << nb_var_diff;
170 auto i_map = diff_infos.find(uvar_name);
171 if (i_map == diff_infos.end()) {
172 diff_infos.insert(MapDiffInfosValues(uvar_name, DiffInfo(uvar_name, nb_var_diff)));
175 i_map->second.m_nb_diff += nb_var_diff;
181 SerializeBuffer sbuf;
182 Int64 nb_diff = diff_infos.size();
183 sbuf.setMode(ISerializer::ModeReserve);
184 sbuf.reserve(DT_Int64, 1);
185 for (
auto& i_map : diff_infos) {
186 const DiffInfo& diff_info = i_map.second;
187 sbuf.reserve(DT_Int64, 1);
188 sbuf.reserve(diff_info.m_variable_name);
190 sbuf.allocateBuffer();
191 sbuf.setMode(ISerializer::ModePut);
192 sbuf.putInt64(nb_diff);
193 for (
auto& i_map : diff_infos) {
194 const DiffInfo& diff_info = i_map.second;
195 Int64 n = diff_info.m_nb_diff;
197 sbuf.put(diff_info.m_variable_name);
199 pm->sendSerializer(&sbuf, 0);
205 Int64 total_nb_diff = 0;
206 for (
auto& diff_info : diff_infos)
207 total_nb_diff += diff_info.second.m_nb_diff;
209 if (!m_result_file_name.empty()) {
210 const CommonVariables& vc = subDomain()->commonVariables();
211 std::ofstream result_file(m_result_file_name.localstr());
212 result_file <<
"<?xml version='1.0'?>\n";
213 result_file <<
"<compare-results"
215 <<
" total-nb-diff='" << total_nb_diff <<
"'"
216 <<
" global-iteration='" << vc.globalIteration() <<
"'"
217 <<
" global-time='" << vc.globalTime() <<
"'"
219 for (
auto& i_map : diff_infos) {
220 const DiffInfo& diff_info = i_map.second;
221 result_file <<
" <variable>\n"
222 <<
" <name>" << diff_info.m_variable_name <<
"</name>\n"
223 <<
" <nb-diff>" << diff_info.m_nb_diff <<
"</nb-diff>\n"
226 result_file <<
"</compare-results>\n";
228 if (total_nb_diff != 0) {
229 trace->
error() <<
"Some differences exist (N=" << total_nb_diff <<
") with the reference file";
232 trace->
info() <<
"No difference with the reference !";
240void VerifierService::
241_doVerif(IDataReader* reader,
const VariableList& variables,
bool compare_ghost)
243 _doVerif2(reader, variables, compare_ghost);
Interface of the base class for main arcane objects.
virtual ITraceMng * traceMng() const =0
Trace manager.
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 void barrier()=0
Performs a barrier.
Interface of the subdomain manager.
virtual IParallelMng * parallelMng()=0
Returns the parallelism manager.
virtual IVariableMng * variableMng()=0
Returns the variable manager.
virtual TraceMessage warning()=0
Stream for a warning message.
virtual TraceMessage pfatal()=0
Stream for a parallel fatal error message.
virtual TraceMessage pinfo()=0
Stream for a parallel information message.
virtual TraceMessage error()=0
Stream for an error message.
virtual TraceMessage info()=0
Stream for an information message.
virtual TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium)=0
Stream for a debug message.
Variable manager interface.
virtual VariableCollection usedVariables()=0
List of used variables.
@ PSubDomainDepend
Indicates that the variable value is dependent on the subdomain.
@ PExecutionDepend
Indicates that the variable value is dependent on the execution.
virtual int property() const =0
Returns the properties of the variable.
virtual eItemKind itemKind() const =0
Kind of mesh entities on which the variable is based.
virtual MeshHandle meshHandle() const =0
Mesh associated with the variable.
virtual String name() const =0
Variable name.
bool hasMesh() const
Indicates if the associated mesh has already been created (i.e.: mesh() is valid).
IMesh * mesh() const
Associated mesh.
Output stream linked to a String.
Structure containing the information to create a service.
Unicode character string.
Arguments for VariableComparer methods.
void setMaxPrint(Int32 v)
Sets the number of errors to display in the listing.
void setCompareGhost(bool v)
Indicates on which entities the comparison is performed.
Results of a comparison operation.
Class to perform comparisons between variables.
VariableComparerResults apply(IVariable *var, const VariableComparerArgs &compare_args)
Applies the comparison compare_args to the variable var.
VariableComparerArgs buildForCheckIfSame(IDataReader *data_reader)
Creates a comparison to verify that a variable is identical to a reference value.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
@ IK_Unknown
Unknown or uninitialized mesh entity.