-
Notifications
You must be signed in to change notification settings - Fork 4
/
ushprod.f90
336 lines (259 loc) · 14.2 KB
/
ushprod.f90
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
! THIS VERSION: CUTEST 1.4 - 26/02/2016 AT 09:00 GMT.
!-*-*-*-*-*- C U T E S T C I N T _ U S H P R O D S U B R O U T I N E -*-*-
! Copyright reserved, Gould/Orban/Toint, for GALAHAD productions
! Principal author: Nick Gould
! History -
! fortran 2003 version released in CUTEst, 3rd September 2014
SUBROUTINE CUTEST_Cint_ushprod( status, n, goth, X, &
nnz_vector, INDEX_nz_vector, VECTOR, &
nnz_result, INDEX_nz_result, RESULT )
USE CUTEST
USE, INTRINSIC :: ISO_C_BINDING, ONLY : C_Bool
INTEGER, PARAMETER :: wp = KIND( 1.0D+0 )
! dummy arguments
INTEGER, INTENT( IN ) :: n, nnz_vector
INTEGER, INTENT( OUT ) :: status, nnz_result
LOGICAL ( KIND = C_Bool ), INTENT( IN ) :: goth
INTEGER, DIMENSION( nnz_vector ), INTENT( IN ) :: INDEX_nz_vector
INTEGER, DIMENSION( n ), INTENT( OUT ) :: INDEX_nz_result
REAL ( KIND = wp ), DIMENSION( n ), INTENT( IN ) :: X, VECTOR
REAL ( KIND = wp ), DIMENSION( n ), INTENT( OUT ) :: RESULT
! ----------------------------------------------------------------
! compute the matrix-vector product between the Hessian matrix of
! a group partially separable function and a given sparse vector
! VECTOR. The result is placed in RESULT. If goth is .TRUE. the
! second derivatives are assumed to have already been computed. If
! the user is unsure, set goth = .FALSE. the first time a product
! is required with the Hessian evaluated at X. X is not used if
! goth = .TRUE. Only the components INDEX_nz_vector(1:nnz_vector)
! of VECTOR are nonzero, and the remaining components of VECTOR
! need not have been be set. On exit, only the components
! INDEX_nz_result(1:nnz_result) of RESULT are nonzero, and the
! remaining components of RESULT may not have been set.
! ----------------------------------------------------------------
LOGICAL :: goth_fortran
goth_fortran = goth
CALL CUTEST_ushprod( status, n, goth_fortran, X, &
nnz_vector, INDEX_nz_vector, VECTOR, &
nnz_result, INDEX_nz_result, RESULT )
RETURN
! end of subroutine CUTEST_Cint_ushprod
END SUBROUTINE CUTEST_Cint_ushprod
!-*-*-*-*-*-*-*- C U T E S T U S H P R O D S U B R O U T I N E -*-*-*-*-
! Copyright reserved, Gould/Orban/Toint, for GALAHAD productions
! Principal author: Nick Gould
! History -
! fortran 2003 version released in CUTEst, 3rd September 2014
SUBROUTINE CUTEST_ushprod( status, n, goth, X, &
nnz_vector, INDEX_nz_vector, VECTOR, &
nnz_result, INDEX_nz_result, RESULT )
USE CUTEST
INTEGER, PARAMETER :: wp = KIND( 1.0D+0 )
! dummy arguments
INTEGER, INTENT( IN ) :: n, nnz_vector
INTEGER, INTENT( OUT ) :: status, nnz_result
LOGICAL, INTENT( IN ) :: goth
INTEGER, DIMENSION( nnz_vector ), INTENT( IN ) :: INDEX_nz_vector
INTEGER, DIMENSION( n ), INTENT( OUT ) :: INDEX_nz_result
REAL ( KIND = wp ), INTENT( IN ), DIMENSION( n ) :: X, VECTOR
REAL ( KIND = wp ), INTENT( OUT ), DIMENSION( n ) :: RESULT
! ----------------------------------------------------------------
! compute the matrix-vector product between the Hessian matrix of
! a group partially separable function and a given sparse vector
! VECTOR. The result is placed in RESULT. If goth is .TRUE. the
! second derivatives are assumed to have already been computed. If
! the user is unsure, set goth = .FALSE. the first time a product
! is required with the Hessian evaluated at X. X is not used if
! goth = .TRUE. Only the components INDEX_nz_vector(1:nnz_vector)
! of VECTOR are nonzero, and the remaining components of VECTOR
! need not have been be set. On exit, only the components
! INDEX_nz_result(1:nnz_result) of RESULT are nonzero, and the
! remaining components of RESULT may not have been set.
! ----------------------------------------------------------------
CALL CUTEST_ushprod_threadsafe( CUTEST_data_global, &
CUTEST_work_global( 1 ), &
status, n, goth, X, &
nnz_vector, INDEX_nz_vector, VECTOR, &
nnz_result, INDEX_nz_result, RESULT )
RETURN
! end of subroutine CUTEST_ushprod
END SUBROUTINE CUTEST_ushprod
!-*-*- C U T E S T U S H P R O D _ t h r e a d e d S U B R O U T I N E -*-
! Copyright reserved, Gould/Orban/Toint, for GALAHAD productions
! Principal author: Nick Gould
! History -
! fortran 2003 version released in CUTEst, 3rd September 2014
SUBROUTINE CUTEST_ushprod_threaded( status, n, goth, X, &
nnz_vector, INDEX_nz_vector, VECTOR, &
nnz_result, INDEX_nz_result, RESULT, &
thread )
USE CUTEST
INTEGER, PARAMETER :: wp = KIND( 1.0D+0 )
! dummy arguments
INTEGER, INTENT( IN ) :: n, nnz_vector, thread
INTEGER, INTENT( OUT ) :: status, nnz_result
LOGICAL, INTENT( IN ) :: goth
INTEGER, DIMENSION( nnz_vector ), INTENT( IN ) :: INDEX_nz_vector
INTEGER, DIMENSION( n ), INTENT( OUT ) :: INDEX_nz_result
REAL ( KIND = wp ), INTENT( IN ), DIMENSION( n ) :: X, VECTOR
REAL ( KIND = wp ), INTENT( OUT ), DIMENSION( n ) :: RESULT
! ----------------------------------------------------------------
! compute the matrix-vector product between the Hessian matrix of
! a group partially separable function and a given sparse vector
! VECTOR. The result is placed in RESULT. If goth is .TRUE. the
! second derivatives are assumed to have already been computed. If
! the user is unsure, set goth = .FALSE. the first time a product
! is required with the Hessian evaluated at X. X is not used if
! goth = .TRUE. Only the components INDEX_nz_vector(1:nnz_vector)
! of VECTOR are nonzero, and the remaining components of VECTOR
! need not have been be set. On exit, only the components
! INDEX_nz_result(1:nnz_result) of RESULT are nonzero, and the
! remaining components of RESULT may not have been set.
! ----------------------------------------------------------------
! check that the specified thread is within range
IF ( thread < 1 .OR. thread > CUTEST_data_global%threads ) THEN
IF ( CUTEST_data_global%out > 0 ) &
WRITE( CUTEST_data_global%out, "( ' ** CUTEST error: thread ', I0, &
& ' out of range [1,', I0, ']' )" ) thread, CUTEST_data_global%threads
status = 4 ; RETURN
END IF
! evaluate using specified thread
CALL CUTEST_ushprod_threadsafe( CUTEST_data_global, &
CUTEST_work_global( thread ), &
status, n, goth, X, &
nnz_vector, INDEX_nz_vector, VECTOR, &
nnz_result, INDEX_nz_result, RESULT )
RETURN
! end of subroutine CUTEST_ushprod_threaded
END SUBROUTINE CUTEST_ushprod_threaded
!-*- C U T E S T U S H P R O D _ t h r e a d s a f e S U B R O U T I N E -
! Copyright reserved, Gould/Orban/Toint, for GALAHAD productions
! Principal authors: Ingrid Bongartz and Nick Gould
! History -
! fortran 77 version originally released as UPROD in CUTE, July 1991
! fortran 2003 version released in CUTEst, 3rd September 2014
SUBROUTINE CUTEST_ushprod_threadsafe( data, work, status, n, goth, X, &
nnz_vector, INDEX_nz_vector, VECTOR, &
nnz_result, INDEX_nz_result, RESULT )
USE CUTEST
INTEGER, PARAMETER :: wp = KIND( 1.0D+0 )
! dummy arguments
TYPE ( CUTEST_data_type ), INTENT( IN ) :: data
TYPE ( CUTEST_work_type ), INTENT( INOUT ) :: work
INTEGER, INTENT( IN ) :: n, nnz_vector
INTEGER, INTENT( OUT ) :: status, nnz_result
LOGICAL, INTENT( IN ) :: goth
INTEGER, DIMENSION( nnz_vector ), INTENT( IN ) :: INDEX_nz_vector
INTEGER, DIMENSION( n ), INTENT( OUT ) :: INDEX_nz_result
REAL ( KIND = wp ), INTENT( IN ), DIMENSION( n ) :: X, VECTOR
REAL ( KIND = wp ), INTENT( OUT ), DIMENSION( n ) :: RESULT
! ----------------------------------------------------------------
! compute the matrix-vector product between the Hessian matrix of
! a group partially separable function and a given sparse vector
! VECTOR. The result is placed in RESULT. If goth is .TRUE. the
! second derivatives are assumed to have already been computed. If
! the user is unsure, set goth = .FALSE. the first time a product
! is required with the Hessian evaluated at X. X is not used if
! goth = .TRUE. Only the components INDEX_nz_vector(1:nnz_vector)
! of VECTOR are nonzero, and the remaining components of VECTOR
! need not have been be set. On exit, only the components
! INDEX_nz_result(1:nnz_result) of RESULT are nonzero, and the
! remaining components of RESULT may not have been set.
! ----------------------------------------------------------------
! local variables
INTEGER :: i, ig, j, ifstat, igstat
REAL ( KIND = wp ) :: ftt
REAL ( KIND = wp ) :: time_in, time_out
EXTERNAL :: RANGE
IF ( work%record_times ) CALL CPU_TIME( time_in )
! there are non-trivial group functions
IF ( .NOT. goth ) THEN
DO i = 1, MAX( data%nel, data%ng )
work%ICALCF( i ) = i
END DO
! evaluate the element function values
CALL ELFUN( work%FUVALS, X, data%EPVALU, data%nel, data%ITYPEE, &
data%ISTAEV, data%IELVAR, data%INTVAR, data%ISTADH, &
data%ISTEP, work%ICALCF, data%ltypee, data%lstaev, &
data%lelvar, data%lntvar, data%lstadh, data%lstep, &
data%lcalcf, data%lfuval, data%lvscal, data%lepvlu, &
1, ifstat )
IF ( ifstat /= 0 ) GO TO 930
! evaluate the element function gradient and Hessian values
CALL ELFUN( work%FUVALS, X, data%EPVALU, data%nel, data%ITYPEE, &
data%ISTAEV, data%IELVAR, data%INTVAR, data%ISTADH, &
data%ISTEP, work%ICALCF, data%ltypee, data%lstaev, &
data%lelvar, data%lntvar, data%lstadh, data%lstep, &
data%lcalcf, data%lfuval, data%lvscal, data%lepvlu, &
3, ifstat )
IF ( ifstat /= 0 ) GO TO 930
! compute the group argument values ft
DO ig = 1, data%ng
ftt = - data%B( ig )
! include the contribution from the linear element
DO j = data%ISTADA( ig ), data%ISTADA( ig + 1 ) - 1
ftt = ftt + data%A( j ) * X( data%ICNA( j ) )
END DO
! include the contributions from the nonlinear elements
DO j = data%ISTADG( ig ), data%ISTADG( ig + 1 ) - 1
ftt = ftt + data%ESCALE( j ) * work%FUVALS( data%IELING( J))
END DO
work%FT( ig ) = ftt
! record the derivatives of trivial groups
IF ( data%GXEQX( ig ) ) THEN
work%GVALS( ig, 2 ) = 1.0_wp
work%GVALS( ig, 3 ) = 0.0_wp
END IF
END DO
! evaluate the group derivative values
IF ( .NOT. data%altriv ) THEN
CALL GROUP( work%GVALS, data%ng, work%FT, data%GPVALU, data%ng, &
data%ITYPEG, data%ISTGP, work%ICALCF, data%ltypeg, &
data%lstgp, data%lcalcf, data%lcalcg, data%lgpvlu, &
.TRUE., igstat )
IF ( igstat /= 0 ) GO TO 930
END IF
! compute the gradient value
CALL CUTEST_form_gradients( n, data%ng, data%nel, data%ntotel, &
data%nvrels, data%nnza, data%nvargp, work%firstg, data%ICNA, &
data%ISTADA, data%IELING, data%ISTADG, data%ISTAEV, &
data%IELVAR, data%INTVAR, data%A, work%GVALS( : , 2 ), &
work%FUVALS, data%lnguvl, work%FUVALS( data%lggfx + 1 ), &
data%GSCALE, data%ESCALE, work%FUVALS( data%lgrjac + 1 ), &
data%GXEQX, data%INTREP, data%ISVGRP, data%ISTAGV, data%ITYPEE, &
work%ISTAJC, work%W_ws, work%W_el, RANGE )
work%firstg = .FALSE.
END IF
! evaluate the sparse product
work%nbprod = work%nbprod + 1
CALL CUTEST_hessian_times_sp_vector( &
data%n, data%ng, data%nel, data%ntotel, data%nvrels, data%nvargp, &
1, nnz_vector, nnz_result, work%nbprod, data%alllin, &
INDEX_nz_vector, data%ISTAEV, data%ISTADH, &
data%INTVAR, data%IELING, data%IELVAR, work%ISWKSP, INDEX_nz_result, &
VECTOR, RESULT, work%GVALS( : , 2 ) , work%GVALS( : , 3 ), &
work%FUVALS( data%lgrjac + 1 ), data%GSCALE, data%ESCALE, &
work%FUVALS( : data%lnhuvl ), data%lnhuvl, data%GXEQX, data%INTREP, &
data%IGCOLJ, data%ISLGRP, data%ISVGRP, data%ISTAGV, data%IVALJR, &
data%ITYPEE, data%ISYMMH, work%ISTAJC, work%IUSED, &
data%LIST_elements, data%LINK_elem_uses_var, work%NZ_components_w, &
work%W_ws, work%W_el, work%W_in, work%H_in, RANGE )
! update the counters for the report tool
work%nhvpr = work%nhvpr + 1
IF ( .NOT. goth ) work%nc2oh = work%nc2oh + 1
status = 0
GO TO 990
! unsuccessful returns
930 CONTINUE
IF ( data%out > 0 ) WRITE( data%out, &
"( ' ** SUBROUTINE USHPROD: error flag raised during SIF evaluation')" )
status = 3
! update elapsed CPU time if required
990 CONTINUE
IF ( work%record_times ) THEN
CALL CPU_TIME( time_out )
work%time_ushprod = work%time_ushprod + time_out - time_in
END IF
RETURN
! end of subroutine CUTEST_ushprod_threadsafe
END SUBROUTINE CUTEST_ushprod_threadsafe