Skip to content

Commit

Permalink
fix: maximize system stacksize limit in fms_init (#1233)
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Lentz authored Jul 13, 2023
1 parent 0463dd1 commit 8eb24f8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
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 @@ -336,6 +336,11 @@ subroutine fms_init (localcomm, alt_input_nml_path)
use fms_io_mod, only: fms_io_version
#endif

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 @@ -344,6 +349,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);
}

0 comments on commit 8eb24f8

Please sign in to comment.