-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/8.5.0' into main
- Loading branch information
Showing
5 changed files
with
77 additions
and
55 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,36 @@ | ||
cmake_minimum_required(VERSION 3.12) | ||
enable_language(Fortran) | ||
################################################################################ | ||
# Configuration step: cmake -S . -B ./build | ||
# Build step: cmake --build ./build -v | ||
# Execution step: mpirun -np 8 ./build/ESMF_HelloWorld | ||
# Clean-up step: rm -rf ./build PET* | ||
################################################################################ | ||
|
||
# Project | ||
project(ESMF_HelloWorld_CMake) | ||
add_executable(ESMF_HelloWorld ESMF_HelloWorld.F90) | ||
cmake_minimum_required(VERSION 3.22) | ||
|
||
# Where to look for Find<Package>.cmake files | ||
# Where to look for the local Find<Package>.cmake files | ||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") | ||
|
||
# Find ESMF | ||
find_package(ESMF REQUIRED) | ||
find_package(ESMF 8.3.0 MODULE REQUIRED) | ||
|
||
# Project depends on ESMF | ||
target_link_libraries(ESMF_HelloWorld ESMF) | ||
# Set compilers consistent with ESMF | ||
set(CMAKE_Fortran_COMPILER "${ESMF_F90COMPILER}") | ||
set(CMAKE_CXX_COMPILER "${ESMF_CXXCOMPILER}") | ||
set(CMAKE_C_COMPILER "${ESMF_CCOMPILER}") | ||
|
||
# Set compilers per ESMFMKFILE | ||
set(CMAKE_CXX_COMPILER ${ESMF_CXXCOMPILER}) | ||
set(CMAKE_Fortran_COMPILER ${ESMF_F90LINKER}) | ||
# Optionally set compiler options consistent with ESMF | ||
set(CMAKE_Fortran_FLAGS "${ESMF_F90COMPILEOPTS}") | ||
set(CMAKE_CXX_FLAGS "${ESMF_CXXCOMPILEOPTS}") | ||
set(CMAKE_C_FLAGS "${ESMF_CCOMPILEOPTS}") | ||
|
||
# Diagnostic output | ||
get_filename_component (Fortran_COMPILER_NAME ${CMAKE_Fortran_COMPILER} NAME) | ||
message("------------------------------------") | ||
message("Fortran compiler: ${CMAKE_Fortran_COMPILER_ID} ${CMAKE_Fortran_COMPILER_VERSION} (${Fortran_COMPILER_NAME})") | ||
message("------------------------------------") | ||
# Project | ||
project(ESMF_HelloWorld_CMake | ||
VERSION 1.0 | ||
LANGUAGES Fortran CXX C | ||
) | ||
|
||
# Executable | ||
add_executable(ESMF_HelloWorld ESMF_HelloWorld.F90) | ||
|
||
# Executable depends on ESMF | ||
target_link_libraries(ESMF_HelloWorld ESMF) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,27 @@ | ||
! Earth System Modeling Framework | ||
! Copyright 2002-2021, University Corporation for Atmospheric Research, | ||
! Copyright (c) 2002-2023, University Corporation for Atmospheric Research, | ||
! Massachusetts Institute of Technology, Geophysical Fluid Dynamics | ||
! Laboratory, University of Michigan, National Centers for Environmental | ||
! Prediction, Los Alamos National Laboratory, Argonne National Laboratory, | ||
! NASA Goddard Space Flight Center. | ||
! Licensed under the University of Illinois-NCSA License. | ||
|
||
program esmf_application | ||
program ESMF_HelloWorld | ||
|
||
! modules | ||
use ESMF | ||
|
||
implicit none | ||
|
||
! local variables | ||
integer:: rc | ||
integer :: rc | ||
|
||
call ESMF_Initialize(rc=rc) | ||
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT) | ||
|
||
print *, "Hello ESMF World" | ||
|
||
call ESMF_Finalize() | ||
|
||
call ESMF_LogWrite(">>> Hello ESMF World <<<", rc=rc) | ||
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT) | ||
|
||
call ESMF_Finalize(rc=rc) | ||
|
||
end program |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
ESMF_HelloWorld_CMake | ||
===================== | ||
|
||
This directory contains code that is based on the ESMF Fortran API. | ||
|
||
The application writes ">>> Hello ESMF World <<<" to the ESMF default log (see PET*.ESMF_LogFile's). | ||
|
||
The main purpose of this example is to demonstrate the use of CMake for ESMF applications. The code is accompanied by `CMakeLists.txt` and `cmake/FindESMF.cmake` files. | ||
|
||
Notice the dependency of the example on a relatively recent release of CMake: version 3.22. This is specified in file `CMakeLists.txt`. The primary reason for this restictive dependency is that not until version 3.22 was it supported to use the `find_package()` and `set()` functions before `project()`. Hence it was more difficult in the older versions to specified the compilers consistent with those used by ESMF. | ||
|
||
Notice that it is possible to get the desired end result with previous versions of CMake, requiring some re-arranging of the order of functions in `CMakeLists.txt`. However, the more recently supported order of functions leads to a simpler and more intuitive version of `CMakeLists.txt` file shown here. | ||
|
||
The code can be built using any of the usual CMake build procedures: | ||
|
||
mkdir build; cd build | ||
cmake .. | ||
make | ||
|
||
or alternatively using the `-S`, `-B`, and `--build` CMake options: | ||
|
||
cmake -S . -B ./build | ||
cmake --build ./build | ||
|
||
And execute on 8 PETs, e.g. via mpirun: | ||
|
||
mpirun -np 8 ./build/ESMF_HelloWorld | ||
|
||
================================================================================ | ||
|
||
Please contact esmf_support@ucar.edu with any questions or problems. | ||
|
||
================================================================================ |
This file contains 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