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

Changes to build UFS-WM on MacOS platform with clang@15/[email protected] #2551

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export FC=${FC:-mpif90}
BUILD_DIR=${BUILD_DIR:-${UFS_MODEL_DIR}/build}
mkdir -p "${BUILD_DIR}"

if [[ "$(uname -s)" == "Darwin" ]]; then
gsed -i'.backup' "s:LINKER_LANGUAGE Fortran:LINKER_LANGUAGE CXX:" ./CMakeLists.txt
fi

natalie-perlin marked this conversation as resolved.
Show resolved Hide resolved
cd "${BUILD_DIR}"
ARR_CMAKE_FLAGS=()
for i in ${CMAKE_FLAGS}; do ARR_CMAKE_FLAGS+=("${i}") ; done
Expand Down
24 changes: 0 additions & 24 deletions modulefiles/ufs_macosx.gnu

This file was deleted.

65 changes: 65 additions & 0 deletions modulefiles/ufs_macosx.gnu.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
help([[
loads UFS Model prerequisites for MacOS clang/gcc ("gnu")
]])

prepend_path("MODULEPATH", "/Users/username/spack-stack/spack-stack-1.8.0/envs/ufs-srw-env/install/modulefiles/Core")

stack_gnu_ver=os.getenv("stack_apple_clang_ver") or "15.0.0"
load(pathJoin("stack-apple-clang", stack_gnu_ver))

stack_openmpi_ver=os.getenv("stack_openmpi_ver") or "5.0.3"
load(pathJoin("stack-openmpi", stack_openmpi_ver))

cmake_ver=os.getenv("cmake_ver") or "3.27.9"
load(pathJoin("cmake", cmake_ver))

local ufs_modules = {
{["jasper"] = "2.0.32"},
{["zlib"] = "1.2.13"},
{["libpng"] = "1.6.37"},
{["hdf5"] = "1.14.0"},
{["netcdf-c"] = "4.9.2"},
{["netcdf-fortran"] = "4.6.1"},
{["parallelio"] = "2.6.2"},
{["esmf"] = "8.6.0"},
{["fms"] = "2024.02"},
{["bacio"] = "2.4.1"},
{["crtm"] = "2.4.0.1"},
{["g2"] = "3.5.1"},
{["g2tmpl"] = "1.13.0"},
{["ip"] = "5.0.0"},
{["sp"] = "2.5.0"},
{["w3emc"] = "2.10.0"},
{["gftl-shared"] = "1.9.0"},
{["mapl"] = "2.40.3-esmf-8.6.0"},
{["scotch"] = "7.0.4"},
}

for i = 1, #ufs_modules do
for name, default_version in pairs(ufs_modules[i]) do
local env_version_name = string.gsub(name, "-", "_") .. "_ver"
load(pathJoin(name, os.getenv(env_version_name) or default_version))
end
end

nccmp_ver=os.getenv("nccmp_ver") or "1.9.0.1"
load(pathJoin("nccmp", nccmp_ver))

setenv("CC", "mpicc")
setenv("CXX", "mpicxx")
setenv("FC", "mpifort")
setenv("CMAKE_Platform", "macosx.gnu")
setenv("CMAKE_Fortran_COMPILER_ID", "GNU")

osx_sysroot=os.getenv("OSX_SYSROOT")
setenv("CMAKE_OSX_SYSROOT","OSX_SYSROOT")

setenv("CFLAGS"," -Wno-implicit-function-declaration ")

if mode() == "load" then
LmodMsgRaw([===[
Please export these env. variables after the module is successfully loaded:
> export LDFLAGS+=" -L${libjpeg_turbo_ROOT}/lib -ljpeg -Wl,-rpath,$libjpeg_turbo_ROOT}/lib -L${jasper_ROOT}/lib -ljasper -Wl,-rpath,${jasper_ROOT}/lib -L${libpng_ROOT}/lib -lpng -Wl,-rpath,${libpng_ROOT}/lib "
Copy link
Collaborator

Choose a reason for hiding this comment

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

This seems like a hack to me. Can't this be done in the modulefile?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@climbfuji - it seems that @DavidHuber-NOAA found a great solution (below in a comment) that worked seamlessly!.. Will update the branch with that approach.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops, that was preliminary, the env. variables ${libjpeg_turbo_ROOT}, ${jasper_ROOT}, ${libpng_ROOT} do not expand into full paths during the build... so getting linking issues.
The is is that these variables are not available when the Lmod file is being evaluated - this is a specifics of the Lmod. It is evaluated first before being executed/loaded.
I will attempt to find some other solutions, but so far other solutions appear to be cumbersome.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You're missing a { here. The $libjpeg_turbo_ROOT} should be ${libjpeg_turbo_ROOT}
Without that, it would fail with a syntax error.
How did you test this?

]===])
Comment on lines +59 to +63
Copy link
Collaborator

Choose a reason for hiding this comment

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

Untested, but something like this should work:

Suggested change
if mode() == "load" then
LmodMsgRaw([===[
Please export these env. variables after the module is successfully loaded:
> export LDFLAGS+=" -L${libjpeg_turbo_ROOT}/lib -ljpeg -Wl,-rpath,$libjpeg_turbo_ROOT}/lib -L${jasper_ROOT}/lib -ljasper -Wl,-rpath,${jasper_ROOT}/lib -L${libpng_ROOT}/lib -lpng -Wl,-rpath,${libpng_ROOT}/lib "
]===])
local ldflags=os.getenv("LDFLAGS") or ""
setenv("LDFLAGS", ldflags .. " -L${libjpeg_turbo_ROOT}/lib -ljpeg -Wl,-rpath,$libjpeg_turbo_ROOT}/lib -L${jasper_ROOT}/lib -ljasper -Wl,-rpath,${jasper_ROOT}/lib -L${libpng_ROOT}/lib -lpng -Wl,-rpath,${libpng_ROOT}/lib ")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

end
whatis("Description: UFS build environment")
Loading