Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
SequentialSection.cc
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/* SequentialSection.cc (C) 2000-2015 */
9/* */
10/* Section of code to be executed sequentially. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ArcanePrecomp.h"
15
16#include "arcane/utils/ITraceMng.h"
17#include "arcane/utils/ParallelFatalErrorException.h"
18
19#include "arcane/core/IParallelMng.h"
20#include "arcane/core/ISubDomain.h"
21#include "arcane/core/SequentialSection.h"
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Arcane
27{
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32SequentialSection::
33SequentialSection(IParallelMng* pm)
34: m_parallel_mng(pm)
35, m_has_error(false)
36{
37 _init();
38}
39
40/*---------------------------------------------------------------------------*/
41/*---------------------------------------------------------------------------*/
42
43SequentialSection::
44SequentialSection(ISubDomain* sd)
45: m_parallel_mng(sd->parallelMng())
46, m_has_error(false)
47{
48 _init();
49}
50
51/*---------------------------------------------------------------------------*/
52/*---------------------------------------------------------------------------*/
53
54SequentialSection::
55~SequentialSection() ARCANE_NOEXCEPT_FALSE
56{
57 Integer sid = m_parallel_mng->commRank();
58 if (sid == 0) {
59 Integer error_value = m_has_error ? 1 : 0;
60 //cerr << "** ERROR SEND " << error_value << "!\n";
61 ArrayView<Integer> iv(1, &error_value);
62 m_parallel_mng->broadcast(iv, 0);
63 if (m_has_error)
64 _sendError();
65 }
66 else {
67 return;
68 }
69}
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
73
74void SequentialSection::
75_init()
76{
77 Integer sid = m_parallel_mng->commRank();
78 if (sid == 0) {
79 return;
80 }
81 else {
82 Integer error_value = 0;
83 ArrayView<Integer> iv(1, &error_value);
84 m_parallel_mng->broadcast(iv, 0);
85 //cerr << "** ERROR RECV " << sid << ' ' << error_value << "!\n";
86 if (error_value != 0)
87 _sendError();
88 }
89}
90
91/*---------------------------------------------------------------------------*/
92/*---------------------------------------------------------------------------*/
93
94void SequentialSection::
95_sendError()
96{
97 Integer sid = m_parallel_mng->commRank();
98 ITraceMng* trace = m_parallel_mng->traceMng();
99 if (trace)
100 trace->logdate() << "Subdomain " << sid << "Fatal in sequantial section";
101 m_parallel_mng->barrier();
102 throw ParallelFatalErrorException("sequential section");
103}
104
105/*---------------------------------------------------------------------------*/
106/*---------------------------------------------------------------------------*/
107
108void SequentialSection::
109setError(bool is_error)
110{
111 m_has_error = is_error;
112}
113
114/*---------------------------------------------------------------------------*/
115/*---------------------------------------------------------------------------*/
116
117} // namespace Arcane
118
119/*---------------------------------------------------------------------------*/
120/*---------------------------------------------------------------------------*/
Interface of the parallelism manager for a subdomain.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.