Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
IMultiReduce.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* IMultiReduce.h (C) 2000-2016 */
9/* */
10/* Management of multiple reductions. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_PARALLEL_IMULTIREDUCE_H
13#define ARCANE_PARALLEL_IMULTIREDUCE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Array.h"
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28/*!
29 * \brief Class managing a reduction of a sum of values.
30 *
31 * Instances of this class must be created via IMultiReduce::getSumOfReal().
32 * The user must accumulate values via the call to add(). After execution
33 * of the reduction via IMultiReduce::execute(), it is possible
34 * to retrieve the reduced value via reducedValue().
35 * \sa IMultiReduce
36 */
37class ARCANE_CORE_EXPORT ReduceSumOfRealHelper
38{
39 public:
40
41 ReduceSumOfRealHelper(bool is_strict)
42 : m_reduced_value(0.0)
43 , m_is_strict(is_strict)
44 {
45 if (!m_is_strict)
46 m_values.add(0.0);
47 }
48
49 public:
50
51 //! Adds the value \a v
52 void add(Real v)
53 {
54 if (m_is_strict)
55 m_values.add(v);
56 else
57 m_values[0] += v;
58 }
59
60 //! Clears the accumulated values.
61 void clear()
62 {
63 m_values.clear();
64 }
65
66 //! List of accumulated values.
67 RealConstArrayView values() const { return m_values; }
68
69 //! Reduced value
70 Real reducedValue() const { return m_reduced_value; }
71
72 //! Positions the reduced value.
73 void setReducedValue(Real v) { m_reduced_value = v; }
74
75 private:
76
77 SharedArray<Real> m_values;
78 Real m_reduced_value;
79 bool m_is_strict;
80};
81
82/*---------------------------------------------------------------------------*/
83/*---------------------------------------------------------------------------*/
84
85/*!
86 * \brief Management of multiple reductions.
87 *
88 * For now, only 'sum' type reductions on reals
89 * are supported.
90 *
91 * It is possible to specify a strict mode, via setStrict(), which
92 * allows these sums to be identical regardless of the order
93 * of the operations. However, this requires storing all intermediate values
94 * and is therefore memory-intensive and not scalable because
95 * a single processor will handle the sum calculation.
96 *
97 * The strict mode must be specified before creating the reductions.
98 * The strict mode is automatically active if the environment variable
99 * ARCANE_STRICT_REDUCE is set.
100 */
101class ARCANE_CORE_EXPORT IMultiReduce
102{
103 public:
104
105 virtual ~IMultiReduce() {} //!< Frees resources
106
107 public:
108
109 static IMultiReduce* create(IParallelMng* pm);
110
111 public:
112
113 //! Executes the reductions
114 virtual void execute() = 0;
115
116 //! Indicates if strict mode is used
117 virtual bool isStrict() const = 0;
118
119 //! Sets the strict mode
120 virtual void setStrict(bool is_strict) = 0;
121
122 public:
123
124 /*!
125 * \brief Returns the name manager \a name.
126 * If a name manager \a name does not exist, it is created.
127 * The returned object remains the property of this instance and must not
128 * be explicitly destroyed. It will be when this instance is
129 * destroyed.
130 */
131 virtual ReduceSumOfRealHelper* getSumOfReal(const String& name) = 0;
132};
133
134/*---------------------------------------------------------------------------*/
135/*---------------------------------------------------------------------------*/
136
137} // namespace Arcane
138
139/*---------------------------------------------------------------------------*/
140/*---------------------------------------------------------------------------*/
141
142#endif
Management of multiple reductions.
virtual void setStrict(bool is_strict)=0
Sets the strict mode.
virtual ReduceSumOfRealHelper * getSumOfReal(const String &name)=0
Returns the name manager name. If a name manager name does not exist, it is created....
virtual bool isStrict() const =0
Indicates if strict mode is used.
virtual ~IMultiReduce()
Frees resources.
virtual void execute()=0
Executes the reductions.
Interface of the parallelism manager for a subdomain.
Class managing a reduction of a sum of values.
RealConstArrayView values() const
List of accumulated values.
Real reducedValue() const
Reduced value.
void setReducedValue(Real v)
Positions the reduced value.
void add(Real v)
Adds the value v.
void clear()
Clears the accumulated values.
1D vector of data with reference semantics.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
double Real
Type representing a real number.
ConstArrayView< Real > RealConstArrayView
C equivalent of a 1D array of reals.
Definition UtilsTypes.h:488