Skip to content
Open
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
16 changes: 13 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

# Copyright (c) GFDL, @underwoo

cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
cmake_minimum_required(VERSION 3.22 FATAL_ERROR)

# Define the CMake project
project(FMS
VERSION 2025.04.0
DESCRIPTION "GFDL FMS Library"
HOMEPAGE_URL "https://www.gfdl.noaa.gov/fms"
LANGUAGES C Fortran)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include(GNUInstallDirs)

if(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release|RelWithDebInfo|MinSizeRel|DebugUFS|ReleaseUFS)$")
Expand Down Expand Up @@ -66,6 +66,11 @@ option(LARGEFILE "Enable compiler definition -Duse_LARGEFILE"
option(WITH_YAML "Enable compiler definition -Duse_yaml" OFF)
option(USE_DEPRECATED_IO "THIS OPTION HAS NO EFFECT AND WILL BE REMOVED IN A FUTURE RELEASE" OFF)

if(CMAKE_Fortran_COMPILER_ID MATCHES "NVHPC")
set(ENABLE_QUAD_PRECISION OFF)
message(WARNING "NVHPC does not support building FMS with QUAD_PRECISION!")
endif()

if(32BIT)
list(APPEND kinds "r4")
endif()
Expand Down Expand Up @@ -332,6 +337,7 @@ foreach(kind ${kinds})
mosaic2/include
constants
astronomy/include
field_manager/
Copy link
Author

Choose a reason for hiding this comment

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

When building with nvhpc it could not find parse.inc which is here

field_manager/include
time_interp/include
tracer_manager/include
Expand Down Expand Up @@ -747,9 +753,13 @@ list(APPEND TEST_SRC_SINGLE_TARGET
test_fms/parser/parser_demo2.F90
test_fms/parser/test_output_yaml.F90
test_fms/parser/generic_blocks.F90
test_fms/string_utils/test_string_utils.F90
test_fms/time_manager/test_time_manager.F90
)
if(NOT ${CMAKE_Fortran_COMPILER_ID} STREQUAL "NVHPC")
list(APPEND TEST_SRC_SINGLE_TARGET
test_fms/string_utils/test_string_utils.F90
)
endif()
# list any test sources that are used for two executables (r4 and r8)
list(APPEND TEST_SRC_TWO_TARGETS
test_fms/astronomy/test_astronomy.F90
Expand Down
6 changes: 6 additions & 0 deletions cmake/compiler_flags_NVHPC_C.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# NVHPC C
set(CMAKE_C_FLAGS_RELEASE "-O3")

set(CMAKE_C_FLAGS_DEBUG "-O0 -g")

set(CMAKE_C_LINK_FLAGS "")
13 changes: 13 additions & 0 deletions cmake/compiler_flags_NVHPC_Fortran.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Precision-based Fortran compiler flags
set(r8_flags "-r8") # Fortran flags for 64BIT precision

# NVHPC Fortan
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ")

set(CMAKE_Fortran_FLAGS_RELEASE "-O3")

set(CMAKE_Fortran_FLAGS_DEBUG "-O0" )
# -g can cause bugs, see: https://forums.developer.nvidia.com/t/bug-compiling-with-g-o0-produces-a-compute-sanitizer-error-removing-g-removes-the-error/341478
# not sure if this is only on GPUs

set(CMAKE_Fortran_LINK_FLAGS "" )
4 changes: 4 additions & 0 deletions cmake/fms_compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
include(compiler_flags_Intel_Fortran)
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM")
include(compiler_flags_IntelLLVM_Fortran)
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "NVHPC")
include(compiler_flags_NVHPC_Fortran)
else()
message(WARNING "Fortran compiler with ID ${CMAKE_Fortran_COMPILER_ID} will be used with CMake default options")
endif()
Expand All @@ -24,6 +26,8 @@ elseif(CMAKE_C_COMPILER_ID STREQUAL "IntelLLVM")
include(compiler_flags_IntelLLVM_C)
elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
include(compiler_flags_Clang_C)
elseif(CMAKE_C_COMPILER_ID MATCHES "NVHPC")
include(compiler_flags_NVHPC_C)
else()
message(WARNING "C compiler with ID ${CMAKE_C_COMPILER_ID} will be used with CMake default options")
endif()
11 changes: 7 additions & 4 deletions exchange/xgrid.F90
Original file line number Diff line number Diff line change
Expand Up @@ -4023,9 +4023,12 @@ subroutine get_1_from_xgrid_repro(d_addrs, x_addrs, xmap, xsize, lsize)
real(r8_kind), pointer :: x(:)
real(r8_kind), pointer, contiguous :: tmpptr(:,:)
integer :: shape_d(2)
integer :: i_off, j_off

call mpp_clock_begin(id_get_1_from_xgrid_repro)
shape_d = [xmap%grids(1)%ie_me-xmap%grids(1)%is_me+1, xmap%grids(1)%je_me-xmap%grids(1)%js_me+1]
i_off = xmap%grids(1)%is_me - 1
j_off = xmap%grids(1)%js_me - 1
comm => xmap%get1_repro
!--- pre-post receiving
do p = 1, comm%nrecv
Expand Down Expand Up @@ -4071,25 +4074,25 @@ subroutine get_1_from_xgrid_repro(d_addrs, x_addrs, xmap, xsize, lsize)

do l = 1, lsize
call c_f_pointer(d_addrs(l), tmpptr, shape=shape_d)
d(xmap%grids(1)%is_me:xmap%grids(1)%ie_me, xmap%grids(1)%js_me:xmap%grids(1)%je_me) => tmpptr
d => tmpptr
d = 0
enddo

call mpp_sync_self(check=EVENT_RECV)

!$OMP parallel do default(none) shared(lsize,shape_d,d_addrs,xmap,recv_buffer,pl,ml) &
!$OMP parallel do default(none) shared(lsize,shape_d,d_addrs,xmap,recv_buffer,pl,ml,i_off,j_off) &
!$OMP private(d,tmpptr,grid,i,j,p,pos)
do l = 1, lsize
call c_f_pointer(d_addrs(l), tmpptr, shape=shape_d)
d(xmap%grids(1)%is_me:xmap%grids(1)%ie_me, xmap%grids(1)%js_me:xmap%grids(1)%je_me) => tmpptr
d => tmpptr
do g=2,size(xmap%grids(:))
grid => xmap%grids(g)
do l3=1,grid%size_repro ! index into side1 grid's patterns
i = grid%x_repro(l3)%i1
j = grid%x_repro(l3)%j1
p = grid%x_repro(l3)%pe-xmap%root_pe
pos = pl(p) + (l-1)*ml(p) + grid%x_repro(l3)%recv_pos
d(i,j) = d(i,j) + recv_buffer(pos)
d(i - i_off, j - j_off) = d(i - i_off, j - j_off) + recv_buffer(pos)
end do
end do
! normalize with side 1 grid cell areas
Expand Down