1 |
C $Header$ |
C $Header$ |
2 |
|
C $Name$ |
3 |
|
|
4 |
#include "CPP_EEOPTIONS.h" |
#include "CPP_EEOPTIONS.h" |
5 |
|
|
6 |
|
CBOP |
7 |
|
C !ROUTINE: BARRIER_INIT |
8 |
|
|
9 |
|
C !INTERFACE: |
10 |
SUBROUTINE BARRIER_INIT |
SUBROUTINE BARRIER_INIT |
11 |
|
IMPLICIT NONE |
12 |
|
|
13 |
|
C !DESCRIPTION: |
14 |
|
C *=====================================================================* |
15 |
|
C | SUBROUTINE BARRIER_INIT |
16 |
|
C | o Setup global barrier data structures. |
17 |
|
C *=====================================================================* |
18 |
|
C | Initialise global barrier data structures that can be used in |
19 |
|
C | conjunction with MPI or that can also be used to create |
20 |
|
C *=====================================================================* |
21 |
|
|
22 |
|
C !USES: |
23 |
|
C == Global variables == |
24 |
#include "SIZE.h" |
#include "SIZE.h" |
25 |
#include "EEPARAMS.h" |
#include "EEPARAMS.h" |
26 |
#include "EESUPPORT.h" |
#include "EESUPPORT.h" |
27 |
#include "BARRIER.h" |
#include "BARRIER.h" |
28 |
|
|
29 |
C === Local Variables === |
C !LOCAL VARIABLES: |
30 |
|
C == Local Variables == |
31 |
|
C I :: Loop counter |
32 |
INTEGER I |
INTEGER I |
33 |
|
CEOP |
34 |
|
|
35 |
DO I=1,nThreads |
DO I=1,nThreads |
36 |
key1(1,I) = INVALID |
key1(1,I) = INVALID |
43 |
|
|
44 |
RETURN |
RETURN |
45 |
END |
END |
46 |
|
|
47 |
|
CBOP |
48 |
|
C !ROUTINE: BARRIER |
49 |
|
|
50 |
|
C !INTERFACE: |
51 |
SUBROUTINE BARRIER( myThid ) |
SUBROUTINE BARRIER( myThid ) |
52 |
IMPLICIT NONE |
IMPLICIT NONE |
|
C |
|
|
C /==========================================================\ |
|
|
C | SUBROUTINE BARRIER | |
|
|
C | o Barrier routine that uses "busy waiting". | |
|
|
C |==========================================================| |
|
|
C | This routine provides a pure fortran mechanism to | |
|
|
C | synchronise multiple threads in a multi-threaded code. | |
|
|
C | No thread can leave this routine before all the threads | |
|
|
C | have entered it. | |
|
|
C | Notes | |
|
|
C | ===== | |
|
|
C | The door and key variables are assumed to have been | |
|
|
C | initialized once an initial state of key = INVALID | |
|
|
C | and door = SHUT. | |
|
|
C | We use the routine FOOL_THE_COMPILER to stop compilers | |
|
|
C | generating code which might simply set and test a | |
|
|
C | register value. Shared-memory systems only maintain | |
|
|
C | coherency over process caches and not registers. | |
|
|
C | Also we have to be a bit careful regarding sequential | |
|
|
C | consistency - or lack of it. At the moment the code | |
|
|
C | assumes a total store order memory model, which some | |
|
|
C | machines don't have! However, I have yet to find a | |
|
|
C | problem with this I think because the tolerances in | |
|
|
C | terms of memory ordering i.e. a little bit of reordering | |
|
|
C | probably won't break the barrier mechanism! | |
|
|
C | On non-cache coherent systems e.g. T3E we need to use | |
|
|
C | a library function to do barriers. | |
|
|
C | Note - The PANIC tests can be removed for working code | |
|
|
C | I have left them in without an ifdef option | |
|
|
C | because without them programming errors can | |
|
|
C | lead to infinitely spinning code. If you are | |
|
|
C | confident that your code is OK then removing | |
|
|
C | them may increase performance. Do not remove these| |
|
|
C | lines to make your code "work" If the code is | |
|
|
C | stopping in these PANIC blocks then something is | |
|
|
C | wrong with your program and it needs to be fixed. | |
|
|
C \==========================================================/ |
|
53 |
|
|
54 |
|
C !DESCRIPTION: |
55 |
|
C *==========================================================* |
56 |
|
C | SUBROUTINE BARRIER |
57 |
|
C | o Barrier routine that uses "busy waiting". |
58 |
|
C *==========================================================* |
59 |
|
C | This routine provides a pure fortran mechanism to |
60 |
|
C | synchronise multiple threads in a multi-threaded code. |
61 |
|
C | No thread can leave this routine before all the threads |
62 |
|
C | have entered it. |
63 |
|
C | Notes |
64 |
|
C | ===== |
65 |
|
C | The door and key variables are assumed to have been |
66 |
|
C | initialized once an initial state of key = INVALID |
67 |
|
C | and door = SHUT. |
68 |
|
C | We use the routine FOOL_THE_COMPILER to stop compilers |
69 |
|
C | generating code which might simply set and test a |
70 |
|
C | register value. Shared-memory systems only maintain |
71 |
|
C | coherency over process caches and not registers. |
72 |
|
C | Also we have to be a bit careful regarding sequential |
73 |
|
C | consistency - or lack of it. At the moment the code |
74 |
|
C | assumes a total store order memory model, which some |
75 |
|
C | machines do not have! However, I have yet to find a |
76 |
|
C | problem with this I think because the tolerances in |
77 |
|
C | terms of memory ordering i.e. a little bit of reordering |
78 |
|
C | probably will not break the barrier mechanism! |
79 |
|
C | On non-cache coherent systems e.g. T3E we need to use |
80 |
|
C | a library function to do barriers. |
81 |
|
C | Note - The PANIC tests can be removed for working code |
82 |
|
C | I have left them in without an ifdef option |
83 |
|
C | because without them programming errors can |
84 |
|
C | lead to infinitely spinning code. If you are |
85 |
|
C | confident that your code is OK then removing |
86 |
|
C | them may increase performance. Do not remove these |
87 |
|
C | lines to make your code "work" If the code is |
88 |
|
C | stopping in these PANIC blocks then something is |
89 |
|
C | wrong with your program and it needs to be fixed. |
90 |
|
C *==========================================================* |
91 |
|
|
92 |
|
C !USES: |
93 |
|
C == Global variables == |
94 |
#include "SIZE.h" |
#include "SIZE.h" |
95 |
#include "EEPARAMS.h" |
#include "EEPARAMS.h" |
96 |
#include "EESUPPORT.h" |
#include "EESUPPORT.h" |
97 |
#include "BARRIER.h" |
#include "BARRIER.h" |
98 |
|
|
99 |
C === Routine arguments === |
C !INPUT PARAMETERS: |
100 |
|
C == Routine arguments == |
101 |
INTEGER myThid |
INTEGER myThid |
102 |
|
|
103 |
|
C !LOCAL VARIABLES: |
104 |
C === Local variables === |
C === Local variables === |
105 |
C nDone - Counter for number of threads that have |
C nDone :: Counter for number of threads that have |
106 |
C completed a section. |
C completed a section. |
107 |
C I - Loop counter |
C I :: Loop counter |
108 |
INTEGER nDone |
INTEGER nDone |
109 |
INTEGER I |
INTEGER I |
110 |
|
CEOP |
111 |
|
|
112 |
CcnhDebugStarts |
CcnhDebugStarts |
113 |
C WRITE(myThid,*) ' Barrier entered ' |
C WRITE(myThid,*) ' Barrier entered ' |
115 |
|
|
116 |
C-- Check that thread number is expected range |
C-- Check that thread number is expected range |
117 |
IF ( myThid .LT. 1 .OR. myThid .GT. nThreads ) THEN |
IF ( myThid .LT. 1 .OR. myThid .GT. nThreads ) THEN |
118 |
WRITE(0,*) '!!!!!!! PANIC !!!!!!! CATASTROPHIC ERROR' |
WRITE(*,*) '!!!!!!! PANIC !!!!!!! CATASTROPHIC ERROR' |
119 |
WRITE(0,*) '!!!!!!! PANIC !!!!!!! in S/R BARRIER myThid = ', myThid, ' nThreads = ', nThreads |
WRITE(*,*) '!!!!!!! PANIC !!!!!!! in S/R BARRIER myThid = ', |
120 |
|
& myThid, ' nThreads = ', nThreads |
121 |
STOP 'ABNROMAL END: S/R BARRIER' |
STOP 'ABNROMAL END: S/R BARRIER' |
122 |
ENDIF |
ENDIF |
123 |
|
|
124 |
C-- When every threads key1 is valid thread 1 will open door1. |
C-- When every threads key1 is valid thread 1 will open door1. |
125 |
IF ( key1(1,myThid) .EQ. VALID ) THEN |
IF ( key1(1,myThid) .EQ. VALID ) THEN |
126 |
WRITE(0,*) '!!!!!!! PANIC !!!!!!! CATASTROPHIC ERROR' |
WRITE(*,*) '!!!!!!! PANIC !!!!!!! CATASTROPHIC ERROR' |
127 |
WRITE(0,*) '!!!!!!! PANIC !!!!!!! in S/R BARRIER myThid = ', myThid, ' key1 already validated' |
WRITE(*,*) '!!!!!!! PANIC !!!!!!! in S/R BARRIER myThid = ', |
128 |
|
& myThid, ' key1 already validated' |
129 |
STOP 'ABNROMAL END: S/R BARRIER' |
STOP 'ABNROMAL END: S/R BARRIER' |
130 |
ENDIF |
ENDIF |
131 |
key1(1,myThid) = VALID |
key1(1,myThid) = VALID |
149 |
|
|
150 |
CcnhDebugStarts |
CcnhDebugStarts |
151 |
C IF ( myThid .EQ. 1 ) THEN |
C IF ( myThid .EQ. 1 ) THEN |
152 |
C WRITE(0,*) ' DOOR1 Opened ' |
C WRITE(*,*) ' DOOR1 Opened ' |
153 |
C ENDIF |
C ENDIF |
154 |
CcnhDebugEnds |
CcnhDebugEnds |
155 |
|
|
164 |
C-- When every threads key2 is valid thread 1 will open door2. |
C-- When every threads key2 is valid thread 1 will open door2. |
165 |
C Notes |
C Notes |
166 |
C ===== |
C ===== |
|
C I don't understand memory ordering and sequential consistency. |
|
167 |
C I think that to work with any memory model ( i.e. relaxed, |
C I think that to work with any memory model ( i.e. relaxed, |
168 |
C partial store, total store) the variables key1, key2 and key3 |
C partial store, total store) the variables key1, key2 and key3 |
169 |
C might need to be set to invalid by thread 1. |
C might need to be set to invalid by thread 1. |
170 |
C |
C |
171 |
IF ( key2(1,myThid) .EQ. VALID ) THEN |
IF ( key2(1,myThid) .EQ. VALID ) THEN |
172 |
WRITE(0,*) '!!!!!!! PANIC !!!!!!! CATASTROPHIC ERROR' |
WRITE(*,*) '!!!!!!! PANIC !!!!!!! CATASTROPHIC ERROR' |
173 |
WRITE(0,*) '!!!!!!! PANIC !!!!!!! in S/R BARRIER myThid = ', myThid, ' key2 already validated' |
WRITE(*,*) '!!!!!!! PANIC !!!!!!! in S/R BARRIER myThid = ', |
174 |
|
& myThid, ' key2 already validated' |
175 |
STOP 'ABNROMAL END: S/R BARRIER' |
STOP 'ABNROMAL END: S/R BARRIER' |
176 |
ENDIF |
ENDIF |
177 |
key2(1,myThid) = VALID |
key2(1,myThid) = VALID |
205 |
|
|
206 |
C-- When every threads key3 is valid thread 1 will open door3. |
C-- When every threads key3 is valid thread 1 will open door3. |
207 |
IF ( key3(1,myThid) .EQ. VALID ) THEN |
IF ( key3(1,myThid) .EQ. VALID ) THEN |
208 |
WRITE(0,*) '!!!!!!! PANIC !!!!!!! CATASTROPHIC ERROR' |
WRITE(*,*) '!!!!!!! PANIC !!!!!!! CATASTROPHIC ERROR' |
209 |
WRITE(0,*) '!!!!!!! PANIC !!!!!!! in S/R BARRIER myThid = ', myThid, ' key3 already validated' |
WRITE(*,*) '!!!!!!! PANIC !!!!!!! in S/R BARRIER myThid = ', |
210 |
|
& myThid, ' key3 already validated' |
211 |
STOP 'ABNROMAL END: S/R BARRIER' |
STOP 'ABNROMAL END: S/R BARRIER' |
212 |
ENDIF |
ENDIF |
213 |
key3(1,myThid) = VALID |
key3(1,myThid) = VALID |