Giter Club home page Giter Club logo

Comments (2)

zaikunzhang avatar zaikunzhang commented on September 20, 2024

Update: The Windows / macOS test does not always fail. This is even stranger.

https://github.com/sprimalib/prima/actions/runs/6247172429

from prima.

zaikunzhang avatar zaikunzhang commented on September 20, 2024

Fixed by adding -assume recursion (macos) or /assume:recursion (windows) to the flags of ifort. See

% Modify the compiler options by revising FFLAGS or COMPFLAGS.
% See https://www.mathworks.com/help/matlab/ref/mex.html
% 1. We force the Fortran compiler to allocate arrays on the heap instead of the stack. Otherwise,
% the solvers will encounter stack overflow when the problem size is large. 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.
% 2. We require the Fortran compiler to compile the solvers so that they can be called recursively.
% Otherwise, the solvers will not work properly in recursive invocations. See
% https://fortran-lang.discourse.group/t/frecursive-assume-recursion-and-recursion-thread-safety
compiler_configurations = mex.getCompilerConfigurations('fortran', 'selected');
if contains(compiler_configurations.Manufacturer, 'gnu', 'IgnoreCase', true) % gfortran
extra_compiler_options = '-fno-stack-arrays -frecursive';
elseif contains(compiler_configurations.Manufacturer, 'intel', 'IgnoreCase', true) % Intel compiler
if ispc
extra_compiler_options = '/heap-arrays /assume:recursion';
else
extra_compiler_options = '-heap-arrays -assume recursion';
end
else
warning('prima:UnrecognizedCompiler', 'Unrecognized compiler %s. The package may not work.', ...
compiler_configurations.Name);
extra_compiler_options = '';
end
if ispc % Windows
compiler_options = ['COMPFLAGS="$COMPFLAGS ', extra_compiler_options, '"'];
else
compiler_options = ['FFLAGS="$FFLAGS ', extra_compiler_options, '"'];
end

https://fortran-lang.discourse.group/t/frecursive-assume-recursion-and-recursion-thread-safety

from prima.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.