Geant4
v4-10.4-release
메인 페이지
관련된 페이지
모듈
네임스페이스
클래스
파일들
파일 목록
파일 멤버
모두
클래스
네임스페이스들
파일들
함수
변수
타입정의
열거형 타입
열거형 멤버
Friends
매크로
그룹들
페이지들
source
global
management
src
G4MTBarrier.cc
이 파일의 문서화 페이지로 가기
1
// ********************************************************************
2
// * License and Disclaimer *
3
// * *
4
// * The Geant4 software is copyright of the Copyright Holders of *
5
// * the Geant4 Collaboration. It is provided under the terms and *
6
// * conditions of the Geant4 Software License, included in the file *
7
// * LICENSE and available at http://cern.ch/geant4/license . These *
8
// * include a list of copyright holders. *
9
// * *
10
// * Neither the authors of this software system, nor their employing *
11
// * institutes,nor the agencies providing financial support for this *
12
// * work make any representation or warranty, express or implied, *
13
// * regarding this software system or assume any liability for its *
14
// * use. Please see the license in the file LICENSE and URL above *
15
// * for the full disclaimer and the limitation of liability. *
16
// * *
17
// * This code implementation is the result of the scientific and *
18
// * technical work of the GEANT4 collaboration. *
19
// * By using, copying, modifying or distributing the software (or *
20
// * any work based on the software) you agree to acknowledge its *
21
// * use in resulting scientific publications, and indicate your *
22
// * acceptance of all terms of the Geant4 Software license. *
23
// ********************************************************************
24
//
25
// $Id$
26
//
27
// ---------------------------------------------------------------
28
/*
29
* G4MTBarrier.cc
30
*
31
* Created on: Feb 10, 2016
32
* Author: adotti
33
* Updated on: Feb 9, 2018
34
* Author: jmadsen
35
*/
36
37
#include "
G4MTBarrier.hh
"
38
#include "
G4AutoLock.hh
"
39
40
G4MTBarrier::G4MTBarrier
(
unsigned
int
numThreads ) :
41
m_numActiveThreads(numThreads),
42
m_counter(0)
43
{}
44
45
void
G4MTBarrier::ThisWorkerReady
() {
46
//Step-1: Worker acquires lock on shared resource (the counter)
47
G4AutoLock
lock(&
m_mutex
);
48
//Step-2: Worker increases counter
49
++
m_counter
;
50
//Step-3: Worker broadcasts that the counter has changed
51
G4CONDITIONBROADCAST
(&
m_counterChanged
);
52
//Step-4: Worker waits on condition to continue
53
G4CONDITIONWAIT
(&
m_continue
,&lock);
54
}
55
56
void
G4MTBarrier::Wait
() {
57
while
(
true
)
58
{
59
//Step-2: Acquires lock on shared resource (the counter)
60
G4AutoLock
lock(&
m_mutex
);
61
//If the counter equals active threads, all threads are ready, exit the loop
62
if
(
m_counter
==
m_numActiveThreads
) {
break
; }
63
//Step-3: Not all workers are ready, wait for the number to change
64
//before repeating the check
65
G4CONDITIONWAIT
(&
m_counterChanged
,&lock);
66
}
67
}
68
69
void
G4MTBarrier::ReleaseBarrier
() {
70
//Step-4: re-aquire lock and re-set shared resource for future re-use
71
G4AutoLock
lock(&
m_mutex
);
72
m_counter
= 0;
73
G4CONDITIONBROADCAST
(&
m_continue
);
74
}
75
76
void
G4MTBarrier::WaitForReadyWorkers
() {
77
//Step-1: Master enters a loop to wait all workers to be ready
78
Wait
();
79
//Done, all workers are ready, broadcast a continue signal
80
ReleaseBarrier
();
81
}
82
83
void
G4MTBarrier::ResetCounter
() {
84
G4AutoLock
l(&
m_mutex
);
85
m_counter
= 0;
86
}
87
88
unsigned
int
G4MTBarrier::GetCounter
() {
89
G4AutoLock
l(&
m_mutex
);
90
const
unsigned
int
result
=
m_counter
;
91
return
result
;
92
}
G4MTBarrier::m_continue
G4Condition m_continue
Definition:
G4MTBarrier.hh:153
G4CONDITIONBROADCAST
#define G4CONDITIONBROADCAST(cond)
Definition:
G4Threading.hh:253
G4MTBarrier::ResetCounter
void ResetCounter()
Definition:
G4MTBarrier.cc:83
G4MTBarrier::Wait
void Wait()
Definition:
G4MTBarrier.cc:56
G4MTBarrier::WaitForReadyWorkers
virtual void WaitForReadyWorkers()
Definition:
G4MTBarrier.cc:76
G4CONDITIONWAIT
#define G4CONDITIONWAIT(cond, mutex)
Definition:
G4Threading.hh:251
G4MTBarrier.hh
G4AutoLock.hh
G4MTBarrier::GetCounter
unsigned int GetCounter()
Definition:
G4MTBarrier.cc:88
G4TemplateAutoLock
Definition:
G4AutoLock.hh:276
G4MTBarrier::G4MTBarrier
G4MTBarrier()
Definition:
G4MTBarrier.hh:128
G4MTBarrier::m_counterChanged
G4Condition m_counterChanged
Definition:
G4MTBarrier.hh:152
result
G4double G4ParticleHPJENDLHEData::G4double result
Definition:
G4ParticleHPJENDLHEData.cc:257
G4MTBarrier::ReleaseBarrier
void ReleaseBarrier()
Definition:
G4MTBarrier.cc:69
G4MTBarrier::m_counter
unsigned int m_counter
Definition:
G4MTBarrier.hh:150
G4MTBarrier::m_numActiveThreads
unsigned int m_numActiveThreads
Definition:
G4MTBarrier.hh:149
G4MTBarrier::m_mutex
G4Mutex m_mutex
Definition:
G4MTBarrier.hh:151
G4MTBarrier::ThisWorkerReady
void ThisWorkerReady()
Definition:
G4MTBarrier.cc:45
다음에 의해 생성됨 :
1.8.5