Skip to content

Commit 23f94e0

Browse files
committed
250820.172606.CST [skip ci] revise test_SOLVER.f90 to reduce testing time
1 parent 500a5eb commit 23f94e0

File tree

6 files changed

+338
-89
lines changed

6 files changed

+338
-89
lines changed

fortran/tests/test_bobyqa.f90

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ module test_solver_mod
5757
!
5858
! Started: September 2021
5959
!
60-
! Last Modified: Tue 19 Aug 2025 10:59:55 PM CST
60+
! Last Modified: Wed 20 Aug 2025 05:07:51 PM CST
6161
!--------------------------------------------------------------------------------------------------!
6262

6363
implicit none
@@ -115,7 +115,7 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
115115
integer(IK) :: nnpt
116116
integer(IK) :: nprobs
117117
integer(IK) :: npt
118-
integer(IK) :: npt_list(10)
118+
integer(IK) :: npt_list(100) ! Maximal number of prescribed NPT to test: 100
119119
integer(IK) :: nrand_loc
120120
integer(IK), parameter :: bign = 300_IK
121121
integer(IK), parameter :: largen = 1600_IK
@@ -186,17 +186,13 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
186186
do irand = 1, 1 ! The test is expensive
187187
rseed = int(sum(istr(solname)) + sum(istr(probname)) + n + irand + RP + randseed_loc)
188188
call setseed(rseed)
189-
npt = max(n + 2_IK, int(5.0 * rand() * real(n, RP), kind(npt)))
189+
npt = max(n + 2_IK, int(4.0 * rand() * real(n, RP), kind(npt)))
190190
iprint = 2_IK
191-
if (int(npt) + 2000 > huge(0_IK)) then
192-
maxfun = huge(0_IK)
193-
else
194-
maxfun = npt + int(2000.0_RP * rand(), IK)
195-
end if
191+
maxfun = npt + int(min(1000.0_RP, real(2_IK*npt, RP)) * rand(), IK)
196192
maxhist = maxfun
197-
ftarget = -REALMAX
193+
ftarget = -TEN**abs(real(min(range(ftarget), 10), RP) * rand())
198194
rhobeg = noisy(prob % Delta0)
199-
rhoend = max(1.0E-6_RP, rhobeg * 10.0_RP**(6.0_RP * rand() - 6.0_RP))
195+
rhoend = max(1.0E-4_RP, rhobeg * 10.0_RP**(5.0_RP * rand() - 4.0_RP))
200196
call safealloc(x, n) ! Not all compilers support automatic allocation yet, e.g., Absoft.
201197
x = noisy(prob % x0)
202198
orig_calfun => prob % calfun
@@ -227,27 +223,24 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
227223
call construct(prob, probname, n) ! Construct the testing problem.
228224

