Fix potential stack overflow in overset initialisation#405
Open
A-CGray wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
I have ADflow compiled locally with
-Ofastoptimisations and was running into segfaults when trying to run certain overset meshes. Turns out-Ofastenables the-fstack-arraysflag, which causes gfortran to allocate the memory for arrays on the stack, even when it doesn't know their size. Depending on the size on the size of your mesh, and the number of cores you're working with, some of the code in the overset utils ends up allocating arrays on the stack which are too large (the default limit is 8mb apparently), leading to a stack overflow.This PR fixes the issue by switching one of the problematic array copies to an explicit do loop, and replaces the other ones with array reallocation utility routines that are already in the code (that also use an explicit do loop).
This shouldn't be a commonly encountered issue because it only happens with
-Ofastand relatively high (~150k) cell counts per core.Expected time until merged
Soon
Type of change
Testing
Checklist
ruff checkandruff formatto make sure the Python code adheres to PEP-8 and is consistently formattedfprettifyor C/C++ code withclang-formatas applicable