/[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.6 - (show annotations) (download)
Mon Nov 7 18:16:08 2005 UTC (18 years, 10 months ago) by cnh
Branch: MAIN
CVS Tags: checkpoint58b_post, checkpoint57y_post, checkpoint59, checkpoint58, checkpoint58f_post, checkpoint58d_post, checkpoint58a_post, checkpoint57z_post, checkpoint58y_post, checkpoint58t_post, checkpoint58m_post, checkpoint60, checkpoint61, checkpoint58w_post, checkpoint57y_pre, checkpoint58o_post, checkpoint58p_post, checkpoint58q_post, checkpoint58e_post, mitgcm_mapl_00, checkpoint58r_post, checkpoint58n_post, checkpoint59q, checkpoint59p, checkpoint59r, checkpoint59e, checkpoint59d, checkpoint59g, checkpoint59f, checkpoint59a, checkpoint59c, checkpoint59b, checkpoint59m, checkpoint59l, checkpoint59o, checkpoint59n, checkpoint59i, checkpoint59h, checkpoint59k, checkpoint58k_post, checkpoint58v_post, checkpoint58l_post, checkpoint61f, checkpoint58g_post, checkpoint58x_post, checkpoint61n, checkpoint59j, checkpoint58h_post, checkpoint58j_post, checkpoint61q, checkpoint61e, checkpoint58i_post, checkpoint57x_post, checkpoint58c_post, checkpoint58u_post, checkpoint58s_post, checkpoint61g, checkpoint61d, checkpoint61b, checkpoint61c, checkpoint61a, checkpoint61o, checkpoint61l, checkpoint61m, checkpoint61j, checkpoint61k, checkpoint61h, checkpoint61i, checkpoint61t, checkpoint61r, checkpoint61s, checkpoint61p
Changes since 1.5: +17 -1 lines
Changes that enable OpenMP based threads.
Note - not all compute code is compatible with these.

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

  ViewVC Help
Powered by ViewVC 1.1.22