Skip to content

Commit 75fd178

Browse files
committed
250720.104500.PDT minor updates
1 parent 88287f1 commit 75fd178

File tree

7 files changed

+15
-17
lines changed

7 files changed

+15
-17
lines changed

matlab/mex_gateways/R2025a/bobyqa_mex.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ module calfun_mod
3636
contains
3737

3838
subroutine calfun(x, f)
39-
use, non_intrinsic :: consts_mod, only : RP
4039
use, non_intrinsic :: cbfun_mod, only : evalcb
40+
use, non_intrinsic :: consts_mod, only : RP
4141
implicit none
4242
real(RP), intent(in) :: x(:)
4343
real(RP), intent(out) :: f

matlab/mex_gateways/R2025a/cobyla_mex.F90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ module calcfc_mod
3131
private
3232
public :: funcon_ptr, calcfc
3333

34-
mwPointer :: funcon_ptr ! Pointer to the objective function handle
34+
mwPointer :: funcon_ptr ! Pointer to the objective/constraint function handle
3535

3636
contains
3737

3838
subroutine calcfc(x, f, nlconstr)
39-
use, non_intrinsic :: consts_mod, only : RP
4039
use, non_intrinsic :: cbfun_mod, only : evalcb
40+
use, non_intrinsic :: consts_mod, only : RP
4141
implicit none
4242
real(RP), intent(in) :: x(:)
4343
real(RP), intent(out) :: f

matlab/mex_gateways/R2025a/cobylb.f90

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,18 @@ module calcfc_internal_mod
2525
contains
2626

2727
subroutine calcfc_internal(x_internal, f_internal, constr_internal)
28-
!--------------------------------------------------------------------------------------------------!
29-
! This internal subroutine evaluates the objective function and ALL the constraints.
30-
! In MATLAB/Python/R/Julia, this can be implemented as a lambda function/anonymous function.
31-
!--------------------------------------------------------------------------------------------------!b
3228
use, non_intrinsic :: linalg_mod, only : matprod
3329
implicit none
34-
! Inputs
3530
real(RP), intent(in) :: x_internal(:)
36-
! Outputs
3731
real(RP), intent(out) :: f_internal
3832
real(RP), intent(out) :: constr_internal(:)
3933
constr_internal(1:m_lcon_internal) = matprod(x_internal, amat_ptr) - bvec_ptr
4034
call calcfc_ptr(x_internal, f_internal, constr_internal(m_lcon_internal+1:m_internal))
4135
end subroutine calcfc_internal
4236

43-
4437
end module calcfc_internal_mod
4538

39+
4640
module cobylb_mod
4741
!--------------------------------------------------------------------------------------------------!
4842
! This module performs the major calculations of COBYLA.

matlab/mex_gateways/R2025a/lincoa_mex.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ module calfun_mod
3636
contains
3737

3838
subroutine calfun(x, f)
39-
use, non_intrinsic :: consts_mod, only : RP
4039
use, non_intrinsic :: cbfun_mod, only : evalcb
40+
use, non_intrinsic :: consts_mod, only : RP
4141
implicit none
4242
real(RP), intent(in) :: x(:)
4343
real(RP), intent(out) :: f

matlab/mex_gateways/R2025a/newuoa_mex.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ module calfun_mod
3636
contains
3737

3838
subroutine calfun(x, f)
39-
use, non_intrinsic :: consts_mod, only : RP
4039
use, non_intrinsic :: cbfun_mod, only : evalcb
40+
use, non_intrinsic :: consts_mod, only : RP
4141
implicit none
4242
real(RP), intent(in) :: x(:)
4343
real(RP), intent(out) :: f

matlab/mex_gateways/R2025a/uobyqa_mex.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ module calfun_mod
3636
contains
3737

3838
subroutine calfun(x, f)
39-
use, non_intrinsic :: consts_mod, only : RP
4039
use, non_intrinsic :: cbfun_mod, only : evalcb
40+
use, non_intrinsic :: consts_mod, only : RP
4141
implicit none
4242
real(RP), intent(in) :: x(:)
4343
real(RP), intent(out) :: f

matlab/setup_tools/compile.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function compile(solvers, mexdir, fortd, gateways, options)
6666
% The following code is to circumvent a bug in MATLAB R2025a, which segfaults on Linux when the
6767
% Fortran files contain internal procedures that are passed as actual arguments to other procedures.
6868
% To avoid this bug, we replace gateways/*_mex.F90 with gateways/R2025a/*_mex.F90, and
69-
% fortran/cobylb.f90 with gateways/R2025a/cobylb.f90, which uses module variables instead of
69+
% fortran/cobylb.f90 with gateways/R2025a/cobylb.f90, which use module variables instead of
7070
% internal procedures. The price is that PRIMA becomes thread-unsafe and recursion-unsafe.
7171
% See MathWorks Technical Support Case 07931486 and
7272
% https://www.mathworks.com/matlabcentral/answers/2178414-bug-matlab-2025a-segfaults-on-ubuntu-when-handling-fortran-mex-files-with-internal-subroutines
@@ -80,12 +80,16 @@ function compile(solvers, mexdir, fortd, gateways, options)
8080
['MATLAB R2025a has a bug that causes segmentation faults when handling Fortran MEX files with internal procedures.\n', ...
8181
' PRIMA is adapted to circumvent this bug but it becomes thread-unsafe and recursion-unsafe.']);
8282
end
83-
% Replace the files. N.B.: The .*f90 files have become .* files after the refactorization in setup.m.
83+
% Replace the files. N.B.: The .*90 files have become .* after the code refactoring in setup.m.
84+
replacement_dir = fullfile(gateways, 'R2025a');
8485
for isol = 1 : length(solvers)
8586
solver = solvers{isol};
86-
copyfile(fullfile(gateways, 'R2025a', [solver, '_mex.F']), fullfile(gateways, [solver, '_mex.F']));
87+
copyfile(fullfile(replacement_dir, [solver, '_mex.F']), fullfile(gateways, [solver, '_mex.F']));
88+
if strcmp(solver, 'cobyla')
89+
% For COBYLA, we also need to replace the Fortran source file cobylb.f.
90+
copyfile(fullfile(replacement_dir, 'cobylb.f'), fullfile(fortd, 'cobyla', 'cobylb.f'));
91+
end
8792
end
88-
copyfile(fullfile(gateways, 'R2025a', 'cobylb.f'), fullfile(fortd, 'cobyla', 'cobylb.f'));
8993
end
9094
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9195

0 commit comments

Comments
 (0)