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

Maximize system stacksize limit #1233

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fms/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ noinst_LTLIBRARIES = libfms.la
# Each convenience library depends on its source.
libfms_la_SOURCES = \
fms.F90 \
fms_stacksize.c \
include/fms.inc \
include/fms_r4.fh \
include/fms_r8.fh \
Expand Down
9 changes: 9 additions & 0 deletions fms/fms.F90
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ subroutine fms_init (localcomm, alt_input_nml_path)
use constants_mod, only: constants_version=>version !pjp: PI not computed
use fms_io_mod, only: fms_io_version

interface
subroutine maximize_system_stacksize_limit() bind(C)
end subroutine
end interface

integer, intent(in), optional :: localcomm
character(len=*), intent(in), optional :: alt_input_nml_path
integer :: ierr, io
Expand All @@ -333,6 +338,10 @@ subroutine fms_init (localcomm, alt_input_nml_path)

if (module_is_initialized) return ! return silently if already called
module_is_initialized = .true.

!---- Raise the system stack size limit to its maximum permissible value ----
call maximize_system_stacksize_limit

!---- initialize mpp routines ----
if(present(localcomm)) then
if(present(alt_input_nml_path)) then
Expand Down
33 changes: 33 additions & 0 deletions fms/fms_stacksize.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/***********************************************************************
* GNU Lesser General Public License
*
* This file is part of the GFDL Flexible Modeling System (FMS).
*
* FMS is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* FMS is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FMS. If not, see <http://www.gnu.org/licenses/>.
**********************************************************************/

#include <sys/resource.h>

/*
* Set the stack size limit to its maximum permissible value
*/

void maximize_system_stacksize_limit()
{
struct rlimit stacksize;

getrlimit(RLIMIT_STACK, &stacksize);
stacksize.rlim_cur = stacksize.rlim_max;
setrlimit(RLIMIT_STACK, &stacksize);
Comment on lines +28 to +32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we typically test on SLES, ubuntu, and Centos, but please make an effort to ensure the struct and function exist and works the same way on Mac OS.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested it on Mac OS, but sys/resource.h is a POSIX API (see: resource.h specification) which includes getrlimit(), setrlimit(), struct rlimit, and the RLIMIT_STACK constant. I believe Mac OS is POSIX-compliant, so compatibility shouldn't be an issue.

}