Peano
Loading...
Searching...
No Matches
BooleanSemaphore.h
Go to the documentation of this file.
1// Copyright (C) 2009 Technische Universitaet Muenchen
2// This file is part of the Peano project. For conditions of distribution and
3// use, please see the copyright notice at www.peano-framework.org
4#pragma once
5
6#include "tarch/mpi/mpi.h"
7#include "tarch/logging/Log.h"
10
11#include <string>
12#include <map>
13#include <vector>
14
15namespace tarch {
16 namespace mpi {
17 class BooleanSemaphore;
18 class Lock;
19 class Rank;
20 }
21}
22
72 public:
74 private:
76
81
91
96 bool locked;
97
105
114 std::string toString() const;
115 };
116
124 std::map<int,SemaphoreMapEntry> _map;
125
134 std::vector< std::pair<int, int> > _pendingLockRequests;
135
137
139
161 void serveLockRequests();
162
174 bool tryLockSemaphoreOnGlobalMaster( int number, int forRank );
175
198 void lockSemaphoreOnGlobalMaster( int number, int forRank );
199
210 void unlockSemaphoreOnGlobalMaster( int number, int forRank );
211
229 void addMapEntryLazily(int number);
230
231 public:
232 void init();
233 virtual void shutdown() override;
234
241
273 virtual void receiveDanglingMessages() override;
274
280
288 void acquireLock( int number);
289
300 void releaseLock( int number );
301
303
304 std::string toString() const;
305 };
306
307 private:
308 friend class Rank;
309 friend class tarch::mpi::Lock;
310
312
314
316
321
332
339
344
349
350 public:
363
365};
Log Device.
Definition Log.h:516
BooleanSemaphoreService(const BooleanSemaphoreService &)=delete
int _semaphoreTag
Tag used to exchange locking MPI messages.
tarch::multicore::BooleanSemaphore _mapAccessSemaphore
Semaphore for the global master's map of locks.
~BooleanSemaphoreService()=default
Destructor of the service.
virtual void receiveDanglingMessages() override
Receive any lock-related dangling messages.
bool tryLockSemaphoreOnGlobalMaster(int number, int forRank)
Try to lock a semaphore.
tarch::multicore::BooleanSemaphore _reserverationRequestsSemaphore
std::vector< std::pair< int, int > > _pendingLockRequests
List of pending lock requests.
static BooleanSemaphoreService & getInstance()
Don't use this routine.
std::map< int, SemaphoreMapEntry > _map
Map of semaphores.
void unlockSemaphoreOnGlobalMaster(int number, int forRank)
Unlock semaphore on global master.
Boolean semaphore across MPI ranks.
static tarch::logging::Log _log
void leaveCriticalSection()
Tells the semaphore that it is about to leave.
tarch::multicore::BooleanSemaphore _localRankLockRequestSemaphore
void enterCriticalSection()
Waits until I can enter the critical section.
BooleanSemaphore(const BooleanSemaphore &)=delete
You may not copy a semaphore.
BooleanSemaphore & operator=(const BooleanSemaphore &)=delete
You may not copy a semaphore.
BooleanSemaphore()
Create new boolean semaphore spanning all MPI ranks.
Create a lock around a boolean semaphore region.
Definition Lock.h:20
Represents a program instance within a cluster.
Definition Rank.h:58
Service Interface.
Definition Service.h:87
Have to include this header, as I need access to the SYCL_EXTERNAL keyword.
Definition accelerator.h:19
bool locked
Flag indicating if a semaphore is currently locked.
int rankThatLastLocked
Bookkeeping of who has locked a semaphore last.