Skip to content

Commit

Permalink
230627.074557.CST revise stress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zaikunzhang committed Jun 26, 2023
1 parent f85852f commit e124964
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 24 deletions.
8 changes: 4 additions & 4 deletions fortran/tests/test_bobyqa.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module test_solver_mod
!
! Started: September 2021
!
! Last Modified: Sunday, June 25, 2023 PM08:36:59
! Last Modified: Tuesday, June 27, 2023 AM07:42:30
!--------------------------------------------------------------------------------------------------!

implicit none
Expand Down Expand Up @@ -134,15 +134,15 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
call setseed(rseed)
npt = max(n + 2_IK, int(5.0 * rand() * real(n, RP), kind(npt)))
iprint = 2_IK
if (int(npt) + 1000 > huge(0_IK)) then
if (int(npt) + 2000 > huge(0_IK)) then
maxfun = huge(0_IK)
else
maxfun = npt + int(1000.0_RP * rand(), IK)
maxfun = npt + int(2000.0_RP * rand(), IK)
end if
maxhist = maxfun
ftarget = -REALMAX
rhobeg = noisy(prob % Delta0)
rhoend = max(1.0E-6_RP, rhobeg * 1.0E1_RP**(4.0_RP * rand() - 3.5_RP))
rhoend = max(1.0E-6_RP, rhobeg * 1.0E1_RP**(6.0_RP * rand() - 6.0_RP))
call safealloc(x, n) ! Not all compilers support automatic allocation yet, e.g., Absoft.
x = noisy(prob % x0)
orig_calfun => prob % calfun
Expand Down
8 changes: 4 additions & 4 deletions fortran/tests/test_cobyla.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module test_solver_mod
!
! Started: September 2021
!
! Last Modified: Monday, June 26, 2023 PM09:35:41
! Last Modified: Tuesday, June 27, 2023 AM07:43:01
!--------------------------------------------------------------------------------------------------!

implicit none
Expand Down Expand Up @@ -142,10 +142,10 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
m = int(min(int(10.0_RP * rand() * real(n, RP)), 10**min(range(0), range(0_IK))), IK)
call construct(prob, probname, n, m)
iprint = 2_IK
if (int(n) + 1000 > huge(0_IK)) then
if (int(n) + 2000 > huge(0_IK)) then
maxfun = huge(0_IK)
else
maxfun = n + int(1000.0_RP * rand(), IK)
maxfun = n + int(2000.0_RP * rand(), IK)
end if
maxhist = maxfun
maxfilt = int(TWO * rand() * real(maxfun, RP), kind(maxfilt))
Expand All @@ -156,7 +156,7 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
end if
ftarget = -REALMAX
rhobeg = noisy(prob % Delta0)
rhoend = max(1.0E-6_RP, rhobeg * 1.0E1_RP**(4.0_RP * rand() - 3.5_RP))
rhoend = max(1.0E-6_RP, rhobeg * 1.0E1_RP**(6.0_RP * rand() - 6.0_RP))
call safealloc(x, n) ! Not all compilers support automatic allocation yet, e.g., Absoft.
x = noisy(prob % x0)
orig_calcfc => prob % calcfc
Expand Down
8 changes: 4 additions & 4 deletions fortran/tests/test_lincoa.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module test_solver_mod
!
! Started: September 2021
!
! Last Modified: Sunday, June 25, 2023 PM08:37:36
! Last Modified: Tuesday, June 27, 2023 AM07:43:24
!--------------------------------------------------------------------------------------------------!

implicit none
Expand Down Expand Up @@ -146,10 +146,10 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
call construct(prob, probname, n, m)
npt = max(n + 2_IK, int(5.0 * rand() * real(n, RP), kind(npt)))
iprint = 2_IK
if (int(npt) + 1000 > huge(0_IK)) then
if (int(npt) + 2000 > huge(0_IK)) then
maxfun = huge(0_IK)
else
maxfun = npt + int(1000.0_RP * rand(), IK)
maxfun = npt + int(2000.0_RP * rand(), IK)
end if
maxhist = maxfun
maxfilt = int(TWO * rand() * real(maxfun, RP), kind(maxfilt))
Expand All @@ -160,7 +160,7 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
end if
ftarget = -REALMAX
rhobeg = noisy(prob % Delta0)
rhoend = max(1.0E-6_RP, rhobeg * 1.0E1_RP**(4.0_RP * rand() - 3.5_RP))
rhoend = max(1.0E-6_RP, rhobeg * 1.0E1_RP**(6.0_RP * rand() - 6.0_RP))
call safealloc(x, n) ! Not all compilers support automatic allocation yet, e.g., Absoft.
x = noisy(prob % x0)
orig_calfun => prob % calfun
Expand Down
8 changes: 4 additions & 4 deletions fortran/tests/test_newuoa.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module test_solver_mod
!
! Started: September 2021
!
! Last Modified: Sunday, June 25, 2023 PM08:37:53
! Last Modified: Tuesday, June 27, 2023 AM07:43:43
!--------------------------------------------------------------------------------------------------!

