Arcane  v3.16.0.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
MpiLock.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 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/* MpiLock.h (C) 2000-2025 */
9/* */
10/* Verrou pour les appels MPI. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_PARALLEL_MPI_MPILOCK_H
13#define ARCANE_PARALLEL_MPI_MPILOCK_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/concurrency/SpinLock.h"
18#include "arccore/concurrency/Mutex.h"
19
20#include "arccore/message_passing_mpi/MessagePassingMpiGlobal.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane::MessagePassing::Mpi
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
36class MpiLock
37{
38 public:
39
40 // Le spin lock est plus performant mais ne permet pas d'utiliser
41 // valgrind.
42
43 //typedef SpinLock LockType;
44
45 typedef Mutex LockType;
46
47 public:
48 class Section
49 {
50 public:
51 Section(MpiLock* lock) : mpi_lock(lock)
52 {
53 if (mpi_lock){
54 manual_lock.lock(mpi_lock->m_lock);
55 }
56 }
57 ~Section()
58 {
59 if (mpi_lock)
60 manual_lock.unlock(mpi_lock->m_lock);
61 }
62 private:
63 MpiLock* mpi_lock;
64 LockType::ManualLock manual_lock;
65 };
66 friend class Section;
67 public:
68 MpiLock() {}
69 public:
70 private:
71 LockType m_lock;
72};
73
74/*---------------------------------------------------------------------------*/
75/*---------------------------------------------------------------------------*/
76
77} // namespace Arccore::MessagePassing::Mpi
78
79/*---------------------------------------------------------------------------*/
80/*---------------------------------------------------------------------------*/
81
82#endif
83