229225
! NPT_LIST defines some extreme values of NPT.
230-
nnpt = 10
231-
npt_list(1:nnpt) = [1_IK, &
226+
nnpt = 11
227+
npt_list(1:nnpt) = [0_IK, 1_IK, &
232228
& n + 1_IK, n + 2_IK, n + 3_IK, &
233229
& 2_IK * n, 2_IK * n + 1_IK, 2_IK * n + 2_IK, &
234230
& (n + 1_IK) * (n + 2_IK) / 2_IK - 1_IK, (n + 1_IK) * (n + 2_IK) / 2_IK, &
235231
& (n + 1_IK) * (n + 2_IK) / 2_IK + 1_IK]
236-
do irand = 1, nnpt + max(0_IK, nrand_loc)
232+
do irand = 1, max(0_IK, nrand_loc) + 1_IK
237233
! Initialize the random seed using N, IRAND, RP, and RANDSEED_LOC. Do not include IK so
238234
! that the results for different IK are the same.
239235
rseed = int(sum(istr(solname)) + sum(istr(probname)) + n + irand + RP + randseed_loc)
240236
call setseed(rseed)
241-
if (irand <= nnpt) then
242-
npt = npt_list(irand)
237+
if (irand <= 1) then
238+
npt = npt_list(ceiling(real(nnpt, RP)*rand())) ! Randomly select NPT from NPT_LIST
243239
else
244240
npt = int(TEN * rand() * real(n, RP), kind(npt))
245241
end if
246-
if (rand() <= 0.1) then
247-
npt = 0
248-
end if
249242
iprint = int(randn(), kind(iprint))
250-
maxfun = int(2.0E2_RP * rand() * real(n, RP), kind(maxfun))
243+
maxfun = int(1.0E2_RP * rand() * real(n, RP), kind(maxfun))
251244
maxhist = int(TWO * rand() * real(max(10_IK * n, maxfun), RP), kind(maxhist))
252245
if (rand() <= 0.1) then
253246
maxhist = -maxhist
@@ -261,7 +254,7 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
261254
end if
262255

263256
rhobeg = noisy(prob % Delta0)
264-
rhoend = max(1.0E-6_RP, rhobeg * 10.0_RP**(6.0_RP * rand() - 5.0_RP))
257+
rhoend = max(1.0E-5_RP, rhobeg * 10.0_RP**(6.0_RP * rand() - 5.0_RP))
265258
if (rand() <= 0.1) then
266259
rhoend = rhobeg
267260
elseif (rand() <= 0.1) then ! Note that the value of rand() changes.

fortran/tests/test_cobyla.f90

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ module test_solver_mod
5353
!
5454
! Started: September 2021
5555
!
56-
! Last Modified: Tue 19 Aug 2025 11:00:32 PM CST
56+
! Last Modified: Wed 20 Aug 2025 08:57:28 AM CST
5757
!--------------------------------------------------------------------------------------------------!
5858

5959
implicit none
@@ -170,7 +170,7 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
170170
if (present(nrand)) then
171171
nrand_loc = nrand
172172
else
173-
nrand_loc = NRAND_DFT * 5_IK ! More random tests than default since we cannot vary NPT as other solvers.
173+
nrand_loc = NRAND_DFT
174174
end if
175175

176176
if (present(randseed)) then
@@ -193,25 +193,21 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
193193
do irand = 1, 1 ! The test is expensive
194194
rseed = int(sum(istr(solname)) + sum(istr(probname)) + n + irand + RP + randseed_loc)
195195
call setseed(rseed)
196-
m = int(min(int(10.0_RP * rand() * real(n, RP)), 10**min(range(0), range(0_IK))), IK)
196+
m = int(min(int(5.0_RP * rand() * real(n, RP)), 10**min(range(0), range(0_IK))), IK)
197197
m = min(m, floor(real(huge(m)) / 8.0, IK) - n - 2_IK) ! Avoid integer overflow when calculating UNIT_MEMO in PREPROC/HISTORY
198198
call construct(prob, probname, n, m)
199199
iprint = 2_IK
200-
if (int(n) + 2000 > huge(0_IK)) then
201-
maxfun = huge(0_IK)
202-
else
203-
maxfun = n + int(2000.0_RP * rand(), IK)
204-
end if
200+
maxfun = n + int(min(1000.0_RP, real(4_IK*n, RP)) * rand(), IK)
205201
maxhist = maxfun
206202
maxfilt = int(TWO * rand() * real(maxfun, RP), kind(maxfilt))
207203
if (rand() <= 0.5) then
208204
ctol = TEN**(-abs(5.0 * randn()))
209205
else
210206
ctol = ZERO
211207
end if
212-
ftarget = -REALMAX
208+
ftarget = -TEN**abs(real(min(range(ftarget), 10), RP) * rand())
213209
rhobeg = noisy(prob % Delta0)
214-
rhoend = max(1.0E-6_RP, rhobeg * 10.0_RP**(6.0_RP * rand() - 6.0_RP))
210+
rhoend = max(1.0E-4_RP, rhobeg * 10.0_RP**(5.0_RP * rand() - 4.0_RP))
215211
call safealloc(x, n) ! Not all compilers support automatic allocation yet, e.g., Absoft.
216212
x = noisy(prob % x0)
217213
orig_calcfc => prob % calcfc
@@ -271,7 +267,7 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
271267
rseed = int(sum(istr(solname)) + sum(istr(probname)) + n + irand + RP + randseed_loc)
272268
call setseed(rseed)
273269
iprint = int(randn(), kind(iprint))
274-
maxfun = int(2.0E2_RP * rand() * real(n, RP), kind(maxfun))
270+
maxfun = int(1.0E2_RP * rand() * real(n, RP), kind(maxfun))
275271
maxhist = int(TWO * rand() * real(max(10_IK * n, maxfun), RP), kind(maxhist))
276272
if (rand() <= 0.1) then
277273
maxhist = -maxhist
@@ -296,7 +292,7 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
296292
end if
297293

298294
rhobeg = noisy(prob % Delta0)
299-
rhoend = max(1.0E-6_RP, rhobeg * 10.0_RP**(6.0_RP * rand() - 5.0_RP))
295+
rhoend = max(1.0E-5_RP, rhobeg * 10.0_RP**(6.0_RP * rand() - 5.0_RP))
300296
if (rand() <= 0.1) then
301297
rhoend = rhobeg
302298
elseif (rand() <= 0.1) then ! Note that the value of rand() changes.

fortran/tests/test_lincoa.f90

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ module test_solver_mod
8383
!
8484
! Started: September 2021
8585
!
86-
! Last Modified: Tue 19 Aug 2025 11:00:57 PM CST
86+
! Last Modified: Wed 20 Aug 2025 05:10:00 PM CST
8787
!--------------------------------------------------------------------------------------------------!
8888

8989
implicit none
@@ -145,7 +145,7 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
145145
integer(IK) :: nnpt
146146
integer(IK) :: nprobs
147147
integer(IK) :: npt
148-
integer(IK) :: npt_list(10)
148+
integer(IK) :: npt_list(100) ! Maximal number of prescribed NPT to test: 100
149149
integer(IK) :: nrand_loc
150150
integer(IK), parameter :: bign = 300_IK
151151
integer(IK), parameter :: largen = 1000_IK
@@ -224,25 +224,20 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
224224
do irand = 1, 1 ! The test is expensive
225225
rseed = int(sum(istr(solname)) + sum(istr(probname)) + n + irand + RP + randseed_loc)
226226
call setseed(rseed)
227-
m = int(min(int(10.0_RP * rand() * real(n, RP)), 10**min(range(0), range(0_IK))), IK)
227+
m = int(min(int(5.0_RP * rand() * real(n, RP)), 10**min(range(0), range(0_IK))), IK)
228228
call construct(prob, probname, n, m)
229-
npt = max(n + 2_IK, int(5.0 * rand() * real(n, RP), kind(npt)))
229+
npt = max(n + 2_IK, int(4.0 * rand() * real(n, RP), kind(npt)))
230230
iprint = 2_IK
231-
if (int(npt) + 2000 > huge(0_IK)) then
232-
maxfun = huge(0_IK)
233-
else
234-
maxfun = npt + int(2000.0_RP * rand(), IK)
235-
end if
236-
maxhist = maxfun
231+
maxfun = npt + int(min(1000.0_RP, real(2_IK*npt, RP)) * rand(), IK)
237232
maxfilt = int(TWO * rand() * real(maxfun, RP), kind(maxfilt))
238233
if (rand() <= 0.5) then
239234
ctol = TEN**(-abs(5.0 * randn()))
240235
else
241236
ctol = ZERO
242237
end if
243-
ftarget = -REALMAX
238+
ftarget = -TEN**abs(real(min(range(ftarget), 10), RP) * rand())
244239
rhobeg = noisy(prob % Delta0)
245-
rhoend = max(1.0E-6_RP, rhobeg * 10.0_RP**(6.0_RP * rand() - 6.0_RP))
240+
rhoend = max(1.0E-4_RP, rhobeg * 10.0_RP**(5.0_RP * rand() - 4.0_RP))
246241
call safealloc(x, n) ! Not all compilers support automatic allocation yet, e.g., Absoft.
247242
x = noisy(prob % x0)
248243
orig_calfun => prob % calfun
@@ -297,27 +292,24 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
297292
n = prob % n
298293

299294
! NPT_LIST defines some extreme values of NPT.
300-
nnpt = 10
301-
npt_list(1:nnpt) = [1_IK, &
295+
nnpt = 11
296+
npt_list(1:nnpt) = [0_IK, 1_IK, &
302297
& n + 1_IK, n + 2_IK, n + 3_IK, &
303298
& 2_IK * n, 2_IK * n + 1_IK, 2_IK * n + 2_IK, &
304299
& (n + 1_IK) * (n + 2_IK) / 2_IK - 1_IK, (n + 1_IK) * (n + 2_IK) / 2_IK, &
305300
& (n + 1_IK) * (n + 2_IK) / 2_IK + 1_IK]
306-
do irand = 1, nnpt + max(0_IK, nrand_loc)
301+
do irand = 1, max(0_IK, nrand_loc) + 1_IK
307302
! Initialize the random seed using N, IRAND, RP, and RANDSEED_LOC. Do not include IK so
308303
! that the results for different IK are the same.
309304
rseed = int(sum(istr(solname)) + sum(istr(probname)) + n + irand + RP + randseed_loc)
310305
call setseed(rseed)
311-
if (irand <= nnpt) then
312-
npt = npt_list(irand)
306+
if (irand <= 1) then
307+
npt = npt_list(ceiling(real(nnpt, RP)*rand())) ! Randomly select NPT from NPT_LIST
313308
else
314309
npt = int(TEN * rand() * real(n, RP), kind(npt))
315310
end if
316-
if (rand() <= 0.1) then
317-
npt = 0
318-
end if
319311
iprint = int(randn(), kind(iprint))
320-
maxfun = int(2.0E2_RP * rand() * real(n, RP), kind(maxfun))
312+
maxfun = int(1.0E2_RP * rand() * real(n, RP), kind(maxfun))
321313
maxhist = int(TWO * rand() * real(max(10_IK * n, maxfun), RP), kind(maxhist))
322314
if (rand() <= 0.1) then
323315
maxhist = -maxhist
@@ -342,16 +334,14 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
342334
end if
343335

344336
rhobeg = noisy(prob % Delta0)
345-
rhoend = max(1.0E-6_RP, rhobeg * 10.0_RP**(6.0_RP * rand() - 5.0_RP))
337+
rhoend = max(1.0E-5_RP, rhobeg * 10.0_RP**(6.0_RP * rand() - 5.0_RP))
346338
if (rand() <= 0.1) then
347339
rhoend = rhobeg
348340
elseif (rand() <= 0.1) then ! Note that the value of rand() changes.
349341
rhobeg = ZERO
350342
end if
351-
352343
call safealloc(x0, n) ! Not all compilers support automatic allocation yet, e.g., Absoft.
353344
x0 = noisy(prob % x0)
354-
355345
orig_calfun => prob % calfun
356346

357347
call safealloc(xl, n)
@@ -405,6 +395,7 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
405395
end do
406396
end if
407397

398+
408399
! Test recursive call.
409400
! The depth of the recursion is 2. The first recursion is in RECURSIVE_FUN1, and the second is in
410401
! RECURSIVE_FUN2. RECURSIVE_FUN1(Y) is defined by minimizing the CHROSEN function subject to

fortran/tests/test_newuoa.f90

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module test_solver_mod
4949
!
5050
! Started: September 2021
5151
!
52-
! Last Modified: Tue 19 Aug 2025 11:01:14 PM CST
52+
! Last Modified: Wed 20 Aug 2025 05:06:58 PM CST
5353
!--------------------------------------------------------------------------------------------------!
5454

5555
implicit none
@@ -104,7 +104,7 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
104104
integer(IK) :: nnpt
105105
integer(IK) :: nprobs
106106
integer(IK) :: npt
107-
integer(IK) :: npt_list(10)
107+
integer(IK) :: npt_list(100) ! Maximal number of prescribed NPT to test: 100
108108
integer(IK) :: nrand_loc
109109
integer(IK), parameter :: bign = 300_IK
110110
integer(IK), parameter :: largen = 1600_IK
@@ -170,17 +170,13 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
170170
do irand = 1, 1 ! The test is expensive
171171
rseed = int(sum(istr(solname)) + sum(istr(probname)) + n + irand + RP + randseed_loc)
172172
call setseed(rseed)
173-
npt = max(n + 2_IK, int(5.0 * rand() * real(n, RP), kind(npt)))
173+
npt = max(n + 2_IK, int(4.0 * rand() * real(n, RP), kind(npt)))
174174
iprint = 2_IK
175-
if (int(npt) + 2000 > huge(0_IK)) then
176-
maxfun = huge(0_IK)
177-
else
178-
maxfun = npt + int(2000.0_RP * rand(), IK)
179-
end if
175+
maxfun = npt + int(min(1000.0_RP, real(2_IK*npt, RP)) * rand(), IK)
180176
maxhist = maxfun
181-
ftarget = -REALMAX
177+
ftarget = -TEN**abs(real(min(range(ftarget), 10), RP) * rand())
182178
rhobeg = noisy(prob % Delta0)
183-
rhoend = max(1.0E-6_RP, rhobeg * 10.0_RP**(6.0_RP * rand() - 6.0_RP))
179+
rhoend = max(1.0E-4_RP, rhobeg * 10.0_RP**(5.0_RP * rand() - 4.0_RP))
184180
call safealloc(x, n) ! Not all compilers support automatic allocation yet, e.g., Absoft.
185181
x = noisy(prob % x0)
186182
orig_calfun => prob % calfun
@@ -207,30 +203,27 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
207203
call construct(prob, probname, n) ! Construct the testing problem.
208204

209205
! NPT_LIST defines some extreme values of NPT.
210-
nnpt = 10
211-
npt_list(1:nnpt) = [1_IK, &
206+
nnpt = 11
207+
npt_list(1:nnpt) = [0_IK, 1_IK, &
212208
& n + 1_IK, n + 2_IK, n + 3_IK, &
213209
& 2_IK * n, 2_IK * n + 1_IK, 2_IK * n + 2_IK, &
214210
& (n + 1_IK) * (n + 2_IK) / 2_IK - 1_IK, (n + 1_IK) * (n + 2_IK) / 2_IK, &
215211
& (n + 1_IK) * (n + 2_IK) / 2_IK + 1_IK]
216-
do irand = 1, nnpt + max(0_IK, nrand_loc)
212+
do irand = 1, max(0_IK, nrand_loc) + 1_IK
217213
! Initialize the random seed using N, IRAND, RP, and RANDSEED_LOC. Do not include IK so
218214
! that the results for different IK are the same.
219215
rseed = int(sum(istr(solname)) + sum(istr(probname)) + n + irand + RP + randseed_loc)
220216
call setseed(rseed)
221-
if (irand <= nnpt) then
222-
npt = npt_list(irand)
217+
if (irand <= 1) then
218+
npt = npt_list(ceiling(real(nnpt, RP)*rand())) ! Randomly select NPT from NPT_LIST
223219
else
224220
npt = int(TEN * rand() * real(n, RP), kind(npt))
225221
end if
226-
if (rand() <= 0.1) then
227-
npt = 0
228-
end if
229222
iprint = int(randn(), kind(iprint))
230-
maxfun = int(2.0E2_RP * rand() * real(n, RP), kind(maxfun))
223+
maxfun = int(1.0E2_RP * rand() * real(n, RP), kind(maxfun))
231224
maxhist = int(TWO * rand() * real(max(10_IK * n, maxfun), RP), kind(maxhist))
232225
if (rand() <= 0.1) then
233-
maxhist = 0
226+
maxhist = -maxhist
234227
end if
235228
if (rand() <= 0.8) then
236229
ftarget = -TEN**abs(real(min(range(ftarget), 12), RP) * rand())
@@ -241,7 +234,7 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
241234
end if
242235

243236
rhobeg = noisy(prob % Delta0)
244-
rhoend = max(1.0E-6_RP, rhobeg * 10.0_RP**(6.0_RP * rand() - 5.0_RP))
237+
rhoend = max(1.0E-5_RP, rhobeg * 10.0_RP**(6.0_RP * rand() - 5.0_RP))
245238
if (rand() <= 0.1) then
246239
rhoend = rhobeg
247240
elseif (rand() <= 0.1) then ! Note that the value of rand() changes.

0 commit comments

Comments
 (0)