Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLAPACK test programs reporting stack overflow on Windows #987

Open
2 tasks done
phetdam opened this issue Feb 23, 2024 · 4 comments
Open
2 tasks done

CLAPACK test programs reporting stack overflow on Windows #987

phetdam opened this issue Feb 23, 2024 · 4 comments

Comments

@phetdam
Copy link

phetdam commented Feb 23, 2024

Description

Several of the CLAPACK test programs, mostly the linear algebra ones, e.g. xeigtstz, xlintstc, use quite a bit of stack space, which is a problem on Windows since the default stack size reserved by the MSVC linker is 1 MB. These test programs all crash since they exhaust the stack, but this can be worked around by passing a larger value via /STACK to the MSVC linker.

Steps to reproduce from my original report:

  1. cd into clapack-3.2.1-CMAKE top-level dir
  2. Build: cmake -S . -B build_windows_x86 -A Win32 && cmake --build build_windows_x86 --config Debug
  3. Test: ctest --test-dir build_windows_x86 -C Debug

Originally, I noticed this when I built the CLAPACK 3.2.1 tarball that includes the CMake configuration, i.e. clapack-3.2.1-CMAKE.tgz from the Netlib CLAPACK page. After poking around a bit, I noticed in TESTING/CMakeLists.txt these lines:

if(MSVC_VERSION)
# string(REPLACE "/STACK:10000000" "/STACK:900000000000000000"
# CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
string(REGEX REPLACE "(.*)/STACK:(.*) (.*)" "\\1/STACK:900000000000000000 \\3"
CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
endif()

Clearly there was an effort before to work around the smaller Windows stack size. Unfortunately, this is ineffective, as at least for Visual Studio 2019 and 2022 I reproduced the issue on, no /STACK parameter is passed to the MSVC linker by default.

Fortunately, appending /STACK:12000000 (~12 MB stack size) to CMAKE_EXE_LINKER_FLAGS was relatively easy to do and fixed the issue. I determined the stack space to reserve very crudely via experimentation, first trying 10 MB, then 12 MB.

Reporting issue here since CLAPACK forum moved to the mailing list which said to use the GitHub issue tracker.

Checklist

  • I've included a minimal example to reproduce the issue
  • I'd be willing to make a PR to solve this issue
@langou
Copy link
Contributor

langou commented Feb 23, 2024

Thanks Derek. This is a known issue but you explain it very clearly. CLAPACK is not part of this GitHub repository. But it is fine to report the issue here. Thanks for doing this.

@phetdam
Copy link
Author

phetdam commented Feb 23, 2024

No problem, thanks for the kind words. I ran into this a while ago but finally found some time to poke around.

Glad that it was relatively easy to fix by replacing the TESTING/CMakeLists.txt lines shown above with this:

if(MSVC)
  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:12000000")
endif()

Update: Confirmed this works for both debug + release configurations as well as for both 32- and 64-bit builds.

@martin-frbg
Copy link
Collaborator

IIRC this has been fixed in LAPACK quite a while ago by changing the allocation method used for several huge arrays in the testsuite. Unfortunately CLAPACK has not been updated in a long time and many current LAPACK routines can no longer be machine translated with the equally ancient f2c as they use newer language features of Fortran.

@phetdam
Copy link
Author

phetdam commented Feb 23, 2024

Got it, thanks for the information. I've been working on a pretty ancient codebase that depends on CLAPACK, albeit in a bit of a roundabout manner to avoid including f2c.h directly, but maybe it's time to considering migrating to LAPACKE instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants