Skip to content

Commit

Permalink
Merge pull request #1758 from GEOS-ESM/feature/mathomp4/1756-add-farg…
Browse files Browse the repository at this point in the history
…parse

Fixes #1756. Add fArgParse CLI parser
  • Loading branch information
tclune authored Dec 2, 2022
2 parents 7e1c7e8 + da7d37c commit cc1fbb8
Show file tree
Hide file tree
Showing 13 changed files with 770 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ parameters:

# Anchors to prevent forgetting to update a version
os_version: &os_version ubuntu20
baselibs_version: &baselibs_version v7.6.1
baselibs_version: &baselibs_version v7.7.0
bcs_version: &bcs_version v10.23.0
tag_build_arg_name: &tag_build_arg_name maplversion

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
name: Build and Test MAPL GNU
runs-on: ubuntu-latest
container:
image: gmao/ubuntu20-geos-env-mkl:v7.6.1-openmpi_4.1.4-gcc_12.1.0
image: gmao/ubuntu20-geos-env-mkl:v7.7.0-openmpi_4.1.4-gcc_12.1.0
# Per https://github.com/actions/virtual-environments/issues/1445#issuecomment-713861495
# It seems like we might not need secrets on GitHub Actions which is good for forked
# pull requests
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
name: Build and Test MAPL Intel
runs-on: ubuntu-latest
container:
image: gmao/ubuntu20-geos-env:v7.6.1-intelmpi_2021.6.0-intel_2022.1.0
image: gmao/ubuntu20-geos-env:v7.7.0-intelmpi_2021.6.0-intel_2022.1.0
# Per https://github.com/actions/virtual-environments/issues/1445#issuecomment-713861495
# It seems like we might not need secrets on GitHub Actions which is good for forked
# pull requests
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Add fArgParse CLI argument parser
- Added subroutines for reading 4d integers in NetCDF4_FileFormatter
- Added new option to allow for gaps in datasets ingested by ExtDataNG

### Changed

- Updated to ESMA_cmake v3.21.0
- Adds support for a generic `x86_64` processor for GNU
- Updated to ESMA_env v4.7.0
- Baselibs v7.6.0
- fArgParse v1.4.1
- pFUnit v4.6.1
- Move to use GitHub Actions for label enforcement

### Fixed
Expand Down
12 changes: 10 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,16 @@ endif()
if(NOT TARGET GFTL_SHARED::gftl-shared)
find_package(GFTL_SHARED REQUIRED)
endif()
if(NOT TARGET FARGPARSE::fargparse)
find_package(FARGPARSE QUIET)

option(BUILD_WITH_FARGPARSE "Use fArgParse for command line processing" ON)
if(BUILD_WITH_FARGPARSE)
if(NOT TARGET FARGPARSE::fargparse)
find_package(FARGPARSE 1.4.1 REQUIRED)
else()
if (FARGPARSE_VERSION VERSION_LESS 1.4.1)
message(FATAL_ERROR "fArgParse must be at least 1.4.1")
endif ()
endif()
endif()

option(USE_EXTDATA2G "Use ExtData2G" ON)
Expand Down
14 changes: 13 additions & 1 deletion Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ if (BUILD_WITH_FLAP)
endif ()
set_target_properties(ExtDataDriver.x PROPERTIES Fortran_MODULE_DIRECTORY ${MODULE_DIRECTORY})
target_compile_definitions (ExtDataDriver.x PRIVATE $<$<BOOL:${USE_EXTDATA2G}>:BUILD_WITH_EXTDATA2G>)
add_subdirectory(ExtData_Testing_Framework EXCLUDE_FROM_ALL)

ecbuild_add_executable (TARGET pfio_MAPL_demo.x SOURCES pfio_MAPL_demo.F90)
target_link_libraries (pfio_MAPL_demo.x PRIVATE MAPL FLAP::FLAP esmf)
Expand All @@ -26,6 +27,17 @@ if (BUILD_WITH_FLAP)
target_link_libraries(pfio_MAPL_demo.x PRIVATE OpenMP::OpenMP_Fortran)
endif ()
set_target_properties(pfio_MAPL_demo.x PROPERTIES Fortran_MODULE_DIRECTORY ${MODULE_DIRECTORY})
add_subdirectory(ExtData_Testing_Framework EXCLUDE_FROM_ALL)

endif ()

if (BUILD_WITH_FARGPARSE)

ecbuild_add_executable (TARGET MAPL_demo_fargparse.x SOURCES MAPL_demo_fargparse.F90)
target_link_libraries (MAPL_demo_fargparse.x PRIVATE MAPL FARGPARSE::fargparse esmf)
# CMake has an OpenMP issue with NAG Fortran: https://gitlab.kitware.com/cmake/cmake/-/issues/21280
if (NOT CMAKE_Fortran_COMPILER_ID MATCHES "NAG")
target_link_libraries(MAPL_demo_fargparse.x PRIVATE OpenMP::OpenMP_Fortran)
endif ()
set_target_properties(MAPL_demo_fargparse.x PROPERTIES Fortran_MODULE_DIRECTORY ${MODULE_DIRECTORY})

endif ()
80 changes: 80 additions & 0 deletions Tests/MAPL_demo_fargparse.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
!------------------------------------------------------------------------------
!># Standalone Program for Testing fargparse
!
!------------------------------------------------------------------------------
#define I_AM_MAIN
#include "MAPL_ErrLog.h"
#include "unused_dummy.H"

program main
use MAPL
use mpi
use fargparse

implicit none

type(MAPL_FargparseCLI) :: cli
type(MAPL_CapOptions) :: cap_options
integer :: status

!------------------------------------------------------------------------------

call run(_RC)

contains

#undef I_AM_MAIN
#include "MAPL_ErrLog.h"
subroutine run(rc)

integer, intent(out), optional :: rc

integer :: status
character(len=:), allocatable :: input_file

call MPI_Init(status)
_VERIFY(status)

! Read and parse the command line, and set parameters
! If you have extra options you make a procedure as seen below and add arguments
! there and pass in here
cli = MAPL_FargparseCLI(extra=extra_options)

! This does the casting of arguments into cap_options for CAP
cap_options = MAPL_CapOptions(cli, _RC)

write(*,*) "done with MAPL_FargparseCLI"
write(*,*) " cap_options%with_esmf_moab = ", cap_options%with_esmf_moab
write(*,*) " cap_options%npes_input_server = ", cap_options%npes_input_server
write(*,*) " cap_options%nodes_input_server = ", cap_options%nodes_input_server
write(*,*) " cap_options%npes_output_server = ", cap_options%npes_output_server
write(*,*) " cap_options%nodes_output_server = ", cap_options%nodes_output_server
write(*,*) " cap_options%egress_file = ", cap_options%egress_file

! For our extra options we have to explicitly cast them
call cast(cli%options%at('file'), input_file, _RC)

write(*,*) ""
write(*,*) "Extra arguments"
write(*,*) " input file = ", input_file

_RETURN(_SUCCESS)

end subroutine run

subroutine extra_options(parser, rc)
type (ArgParser), intent(inout) :: parser
integer, intent(out), optional :: rc

call parser%add_argument('-f', '--file', &
help='A file to read', &
type='string', &
default='default.config', &
action='store')

!_RETURN(_SUCCESS)
if (present(rc)) rc = 0

end subroutine extra_options

end program main
61 changes: 33 additions & 28 deletions base/tests/test_sort.pf
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
@test
subroutine test_mapl_sort
module test_sort
use pfunit
use mapl_sortMod
use iso_fortran_env, only: INT32, INT64
implicit none

integer(kind=INT64) :: a(5), c(5)
integer(kind=INT32) :: a4(5)
integer(kind=INT32) :: b1(5,3), b2(3,5)
integer(kind=INT32) :: d1(5,3)

integer :: i, j

a = [5,3,8,6,-7]
do j=1,3
b1(:,j) = a
b2(j,:) = a
enddo
a4 = a


C=A
d1=b1
call MAPL_SORT(C,d1,dim=1)

do j=1,3
do i = 2, size(d1,dim=1)
@assertTrue(d1(i-1,j) <= d1(i,j))

contains

@test
subroutine test_mapl_sort
implicit none

integer(kind=INT64) :: a(5), c(5)
integer(kind=INT32) :: a4(5)
integer(kind=INT32) :: b1(5,3), b2(3,5)
integer(kind=INT32) :: d1(5,3)

integer :: i, j

a = [5,3,8,6,-7]
do j=1,3
b1(:,j) = a
b2(j,:) = a
enddo
a4 = a


C=A
d1=b1
call MAPL_SORT(C,d1,dim=1)

do j=1,3
do i = 2, size(d1,dim=1)
@assertTrue(d1(i-1,j) <= d1(i,j))
end do
end do
end do

end subroutine test_mapl_sort
end subroutine test_mapl_sort

end module test_sort
6 changes: 3 additions & 3 deletions components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ MAPL:
ESMA_env:
local: ./ESMA_env
remote: ../ESMA_env.git
tag: v4.7.0
tag: v4.8.0
develop: main

ESMA_cmake:
local: ./ESMA_cmake
remote: ../ESMA_cmake.git
tag: v3.20.0
tag: v3.21.0
develop: develop

ecbuild:
local: ./ESMA_cmake/ecbuild
remote: ../ecbuild.git
tag: geos/v1.2.0
tag: geos/v1.3.0
7 changes: 6 additions & 1 deletion gridcomps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ esma_add_library (${this}
SRCS MAPL_GridComps.F90
DEPENDENCIES MAPL.base MAPL.pfio MAPL_cfio_r4 MAPL.cap
$<$<BOOL:${BUILD_WITH_FLAP}>:FLAP::FLAP>
TYPE ${MAPL_LIBRARY_TYPE}
$<$<BOOL:${BUILD_WITH_FARGPARSE}>:FARGPARSE::fargparse>
TYPE ${MAPL_LIBRARY_TYPE}
)

target_include_directories (${this} PUBLIC
Expand All @@ -12,6 +13,10 @@ if (BUILD_WITH_FLAP)
target_link_libraries(${this} PRIVATE FLAP::FLAP)
target_compile_definitions (${this} PRIVATE USE_FLAP)
endif()
if (BUILD_WITH_FARGPARSE)
target_link_libraries(${this} PRIVATE FARGPARSE::fargparse)
target_compile_definitions (${this} PRIVATE USE_FARGPARSE)
endif()

add_subdirectory(Cap)
add_subdirectory(History)
Expand Down
8 changes: 6 additions & 2 deletions gridcomps/Cap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ set (srcs
if (BUILD_WITH_FLAP)
list (APPEND srcs FlapCLI.F90)
endif()
if (BUILD_WITH_FARGPARSE)
list (APPEND srcs FargparseCLI.F90)
endif()


esma_add_library (${this} SRCS ${srcs} DEPENDENCIES MAPL.shared MAPL.constants MAPL.base MAPL.profiler MAPL.history
MAPL.ExtData ${EXTDATA2G_TARGET} TYPE ${MAPL_LIBRARY_TYPE})
target_link_libraries (${this} PUBLIC GFTL::gftl GFTL_SHARED::gftl-shared esmf NetCDF::NetCDF_Fortran
PRIVATE MPI::MPI_Fortran $<$<BOOL:${BUILD_WITH_FLAP}>:FLAP::FLAP>)
PRIVATE MPI::MPI_Fortran
$<$<BOOL:${BUILD_WITH_FLAP}>:FLAP::FLAP>
$<$<BOOL:${BUILD_WITH_FARGPARSE}>:FARGPARSE::fargparse>)

target_compile_definitions (${this} PRIVATE $<$<BOOL:${USE_EXTDATA2G}>:BUILD_WITH_EXTDATA2G>)

Expand All @@ -24,7 +29,6 @@ if (NOT CMAKE_Fortran_COMPILER_ID MATCHES "NAG")
endif ()
target_include_directories (${this} PUBLIC $<BUILD_INTERFACE:${MAPL_SOURCE_DIR}/include>)
if (BUILD_WITH_FLAP)
target_link_libraries(${this} PRIVATE FLAP::FLAP)
target_compile_definitions (${this} PRIVATE USE_FLAP)
endif()

Expand Down
4 changes: 2 additions & 2 deletions gridcomps/Cap/CapOptions.F90
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module mapl_CapOptionsMod
! whether or not the nodes are padding with idle when mod(model total npes , each node npes) /=0
logical :: isolate_nodes = .true.
! whether or not copy the data before isend to the oserver
! it is faster but demands more memory if it is true
! it is faster but demands more memory if it is true
logical :: fast_oclient = .false.
! whether or not turn on the io profiler
logical :: with_io_profiler = .false.
Expand Down Expand Up @@ -59,7 +59,7 @@ function new_CapOptions(unusable, cap_rc_file, egress_file, ensemble_subdir_pref
class (KeywordEnforcer), optional, intent(in) :: unusable
character(*), optional, intent(in) :: cap_rc_file
character(*), optional, intent(in) :: egress_file
character(*), optional, intent(in) :: ensemble_subdir_prefix
character(*), optional, intent(in) :: ensemble_subdir_prefix
type(ESMF_LogKind_Flag), optional, intent(in) :: esmf_logging_mode

integer, optional, intent(out) :: rc
Expand Down
Loading

0 comments on commit cc1fbb8

Please sign in to comment.