EMPIRE DA  v1.9.1
Data assimilation codes using EMPIRE communication
 All Classes Files Functions Variables Pages
cgsub.f90
Go to the documentation of this file.
1 
27 subroutine subroutine_cg(method,n,epsin,x,mpi_comm,mpi_size)
28 !
29 ! Change the maximum size of the problem dimension here
30 !
31 implicit none
32 integer, parameter :: rk = kind(1.0d0)
33 
34 integer, intent(in) :: method
35 integer, intent(in) :: n
36 real(kind=rk), intent(in) :: epsin
37 real(kind=rk), dimension(n), intent(inout) :: x
38 integer, intent(in) :: mpi_comm,mpi_size
39 
40 real(kind=rk), dimension(n) :: g,d,gold,w
41 real(kind=rk) :: f,eps,tlev
42 real(kind=rk), parameter :: one=1.0d0
43 logical :: finish
44 integer :: iprint(2),iflag,icall,i!mp,lp,i
45 integer :: irest
46 
47 
48 finish= .false.
49 !
50 ! Read problem input information
51 !
52 irest = 0 !no restarts
53 !irest = 1 !restarts every n steps
54 
55 ! IPRINT = FREQUENCY AND TYPE OF PRINTING
56 ! IPRINT(1) < 0 : NO OUTPUT IS GENERATED
57 ! IPRINT(1) = 0 : OUTPUT ONLY AT FIRST AND LAST ITERATION
58 ! IPRINT(1) > 0 : OUTPUT EVERY IPRINT(1) ITERATIONS
59 ! IPRINT(2) : SPECIFIES THE TYPE OF OUTPUT GENERATED;
60 ! THE LARGER THE VALUE (BETWEEN 0 AND 3),
61 ! THE MORE INFORMATION
62 ! IPRINT(2) = 0 : NO ADDITIONAL INFORMATION PRINTED
63 ! IPRINT(2) = 1 : INITIAL X AND GRADIENT VECTORS PRINTED
64 ! IPRINT(2) = 2 : X VECTOR PRINTED EVERY ITERATION
65 ! IPRINT(2) = 3 : X VECTOR AND GRADIENT VECTOR PRINTED
66 ! EVERY ITERATION
67 iprint(1) = 1
68 iprint(2) = 0
69 !
70 ! Check for correct dimension value n
71 !
72 if (n .lt. 0) then
73  iflag = -3
74  write(*,850)
75  go to 50
76 end if
77 
78 
79 !
80 ! Print parameters
81 !
82 if (iprint(1) .ge. 0) then
83  write(*,820)
84  write(*,840) n, method, irest
85 end if
86 
87 icall=0
88 !
89 ! This is the convergence constant
90 !
91 eps= epsin
92 
93 ! IFLAG=0 indicates an initial entry to program
94 
95 iflag=0
96 
97 !
98 ! Begin counting CPU time.
99 ! (Note: This function may not work on all operating systems.)
100 !
101 
102 
103 20 CONTINUE
104 !
105 ! Calculate the function and gradient values here
106 !
107 ! Rosenbrock test function
108 
109 call fcn(n,x,f,g)
110 30 CONTINUE
111 !
112 ! Call the main optimization code
113 !
114 CALL cgfam(n,x,f,g,d,gold,iprint,eps,w,iflag,irest,method,finish&
115  &,mpi_comm,mpi_size)
116 !
117 ! IFLAG=
118 ! 0 : successful termination
119 ! 1 : return to evaluate F and G
120 ! 2 : return with a new iterate, try termination test
121 ! -i : error
122 !
123 IF(iflag.LE.0.OR.icall.GT.10000) go to 50
124 IF(iflag.EQ.1) THEN
125  icall=icall + 1
126  go to 20
127 ENDIF
128 IF(iflag.EQ.2) THEN
129 !
130 ! Termination Test. The user may replace it by some other test. However,
131 ! the parameter 'FINISH' must be set to 'TRUE' when the test is satisfied.
132 !
133  tlev= eps*(one + dabs(f))
134  i=0
135 40 i=i+1
136  IF(i.GT.n) THEN
137  finish = .true.
138  go to 30
139  ENDIF
140  IF(dabs(g(i)).GT.tlev) THEN
141  go to 30
142  ELSE
143  go to 40
144  ENDIF
145 
146 ENDIF
147 
148 50 continue
149 
150 !
151 ! Code has terminated; print final results
152 !
153 if (iprint(1).ge.0.and.iflag.ge.0) then
154  write (*,890) f
155 end if
156 return
157 !
158 ! Formatting
159 !
160 
161 820 format (//, ' Conjugate Gradient Minimization Routine', /)
162 840 format (/, ' n =', i6, /,' method =', i6,/,' irest =', i6,/)
163 850 format (/,' Error: negative N value'/)
164 890 format (/,' f(x*) =', 1pd16.8)
165 
166 
167 end subroutine subroutine_cg
168 
169 
170 
171 
172 
173 
174 
175 
176 
177 
178 
179 
180 
181 
182 
183 
184 
185 
186 
187 
188 
subroutine subroutine_cg(method, n, epsin, x)
Nonlinear Conjugate gradient method as callable subroutine.
Definition: cgsub.f90:27
subroutine fcn(n, x, f, g)
This is the subroutine which the optimization routines call to get the objective function value and i...
Definition: 4denvar_fcn.f90:31