implicit none
Expand Down Expand Up @@ -128,15 +128,15 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
call setseed(rseed)
npt = max(n + 2_IK, int(5.0 * rand() * real(n, RP), kind(npt)))
iprint = 2_IK
if (int(npt) + 1000 > huge(0_IK)) then
if (int(npt) + 2000 > huge(0_IK)) then
maxfun = huge(0_IK)
else
maxfun = npt + int(1000.0_RP * rand(), IK)
maxfun = npt + int(2000.0_RP * rand(), IK)
end if
maxhist = maxfun
ftarget = -REALMAX
rhobeg = noisy(prob % Delta0)
rhoend = max(1.0E-6_RP, rhobeg * 1.0E1_RP**(4.0_RP * rand() - 3.5_RP))
rhoend = max(1.0E-6_RP, rhobeg * 1.0E1_RP**(6.0_RP * rand() - 6.0_RP))
call safealloc(x, n) ! Not all compilers support automatic allocation yet, e.g., Absoft.
x = noisy(prob % x0)
orig_calfun => prob % calfun
Expand Down
8 changes: 4 additions & 4 deletions fortran/tests/test_uobyqa.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module test_solver_mod
!
! Started: September 2021
!
! Last Modified: Monday, June 26, 2023 PM09:42:08
! Last Modified: Tuesday, June 27, 2023 AM07:44:03
!--------------------------------------------------------------------------------------------------!

implicit none
Expand Down Expand Up @@ -123,15 +123,15 @@ subroutine test_solver(probs, mindim, maxdim, dimstride, nrand, randseed, testdi
call setseed(rseed)
iprint = 2_IK
npt = (n + 2_IK) * (n + 1_IK) / 2_IK
if (int(npt) + 1000 > huge(0_IK)) then
if (int(npt) + 2000 > huge(0_IK)) then
maxfun = huge(0_IK)
else
maxfun = npt + int(1000.0_RP * rand(), IK)
maxfun = npt + int(2000.0_RP * rand(), IK)
end if
maxhist = maxfun
ftarget = -REALMAX
rhobeg = noisy(prob % Delta0)
rhoend = max(1.0E-6_RP, rhobeg * 1.0E1_RP**(4.0_RP * rand() - 3.5_RP))
rhoend = max(1.0E-6_RP, rhobeg * 1.0E1_RP**(6.0_RP * rand() - 6.0_RP))
call safealloc(x, n) ! Not all compilers support automatic allocation yet, e.g., Absoft.
x = noisy(prob % x0)
orig_calfun => prob % calfun
Expand Down
17 changes: 13 additions & 4 deletions matlab/tests/stress.m
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
function stress(solver, options)
%STRESS Stress test for the solver on problems large dimensions.
% N.B.: When the dimension beyond some limit, the MEX function will crash due to memory violations.
% As we can see below in the comments, the limit is much higher on Linux than on macOS and Windows.
% This is probably because MEX uses gfortran on Linux, and it puts automatic arrays on the heap by
% default, where as MEX uses ifort on macOS and Windows, and it puts automatic arrays on the stack
% by default.
% In the official version, the limit for each solver is much higher than the size of problems that
% it is designed to solve. To achieve this, we have to force the MEX function to use the heap
% instead of the stack for automatic arrays. This is done by the following compilation options:
% gfortran on Linux: -fno-stack-arrays
% Intel compiler on macOS: -heap-arrays
% Intel compiler on Windows: /heap-arrays
% As of gfortran 12.0, `-fno-stack-arrays` is indeed the default, and we specify it for safety; as
% of Intel oneAPI 2023.1.0, `-no-heap-arrays` is the default, so we must specify `-heap-arrays`.
% N.B.: We assume that the function evaluation is much more expensive than the memory allocation,
% so the performance loss due to the heap allocation is negligible. This is true for derivative-free
% optimization, but may not be true for optimization with derivatives.
% See matlab/setup_tools/compile.m for details.


% Turn off unwanted warnings
orig_warning_state = warnoff({solver});
Expand Down

0 comments on commit e124964

Please sign in to comment.