1 |
C $Header: /u/u0/gcmpack/MITgcm/eesupp/src/bar2.F,v 1.5 2004/03/27 03:51:50 edhill Exp $ |
2 |
C $Name: $ |
3 |
#include "CPP_EEOPTIONS.h" |
4 |
|
5 |
CBOP |
6 |
C !ROUTINE: BAR2_INIT |
7 |
|
8 |
C !INTERFACE: |
9 |
SUBROUTINE BAR2_INIT( myThid ) |
10 |
IMPLICIT NONE |
11 |
|
12 |
C !DESCRIPTION: |
13 |
C *=====================================================================* |
14 |
C | SUBROUTINE BAR2\_INIT |
15 |
C | o Setup global barrier data structures. |
16 |
C *=====================================================================* |
17 |
C | Initialise global barrier data structures that can be used in |
18 |
C | conjunction with MPI or that can also be used to create |
19 |
C *=====================================================================* |
20 |
|
21 |
C !USES: |
22 |
C == Global variables == |
23 |
#include "SIZE.h" |
24 |
#include "EEPARAMS.h" |
25 |
#include "EESUPPORT.h" |
26 |
#include "BAR2.h" |
27 |
C |
28 |
|
29 |
C !INPUT/OUTPUT PARAMETERS: |
30 |
C == Routine arguments == |
31 |
C myThid :: Thread number of this instance of BAR2_INIT |
32 |
INTEGER myThid |
33 |
|
34 |
C !LOCAL VARIABLES: |
35 |
C == Local variables == |
36 |
C I :: Loop counter |
37 |
INTEGER I |
38 |
CEOP |
39 |
|
40 |
C |
41 |
DO I = 1, lShare4 |
42 |
BAR2_level(I,myThid) = 0 |
43 |
BAR2_barrierCount(I,myThid) = 0 |
44 |
BAR2_spinsCount(I,myThid) = 0 |
45 |
BAR2_spinsCount(I,myThid) = 0 |
46 |
BAR2_spinsMax (I,myThid) = 0 |
47 |
BAR2_spinsMin (I,myThid) = 1000000000 |
48 |
ENDDO |
49 |
C |
50 |
bar2CollectStatistics = .TRUE. |
51 |
C |
52 |
RETURN |
53 |
END |
54 |
|
55 |
CBOP |
56 |
|
57 |
C !ROUTINE: BAR2 |
58 |
|
59 |
C !INTERFACE: |
60 |
SUBROUTINE BAR2( myThid ) |
61 |
IMPLICIT NONE |
62 |
|
63 |
C !DESCRIPTION: |
64 |
C *=====================================================================* |
65 |
C | SUBROUTINE BAR2 |
66 |
C | o Global barrier routine. |
67 |
C *=====================================================================* |
68 |
C | Implements a simple true shared memory barrier that uses a global |
69 |
C | heap array that all threads can access to synchronise. Each thread |
70 |
C | writes to a predefined location. One thread polls the locations. Other |
71 |
C | threads poll an all clear assertion location. Once the polling |
72 |
C | thread that is looping over locations sees writes for each thread is |
73 |
C | writes the all clear assertion location and everyone proceeds. A |
74 |
C | cyclic series of locations is used to ensure that race conditions do |
75 |
C | not occur. A few simple statistics are recorded giving number of |
76 |
C | barrier calls, max, min and aggregate polling loop counts. |
77 |
C *=====================================================================* |
78 |
|
79 |
C !USES: |
80 |
C == Global variables == |
81 |
#include "SIZE.h" |
82 |
#include "EEPARAMS.h" |
83 |
#include "EESUPPORT.h" |
84 |
#include "BAR2.h" |
85 |
|
86 |
C !INPUT/OUTPUT PARAMETERS: |
87 |
C == Routine arguments == |
88 |
C myThid :: Thread number of this instance of BAR2 |
89 |
INTEGER myThid |
90 |
|
91 |
C !LOCAL VARIABLES: |
92 |
C == Local variables == |
93 |
C myLevel :: Temp. to hold "active" barrier level |
94 |
C nDone :: Temp. for counting number of threads that |
95 |
C have reached the barrier. |
96 |
C I :: Loop counter |
97 |
C spinCount :: Temp. for doing statistics on how many |
98 |
C times barrier code looped. |
99 |
INTEGER myLevel |
100 |
INTEGER nDone |
101 |
INTEGER I |
102 |
INTEGER spinCount |
103 |
CEOP |
104 |
|
105 |
#ifdef USE_OMP_THREADING |
106 |
C$OMP BARRIER |
107 |
BAR2_barrierCount(1,myThid) = BAR2_barrierCount(1,myThid)+1 |
108 |
Cdbg C$OMP BARRIER |
109 |
Cdbg DO I = 2, nThreads |
110 |
Cdbg IF ( BAR2_barrierCount(1,I) .NE. BAR2_barrierCount(1,1) ) THEN |
111 |
Cdbg PRINT *, BAR2_barrierCount(1,1:nThreads) |
112 |
Cdbg CALL SYSTEM('sleep 1') |
113 |
Cdbg PRINT *, BAR2_barrierCount(1,1:nThreads) |
114 |
Cdbg Stop ' bar2 OUT OF SYNC ' |
115 |
Cdbg ENDIF |
116 |
Cdbg ENDDO |
117 |
Cdbg C$OMP BARRIER |
118 |
RETURN |
119 |
#endif |
120 |
|
121 |
C |
122 |
spinCount = 0 |
123 |
C |
124 |
IF ( myThid .NE. 1 ) THEN |
125 |
|
126 |
BAR2_level(1,myThid) = BAR2_level(1,myThid)+1 |
127 |
myLevel = BAR2_level(1,myThid) |
128 |
10 CONTINUE |
129 |
IF ( BAR2_level(1,1) .EQ. myLevel ) GOTO 11 |
130 |
spinCount = spinCount+1 |
131 |
CALL FOOL_THE_COMPILER( BAR2_level ) |
132 |
GOTO 10 |
133 |
11 CONTINUE |
134 |
|
135 |
ELSE |
136 |
|
137 |
myLevel = BAR2_level(1,1) |
138 |
12 CONTINUE |
139 |
CALL FOOL_THE_COMPILER( BAR2_level ) |
140 |
nDone = 1 |
141 |
DO I = 2, nThreads |
142 |
IF ( BAR2_level(1,1) .EQ. BAR2_level(1,I)-1 ) nDone = nDone+1 |
143 |
ENDDO |
144 |
spinCount = spinCount+1 |
145 |
IF ( nDone .LT. nThreads ) GOTO 12 |
146 |
|
147 |
BAR2_level(1,1) = myLevel+1 |
148 |
|
149 |
ENDIF |
150 |
C |
151 |
BAR2_barrierCount(1,myThid) = BAR2_barrierCount(1,myThid)+1 |
152 |
BAR2_spinsCount(1,myThid) = BAR2_spinsCount(1,myThid)+spinCount |
153 |
BAR2_spinsMax (1,myThid) = MAX(BAR2_spinsMax(1,myThid),spinCount) |
154 |
BAR2_spinsMin (1,myThid) = MIN(BAR2_spinsMin(1,myThid),spinCount) |
155 |
C |
156 |
RETURN |
157 |
END |
158 |
|