forked from altMITgcm/MITgcm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autodiff_whtapeio_sync.F
184 lines (164 loc) · 5.24 KB
/
autodiff_whtapeio_sync.F
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
C $Header: /u/gcmpack/MITgcm/pkg/autodiff/autodiff_whtapeio_sync.F,v 1.11 2015/07/22 20:54:42 gforget Exp $
C $Name: $
#include "AUTODIFF_OPTIONS.h"
#include "MDSIO_OPTIONS.h"
#ifdef ALLOW_CTRL
# include "CTRL_OPTIONS.h"
#endif
subroutine autodiff_whtapeio_sync( myLev, myStep, myThid )
IMPLICIT NONE
C /==========================================================\
C | SUBROUTINE autodiff_whtapeio_sync |
C |==========================================================|
C == Global variables ===
#include "SIZE.h"
#include "EEPARAMS.h"
#include "PARAMS.h"
#include "ctrl.h"
#ifndef ALLOW_OPENAD
# include "AUTODIFF.h"
#endif
#ifdef ALLOW_WHIO_3D
# include "tamc.h"
# include "MDSIO_BUFF_WH.h"
#endif
C == Routine arguments ==
C myThid - Thread number for this instance of the routine.
integer myThid
integer myLev
integer myStep
#ifdef ALLOW_AUTODIFF_WHTAPEIO
character*(MAX_LEN_FNAM) fName
integer filePrec, IL, length_of_rec
LOGICAL iAmDoingIO
C sNxWh :: x tile size with halo included
C sNyWh :: y tile size with halo included
C pocNyWh :: processor sum of sNyWh
C gloNyWh :: global sum of sNyWh
INTEGER sNxWh
INTEGER sNyWh
INTEGER procNyWh
INTEGER gloNyWh
PARAMETER ( sNxWh = sNx+2*Olx )
PARAMETER ( sNyWh = sNy+2*Oly )
PARAMETER ( procNyWh = sNyWh*nSy*nSx )
PARAMETER ( gloNyWh = procNyWh*nPy*nPx )
logical exst
#ifdef ALLOW_WHIO_3D
character*(max_len_mbuf) msgBuf
integer ioUnit
#endif
c == functions ==
INTEGER ILNBLNK
INTEGER MDS_RECLEN
EXTERNAL ILNBLNK
EXTERNAL MDS_RECLEN
IF ( .NOT.useAUTODIFF ) THEN
RETURN
ENDIF
IF ( tapeConcatIO ) THEN
IF ( doSinglePrecTapelev ) THEN
filePrec = 32
ELSE
filePrec = 64
ENDIF
C Only do I/O if I am the master thread (and mpi process 0 IF tapeSingleCpuIO):
iAmDoingIO = .FALSE.
IF ( .NOT.tapeSingleCpuIO .OR. myProcId.EQ.0 ) THEN
_BEGIN_MASTER( myThid )
iAmDoingIO = .TRUE.
_END_MASTER( myThid )
ENDIF
IF ( iAmDoingIO ) THEN
IL = ilnblnk( adTapeDir )
IF ( .NOT.tapeSingleCpuIO ) THEN
WRITE(fName,'(2A,I1.1,A,I3.3,A)')
& adTapeDir(1:IL),'tapes',myLev,'.',myProcId,'.data'
length_of_rec = MDS_RECLEN( filePrec,sNxWh*procNyWh,myThid )
ELSE
WRITE(fName,'(2A,I1.1,A)')
& adTapeDir(1:IL),'tapes',myLev,'.data'
length_of_rec = MDS_RECLEN( filePrec,sNxWh*gloNyWh,myThid)
ENDIF
ENDIF
#ifdef ALLOW_WHIO_3D
length_of_rec=length_of_rec*nWh
#endif
tapeFileUnit=tapeFileUnitS(myLev)
tapeFileCounter=0
IF ( iAmDoingIO.AND.(myStep.EQ.0).AND.
& (myLev.GT.0).AND.(tapeFileUnit.EQ.0) ) THEN
inquire( file=fName, exist=exst )
#ifdef AUTODIFF_USE_MDSFINDUNITS
CALL MDSFINDUNIT( tapeFileUnit, myThid )
#else
CALL AUTODIFF_FINDUNIT( tapeFileUnit, myThid )
#endif
OPEN( tapeFileUnit, file=fName, status='unknown',
& access='direct', recl=length_of_rec )
tapeFileUnitS(myLev)=tapeFileUnit
#if (defined (ALLOW_INIT_WHTAPEIO) && defined (ALLOW_WHIO_3D))
c exst needs to have been tested before opening the file
IF (.NOT.exst) then
iWh=tapeMaxCounter*MAX(nchklev_2,nchklev_3)/nWh+1
write(msgBuf,'(a,i1,a,i3)') 'whio : create lev ',
& myLev,' rec ',iWh
ioUnit=standardMessageUnit
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid )
IF ( .NOT.tapeSingleCpuIO ) then
IF (filePrec .EQ. precFloat32) THEN
WRITE(tapeFileUnit,rec=iWh) fld3d_procbuff_r4
ELSE
WRITE(tapeFileUnit,rec=iWh) fld3d_procbuff_r8
ENDIF
ELSE
# ifdef INCLUDE_WHIO_GLOBUFF_3D
IF (filePrec .EQ. precFloat32) THEN
WRITE(tapeFileUnit,rec=iWh) fld3d_globuff_r4
ELSE
WRITE(tapeFileUnit,rec=iWh) fld3d_globuff_r8
ENDIF
# endif
ENDIF
iWh=0
ENDIF
#endif
ENDIF
#ifdef ALLOW_WHIO_3D
_BARRIER
IF ((myStep.EQ.1).AND.iAmDoingIO.AND.
& tapeBufferIO.AND.writeWh) THEN
if (iWh.LT.1) stop
write(msgBuf,'(a,i1,a,i3)') 'whio : write lev ',
& myLev,' rec ',iWh
ioUnit=standardMessageUnit
CALL PRINT_MESSAGE( msgBuf, ioUnit, SQUEEZE_RIGHT, myThid )
IF ( .NOT.tapeSingleCpuIO ) then
IF (filePrec .EQ. precFloat32) THEN
WRITE(tapeFileUnit,rec=iWh) fld3d_procbuff_r4
ELSE
WRITE(tapeFileUnit,rec=iWh) fld3d_procbuff_r8
ENDIF
ELSE
# ifdef INCLUDE_WHIO_GLOBUFF_3D
IF (filePrec .EQ. precFloat32) THEN
WRITE(tapeFileUnit,rec=iWh) fld3d_globuff_r4
ELSE
WRITE(tapeFileUnit,rec=iWh) fld3d_globuff_r8
ENDIF
# endif
ENDIF
ENDIF
_BARRIER
IF (myStep.EQ.0) THEN
tapeBufferIO=.TRUE.
ELSE
tapeBufferIO=.FALSE.
writeWh=.FALSE.
ENDIF
iWh=0
jWh=0
#endif /* ALLOW_WHIO_3D */
ENDIF !IF ( tapeConcatIO ) THEN
#endif /* ALLOW_AUTODIFF_WHTAPEIO */
end