1 |
heimbach |
1.1 |
|
2 |
|
|
c ================================================================== |
3 |
|
|
c |
4 |
|
|
c prgopti.F: Routines for doing an off-line optimization after the |
5 |
|
|
c ECCO forward and adjoint model have been run. |
6 |
|
|
c |
7 |
|
|
c main - Driver routine. |
8 |
|
|
c opti - Mid-level routine to do the spin up and spin down. |
9 |
|
|
c optimum - Routine that calls the minimization. |
10 |
|
|
c |
11 |
|
|
c Documentation: |
12 |
|
|
c |
13 |
|
|
c The collection of these routines originated mainly from Ralf |
14 |
|
|
c Giering. Patrick Heimbach improved and corrected considerable |
15 |
|
|
c parts of the original code. Christian Eckert contributed the |
16 |
|
|
c interface to the ECCO release of the MITgcmUV in order to get |
17 |
|
|
c the offline version going. |
18 |
|
|
c |
19 |
|
|
c How to use the off-line optimization. |
20 |
|
|
c |
21 |
|
|
c Doing an off-line optimization means that one alternately |
22 |
|
|
c calls the adjoint model and the optimization routines. |
23 |
|
|
c |
24 |
|
|
c The adjoint model yields at iteration i the cost function |
25 |
|
|
c value and the gradient of the cost function with respect to |
26 |
|
|
c the control variables. The optimization routines then use |
27 |
|
|
c this information to reduce the cost function and give a |
28 |
|
|
c new estimate of the control variables which can then be used |
29 |
|
|
c in the next cycle to yield a new cost function and the |
30 |
|
|
c corresponding gradient. |
31 |
|
|
c |
32 |
|
|
c started: Ralf Giering (lsoptv1) |
33 |
|
|
c |
34 |
|
|
c Patrick Heimbach heimbach@mit.edu 28-Feb-2000 |
35 |
|
|
c |
36 |
|
|
c - Corrected and restructured the original lsoptv1 |
37 |
|
|
c code. |
38 |
|
|
c |
39 |
|
|
c Christian Eckert eckert@mit.edu 15-Feb-2000 |
40 |
|
|
c |
41 |
|
|
c - Off-line capability and some cosmetic changes |
42 |
|
|
c of the optimization wrapper. |
43 |
|
|
c |
44 |
|
|
c changed: |
45 |
|
|
c |
46 |
|
|
c ================================================================== |
47 |
|
|
|
48 |
|
|
|
49 |
|
|
program optim_main |
50 |
|
|
|
51 |
|
|
c ================================================================== |
52 |
|
|
c PROGRAM optim_main |
53 |
|
|
c ================================================================== |
54 |
|
|
c |
55 |
|
|
c o Driver routine for the ECCO optimization package. |
56 |
|
|
c |
57 |
|
|
c started: Christian Eckert eckert@mit.edu 15-Feb-2000 |
58 |
|
|
c |
59 |
|
|
c changed: Christian Eckert eckert@mit.edu 10-Mar-2000 |
60 |
|
|
c |
61 |
|
|
c - Added ECCO layout. |
62 |
|
|
c |
63 |
|
|
c ================================================================== |
64 |
|
|
c SUBROUTINE |
65 |
|
|
c ================================================================== |
66 |
|
|
|
67 |
|
|
implicit none |
68 |
|
|
|
69 |
|
|
c == global variables == |
70 |
|
|
|
71 |
|
|
#include "blas1.h" |
72 |
|
|
#include "mpif.h" |
73 |
|
|
integer nx |
74 |
|
|
integer ierr |
75 |
|
|
|
76 |
|
|
c == routine arguments == |
77 |
|
|
|
78 |
|
|
c == local variables == |
79 |
|
|
|
80 |
|
|
integer nn |
81 |
|
|
|
82 |
|
|
integer myid,nprocs,mystart,myend |
83 |
|
|
common /mpi_parm/ myid,nprocs,mystart,myend |
84 |
|
|
c == end of interface == |
85 |
|
|
|
86 |
|
|
call MPI_INIT(ierr) |
87 |
|
|
call MPI_COMM_RANK(MPI_COMM_WORLD,myid,ierr) |
88 |
|
|
call MPI_COMM_SIZE(MPI_COMM_WORLD,nprocs,ierr) |
89 |
|
|
|
90 |
|
|
if (myid .eq. 0) then |
91 |
|
|
c-- Headline. |
92 |
|
|
print* |
93 |
|
|
print*,' ==================================================' |
94 |
|
|
print*,' Large Scale Optimization with off-line capability.' |
95 |
|
|
print*,' ==================================================' |
96 |
|
|
print* |
97 |
|
|
print*,' Version 2.1.0' |
98 |
|
|
print* |
99 |
|
|
endif |
100 |
|
|
|
101 |
|
|
c-- Get the number of control variables. |
102 |
|
|
call optim_numbmod( nn ) |
103 |
|
|
|
104 |
|
|
cph( |
105 |
|
|
if (myid .eq. 0) |
106 |
|
|
& print *, 'pathei: vor optim_sub' |
107 |
|
|
cph) |
108 |
|
|
c-- Call the subroutine. |
109 |
|
|
call optim_sub( nn ) |
110 |
|
|
|
111 |
|
|
if (myid .eq. 0) then |
112 |
|
|
c-- Succesful termination. |
113 |
|
|
print* |
114 |
|
|
print*,' ======================================' |
115 |
|
|
print*,' Large Scale Optimization run finished.' |
116 |
|
|
print*,' ======================================' |
117 |
|
|
print* |
118 |
|
|
endif |
119 |
|
|
|
120 |
|
|
call MPI_FINALIZE(ierr) |
121 |
|
|
|
122 |
|
|
end |
123 |
|
|
|
124 |
|
|
CStartOfInterface |
125 |
|
|
INTEGER FUNCTION IFNBLNK( string ) |
126 |
|
|
C /==========================================================\ |
127 |
|
|
C | FUNCTION IFNBLNK | |
128 |
|
|
C | o Find first non-blank in character string. | |
129 |
|
|
C \==========================================================/ |
130 |
|
|
IMPLICIT NONE |
131 |
|
|
C |
132 |
|
|
CHARACTER*(*) string |
133 |
|
|
CEndOfInterface |
134 |
|
|
C |
135 |
|
|
INTEGER L, LS |
136 |
|
|
C |
137 |
|
|
LS = LEN(string) |
138 |
|
|
IFNBLNK = 0 |
139 |
|
|
DO 10 L = 1, LS |
140 |
|
|
IF ( string(L:L) .EQ. ' ' ) GOTO 10 |
141 |
|
|
IFNBLNK = L |
142 |
|
|
GOTO 11 |
143 |
|
|
10 CONTINUE |
144 |
|
|
11 CONTINUE |
145 |
|
|
C |
146 |
|
|
RETURN |
147 |
|
|
END |
148 |
|
|
|
149 |
|
|
CStartOfInterface |
150 |
|
|
INTEGER FUNCTION ILNBLNK( string ) |
151 |
|
|
C /==========================================================\ |
152 |
|
|
C | FUNCTION ILNBLNK | |
153 |
|
|
C | o Find last non-blank in character string. | |
154 |
|
|
C \==========================================================/ |
155 |
|
|
IMPLICIT NONE |
156 |
|
|
CHARACTER*(*) string |
157 |
|
|
CEndOfInterface |
158 |
|
|
INTEGER L, LS |
159 |
|
|
C |
160 |
|
|
LS = LEN(string) |
161 |
|
|
ILNBLNK = LS |
162 |
|
|
DO 10 L = LS, 1, -1 |
163 |
|
|
IF ( string(L:L) .EQ. ' ' ) GOTO 10 |
164 |
|
|
ILNBLNK = L |
165 |
|
|
GOTO 11 |
166 |
|
|
10 CONTINUE |
167 |
|
|
11 CONTINUE |
168 |
|
|
C |
169 |
|
|
RETURN |
170 |
|
|
END |
171 |
|
|
|