/[MITgcm]/MITgcm/eesupp/src/bar2.F
ViewVC logotype

Contents of /MITgcm/eesupp/src/bar2.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.7 - (show annotations) (download)
Tue Aug 4 18:01:37 2009 UTC (14 years, 9 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint62v, checkpoint62u, checkpoint62t, checkpoint65z, checkpoint65x, checkpoint65y, checkpoint65r, checkpoint65s, checkpoint65p, checkpoint65q, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint65j, checkpoint65k, checkpoint65h, checkpoint65i, checkpoint65n, checkpoint65l, checkpoint65m, checkpoint65b, checkpoint65c, checkpoint65a, checkpoint65f, checkpoint65g, checkpoint65d, checkpoint65e, checkpoint62c, checkpoint62s, checkpoint62r, checkpoint62q, checkpoint62p, checkpoint62a, checkpoint62g, checkpoint62f, checkpoint62e, checkpoint62d, checkpoint62k, checkpoint62j, checkpoint62i, checkpoint62h, checkpoint62o, checkpoint62n, checkpoint62m, checkpoint62l, checkpoint62w, checkpoint62z, checkpoint62y, checkpoint62x, checkpoint63g, checkpoint64, checkpoint65, checkpoint62, checkpoint63, checkpoint66g, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, checkpoint66n, checkpoint66m, checkpoint66l, checkpoint66k, checkpoint66j, checkpoint66i, checkpoint66h, checkpoint63p, checkpoint63q, checkpoint63r, checkpoint63s, checkpoint63l, checkpoint63m, checkpoint63n, checkpoint63o, checkpoint63h, checkpoint63i, checkpoint63j, checkpoint63k, checkpoint63d, checkpoint63e, checkpoint63f, checkpoint63a, checkpoint63b, checkpoint63c, checkpoint65o, checkpoint62b, checkpoint64y, checkpoint64x, checkpoint64z, checkpoint64q, checkpoint64p, checkpoint64s, checkpoint64r, checkpoint64u, checkpoint64t, checkpoint64w, checkpoint64v, checkpoint64i, checkpoint64h, checkpoint64k, checkpoint64j, checkpoint64m, checkpoint64l, checkpoint64o, checkpoint64n, checkpoint64a, checkpoint64c, checkpoint64b, checkpoint64e, checkpoint64d, checkpoint64g, checkpoint64f, checkpoint61v, checkpoint61w, checkpoint61u, checkpoint61z, checkpoint61x, checkpoint61y, HEAD
Changes since 1.6: +8 -10 lines
changed to pass when compiling with strick checking of arguments across S/R

1 C $Header: /u/gcmpack/MITgcm/eesupp/src/bar2.F,v 1.6 2005/11/07 18:16:08 cnh 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 spinCount = 0
122
123 IF ( myThid .NE. 1 ) THEN
124
125 BAR2_level(1,myThid) = BAR2_level(1,myThid)+1
126 myLevel = BAR2_level(1,myThid)
127 10 CONTINUE
128 IF ( BAR2_level(1,1) .EQ. myLevel ) GOTO 11
129 spinCount = spinCount+1
130 CALL FOOL_THE_COMPILER( BAR2_level(1,1) )
131 GOTO 10
132 11 CONTINUE
133
134 ELSE
135
136 myLevel = BAR2_level(1,1)
137 12 CONTINUE
138 CALL FOOL_THE_COMPILER( BAR2_level(1,1) )
139 nDone = 1
140 DO I = 2, nThreads
141 IF ( BAR2_level(1,1) .EQ. BAR2_level(1,I)-1 ) nDone = nDone+1
142 ENDDO
143 spinCount = spinCount+1
144 IF ( nDone .LT. nThreads ) GOTO 12
145
146 BAR2_level(1,1) = myLevel+1
147
148 ENDIF
149
150 BAR2_barrierCount(1,myThid) = BAR2_barrierCount(1,myThid)+1
151 BAR2_spinsCount(1,myThid) = BAR2_spinsCount(1,myThid)+spinCount
152 BAR2_spinsMax (1,myThid) = MAX(BAR2_spinsMax(1,myThid),spinCount)
153 BAR2_spinsMin (1,myThid) = MIN(BAR2_spinsMin(1,myThid),spinCount)
154
155 RETURN
156 END

  ViewVC Help
Powered by ViewVC 1.1.22