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 6 commits into
base: develop
Choose a base branch
from

Conversation

natalie-perlin
Copy link
Collaborator

@natalie-perlin natalie-perlin commented Jan 7, 2025

Description:

Updates to build UFS WM on MacOSX platforms, Ventura or Sonoma OS, [email protected], [email protected]
openmpi/5.0.3 (or 4.1.6, tested as well) is built as a part of the spack-stack-1.8.0.

Tested on three MacOS systems:
A: x86_64, Sonoma OS 14.7.2,, XCode 15.4, [email protected], [email protected]
B: M1 , Sonoma OS 14.7.2, XCode 15.4, [email protected], [email protected]
C: (NOAA AWS MacOS instance) M2, Ventura OS 13.6.9, xcode-select command-line tools only; [email protected], [email protected]

Files changed with the options added for MacOS:

  • ./modulefiles/ufs_macosx.gnu.lua (a new file, replacing the old one ufs_macosx.gnu)
  • CMakeList.txt
  • ./tests/compile.sh
  • ./tests/detect_machine.sh
  • ./tests/default_vars.sh
  • ./tests/run_compile.sh
  • ./tests/run_test.sh
  • ./tests/opnReqTest

Running of the UFS-WM was tested as a part of the UFS-SRW App, successfully ran a standard community test. A corresponding PR in the UFS-SRW repo:
ufs-community/ufs-srweather-app#1171

TESTING THE BUILD:
NB: Set the path of your local spack-stack environment location as env. variable stackpath in ./modulefiles/ufs_macosx.gnu.lua, and adjust versions of packages/modules if needed.

  1. Using CMake method, i.e.
    i) load the modulefiles:
module use $PWD/modulefiles
module load ufs_macosx.gnu

ii) set env. variable:
export CMAKE_FLAGS="-DAPP= ... -DCCPP_SUITES="
and
iii) running the ./build.sh script, i.e.: ./build.sh 2>&1 | tee log.build.ufs.001

  1. Using a compile script ./tests/compile.sh, e.g. :
cd ./tests
./compile.sh macosx "-DAPP=S2SWA -DCCPP_SUITES=FV3_GFS_v17_coupled_p8,FV3_GFS_v17_coupled_p8_ugwpv1" s2swa.gnu gnu YES NO 2>&1 | tee  log.ufs.build_s2swa.txt

Log files from MacOS systems, built using ./compile.sh script
System A:
MacA.build_log.s2swa.txt
MacA_compile_s2swa.gnu_time.log.txt
MacA.modules.fv3_s2swa.gnu.lua.txt

System C:
MacC.build_log.s2swa.txt
MacC.compile_s2swa.gnu_time.log.txt
MacC.modules.fv3_s2swa.gnu.lua.txt

Priority:

(TBD)

Git Tracking

No regular testing of UFS-WM on MacOS systems is being done

This PR addresses the issues from #2371,
and uses the solution proposed.

UFSWM Blocking Dependencies:

Uses spack-stack-1.8.0
#2453
except for using mapl-2.40.3-esmf-8.6.0 required for the current ufs-wm build

At the moment, all the modules are loaded in the ufs_macosx.gnu.lua file; ufs_common.lua not used


Changes

Library Changes/Upgrades:

Directions for building spack-stack

Detailed directions to build spack-stack-1.8.0 with the software versions used in this PR:
https://docs.google.com/document/d/1Z0L7eujZGtyeZRzcgguyZPsZpkwb2Om7UhFqQPVtxnE/edit?usp=sharing


Testing Log:

  • RDHPCS
    • Hera
    • Orion
    • Hercules
    • Jet
    • GaeaC5
    • GaeaC6
    • Derecho
  • WCOSS2
    • Dogwood/Cactus
    • Acorn
  • CI
  • opnReqTest (complete task if unnecessary)

build.sh Outdated Show resolved Hide resolved
@jkbk2004
Copy link
Collaborator

jkbk2004 commented Jan 7, 2025

@grantfirl new fv3 hash is NOAA-EMC/fv3atm@7d99880

no changes from develop branch for the build.sh script
@natalie-perlin
Copy link
Collaborator Author

@grantfirl new fv3 hash is NOAA-EMC/fv3atm@7d99880

Successfully tested the build of the code (S2SWA) with the hash 7d99880 on NOAA AWS MacOS instance.

@GeorgeVandenberghe-NOAA
Copy link
Collaborator

@jkbk2004
Copy link
Collaborator

@natalie-perlin do you think you can combine ufs_macosx.gnu into ufs_macosx.gnu.lua? I mean like https://github.com/ufs-community/ufs-weather-model/blob/develop/modulefiles/ufs_wcoss2.intel.lua. Also, some test result or instruction will be helpful for people using mac even in sequential mode.

@DeniseWorthen
Copy link
Collaborator

DeniseWorthen commented Jan 13, 2025

@natalie-perlin I've been able to build on my system (m2, sonoma 14.5) with a few modifications for uwm (instead of srw). I'm having problems actually building w/ the stack though, somewhere in the module loading (?).

I've merged in your branch w/ a few changes like so:

diff --git a/modulefiles/ufs_common.lua b/modulefiles/ufs_common.lua
index 062fa384..63c5b1df 100644
--- a/modulefiles/ufs_common.lua
+++ b/modulefiles/ufs_common.lua
@@ -6,7 +6,7 @@ local ufs_modules = {
   {["jasper"]          = "2.0.32"},
   {["zlib"]            = "1.2.13"},
   {["libpng"]          = "1.6.37"},
-  {["hdf5"]            = "1.14.0"},
+  {["hdf5"]            = "1.14.3"},
   {["netcdf-c"]        = "4.9.2"},
   {["netcdf-fortran"]  = "4.6.1"},
   {["parallelio"]      = "2.5.10"},
diff --git a/modulefiles/ufs_macosx.gnu.lua b/modulefiles/ufs_macosx.gnu.lua
index 62a39b0a..b472c258 100644
--- a/modulefiles/ufs_macosx.gnu.lua
+++ b/modulefiles/ufs_macosx.gnu.lua
@@ -2,7 +2,7 @@ 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")
+prepend_path("MODULEPATH", "/Users/max/spack-stack-1.8.0/envs/uwm.env.mymacos/install/modulefiles/Core")

 stack_gnu_ver=os.getenv("stack_apple_clang_ver") or "15.0.0"
 load(pathJoin("stack-apple-clang", stack_gnu_ver))
@@ -15,9 +15,9 @@ load(pathJoin("cmake", cmake_ver))

 local ufs_modules = {
   {["jasper"]          = "2.0.32"},
-  {["zlib"]            = "1.2.13"},
+  {["zlib-ng"]         = "2.1.6"},
   {["libpng"]          = "1.6.37"},
-  {["hdf5"]            = "1.14.0"},
+  {["hdf5"]            = "1.14.3"},
   {["netcdf-c"]        = "4.9.2"},
   {["netcdf-fortran"]  = "4.6.1"},
   {["parallelio"]      = "2.6.2"},
@@ -28,7 +28,6 @@ local ufs_modules = {
   {["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"},
@@ -56,10 +55,7 @@ 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 "
-  ]===])
-end
+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 ")
+
 whatis("Description: UFS build environment")

Steps to build:

max:~/ufs_on_osx/ufs_dw$ module use modulefiles/
max:~/ufs_on_osx/ufs_dw$ module load ufs_macosx.gnu
max:~/ufs_on_osx/ufs_dw$ module list

Currently Loaded Modules:
  1) stack-apple-clang/15.0.0  12) snappy/1.1.10           23) crtm-fix/2.4.0.1_emc  34) pflogger/1.14.0
  2) pmix/5.0.1                13) zstd/1.5.2              24) git-lfs/3.4.1         35) pigz/2.8
  3) openmpi/5.0.3             14) c-blosc/1.21.5          25) crtm/2.4.0.1          36) tar/1.34
  4) stack-openmpi/5.0.3       15) netcdf-c/4.9.2          26) g2/3.5.1              37) gettext/0.22.5
  5) curl/8.6.0                16) netcdf-fortran/4.6.1    27) g2tmpl/1.13.0         38) libxcrypt/4.4.35
  6) cmake/3.27.9              17) parallel-netcdf/1.12.3  28) ip/5.0.0              39) sqlite/3.43.2
  7) libjpeg/2.1.0             18) parallelio/2.6.2        29) w3emc/2.10.0          40) python/3.11.7
  8) jasper/2.0.32             19) esmf/8.6.0              30) gftl/1.14.0           41) mapl/2.40.3-esmf-8.6.0
  9) zlib-ng/2.1.6             20) llvm-openmp/18.1.0      31) gftl-shared/1.9.0     42) scotch/7.0.4
 10) libpng/1.6.37             21) fms/2024.02             32) fargparse/1.8.0       43) nccmp/1.9.0.1
 11) hdf5/1.14.3               22) bacio/2.4.1             33) yafyaml/1.4.0         44) ufs_macosx.gnu



max:~/ufs_on_osx/ufs_dw$ cd tests
 ./compile.sh macosx  "-DAPP=DATM-WAV -DDEBUG=ON" cdeps.gnu gnu YES NO 2>&1 | tee cdeps.log

Which gives

max:~/ufs_on_osx/ufs_dw/tests$ ./compile.sh macosx  "-DAPP=DATM-WAV -DDEBUG=ON" cdeps.gnu gnu YES NO 2>&1 | tee cdeps.log
+ SECONDS=0
++ realpath ./compile.sh
+ SCRIPT_REALPATH=/Users/max/ufs_on_osx/ufs_dw/tests/compile.sh
++ dirname /Users/max/ufs_on_osx/ufs_dw/tests/compile.sh
+ MYDIR=/Users/max/ufs_on_osx/ufs_dw/tests
+ readonly MYDIR
+ readonly ARGC=6
+ ARGC=6
+ [[ 6 -lt 2 ]]
+ MACHINE_ID=macosx
+ MAKE_OPT='-DAPP=DATM-WAV -DDEBUG=ON'
+ COMPILE_ID=cdeps.gnu
+ RT_COMPILER=gnu
+ clean_before=YES
+ clean_after=NO
+ BUILD_NAME=fv3_cdeps.gnu
++ cd /Users/max/ufs_on_osx/ufs_dw/tests/..
++ pwd
+ PATHTR=/Users/max/ufs_on_osx/ufs_dw
++ pwd
+ BUILD_DIR=/Users/max/ufs_on_osx/ufs_dw/tests/build_fv3_cdeps.gnu
+ [[ macosx == derecho ]]
+ BUILD_JOBS=8
+ set +x
./compile.sh: line 60: /Users/max/ufs_on_osx/ufs_dw/modulefiles/ufs_macosx.gnu: No such file or directory

@DeniseWorthen
Copy link
Collaborator

@natalie-perlin I'm not sure about the thumbs up? Is that for the build vs the actual compile using the build (which is failing)...

@natalie-perlin
Copy link
Collaborator Author

@natalie-perlin I've been able to build on my system (m2, sonoma 14.5) with a few modifications for uwm (instead of srw). I'm having problems actually building w/ the stack though, somewhere in the module loading (?).

./compile.sh: line 60: /Users/max/ufs_on_osx/ufs_dw/modulefiles/ufs_macosx.gnu: No such file or directory

@DeniseWorthen - thank you for testing!..
It looks like the modulefile is expected to be a bash file, not a *lua modulefile. The ./tests/compile.sh does not attempt to the modulefile but to source it instead: has the following:

   macosx|linux)
    source "${PATHTR}/modulefiles/ufs_${MACHINE_ID}.${RT_COMPILER}"

Keeping the ufs_macosx.gnu as a bash file and not converting it to *.lua modulefile (as Jong @jkbk2004 suggested, I think) also solves the issue with environmental variables being available in bash modulefile, but not in *.lua file:
#2551 (comment)
#2551 (comment)

@natalie-perlin
Copy link
Collaborator Author

@natalie-perlin I'm not sure about the thumbs up? Is that for the build vs the actual compile using the build (which is failing)...

... Just acknowledging that I'm looking into the issue!..

@natalie-perlin
Copy link
Collaborator Author

@jkbk2004 , @DeniseWorthen @climbfuji @SamuelTrahanNOAA @DavidHuber-NOAA

So let me test modifying the the *.lua modulefile into the bash file, do the builds on the test systems, upload the logs. It also may not be too hard to prepare and HSD 2020_CAPE test as it uses 8 cpus, a number of cpus available on the two of the three system being tested.

@barlage
Copy link
Collaborator

barlage commented Jan 13, 2025

@natalie-perlin is there a separate issue/discussion on the spack stack 1.8.0 build? I'm not even getting that far on my M3, which I see isn't on the tested platforms, but it is Sonoma 14.7.2 and CLT 15.3. It's failing very early in the zlib build so it's likely I have something not configured correctly. I will try with an M1 and M2 I have at home. Anyway, I don't want to clog up this PR with tangental comments. I also have a few small comments on your spack stack build instructions.

@natalie-perlin
Copy link
Collaborator Author

@natalie-perlin is there a separate issue/discussion on the spack stack 1.8.0 build? I'm not even getting that far on my M3, which I see isn't on the tested platforms, but it is Sonoma 14.7.2 and CLT 15.3. It's failing very early in the zlib build so it's likely I have something not configured correctly. I will try with an M1 and M2 I have at home. Anyway, I don't want to clog up this PR with tangental comments. I also have a few small comments on your spack stack build instructions.

Thanks for the comment on your testing progress! Please note that spack-stack-1.x.0 version is not equivalent to setting specific version/modules to be built, there are still ranges of versions of the packages. It may worth trying to use versions of the packages/modules you've built with the spack-stack-1.7.0, and to set the corresponding path and package versions in ./modulefiles/ufs_macosx.gnu.lua.
Note that other Tier1 machines still use spack-stack-1.6.0 with additional environments and packages (esmf/8.6.0, mapl/2.40.3, fms/2024.01).

Please feel free to comment on the Spack-stack build document and communicate on the issues that may be found on your system.

@natalie-perlin
Copy link
Collaborator Author

@natalie-perlin I've been able to build on my system (m2, sonoma 14.5) with a few modifications for uwm (instead of srw). I'm having problems actually building w/ the stack though, somewhere in the module loading (?).

./compile.sh: line 60: /Users/max/ufs_on_osx/ufs_dw/modulefiles/ufs_macosx.gnu: No such file or directory

@DeniseWorthen - the code has been updated to build the UFS-WM using ./tests/compile.sh script as well.

@DeniseWorthen
Copy link
Collaborator

@natalie-perlin Thanks. I'll test and report back.

@barlage
Copy link
Collaborator

barlage commented Jan 14, 2025

@natalie-perlin I've successfully built spack-stack 1.8.0 on my M3/Sonoma 14.7.2/Xcode 15.4/CLT 15.3 using your instructions, so a "default" build of 1.8.0. This builds with openmpi/5.0.3. I will note that this build has broken some of my other simple workflows that use mpi with some dylib linking issues so I may revert the openmpi version back to something earlier but I'll deal with that later.

For the UFS build, I'm using

module use modulefiles
module load ufs_macosx.gnu.lua
export CMAKE_FLAGS="-DAPP=ATM -D32BIT=ON -DCCPP_SUITES=FV3_GFS_v17_p8"
./build.sh 2>&1 | tee log.build.ufs

with some modifications similar to @DeniseWorthen

diff --git a/modulefiles/ufs_common.lua b/modulefiles/ufs_common.lua
index 062fa384..63c5b1df 100644
--- a/modulefiles/ufs_common.lua
+++ b/modulefiles/ufs_common.lua
@@ -6,7 +6,7 @@ local ufs_modules = {
   {["jasper"]          = "2.0.32"},
   {["zlib"]            = "1.2.13"},
   {["libpng"]          = "1.6.37"},
-  {["hdf5"]            = "1.14.0"},
+  {["hdf5"]            = "1.14.3"},
   {["netcdf-c"]        = "4.9.2"},
   {["netcdf-fortran"]  = "4.6.1"},
   {["parallelio"]      = "2.5.10"},
diff --git a/modulefiles/ufs_macosx.gnu.lua b/modulefiles/ufs_macosx.gnu.lua
index f2f07258..b43e9bc9 100644
--- a/modulefiles/ufs_macosx.gnu.lua
+++ b/modulefiles/ufs_macosx.gnu.lua
@@ -2,14 +2,14 @@ help([[
 loads UFS Model modules for MacOSX 
 ]])
 -- Replace the stackpath below by the path of the local spack-stack environment build:
-local stackpath = "/Users/username/spack-stack/spack-stack-1.8.0/envs/ufs-srw-env"
+local stackpath = "/Users/michael.barlage/packages/spack-stack-1.8.0/envs/ufs-srw-env"
 local modulepath = stackpath .. "/install/modulefiles/Core"
 prepend_path("MODULEPATH", modulepath)
 
 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 "4.1.6"
+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"
@@ -19,7 +19,7 @@ local ufs_modules = {
   {["jasper"]          = "2.0.32"},
   {["zlib"]            = "1.2.13"},
   {["libpng"]          = "1.6.37"},
-  {["hdf5"]            = "1.14.0"},
+  {["hdf5"]            = "1.14.3"},
   {["netcdf-c"]        = "4.9.2"},
   {["netcdf-fortran"]  = "4.6.1"},
   {["parallelio"]      = "2.6.2"},

The model seems to build successfully, but I'm getting the same error as before on my C24 atmo-only test:

[~/data/C24]$ mpirun -np 6 ./ufs_model
* . * . * . * . * . * . * . * . * . * . * . * . * . * . * . * . * . * . * . * . 
     PROGRAM ufs-weather-model HAS BEGUN. COMPILED       0.00     ORG: np23
     STARTING DATE-TIME  JAN 14,2025  13:03:58.556   14  TUE   2460690

Compiler version: GCC version 13.3.0

MPI Library: Open MPI v5.0.3, package: Open MPI Distribution, ident: 5.0.3, repo rev: v5.0.3, Apr 08, 2024 
MPI Version: 3.1
libc++abi: terminating due to uncaught exception of type nlohmann::json_abi_v3_11_2::detail::out_of_range: [json.exception.out_of_range.403] key 'NUOPC' not found
libc++abi: terminating due to uncaught exception of type nlohmann::json_abi_v3_11_2::detail::out_of_range: [json.exception.out_of_range.403] key 'NUOPC' not found

Program received signal SIGABRT: Process abort signal.

Am I still missing something since it seems like the previous discussion resolved this issue? Has that solution not propagated into the UWM repo?

Seems to be linking with CXX:

[ 99%] Built target ufs
Dependee "/Users/michael.barlage/src/models/macos_test/natalie_test/build/CMakeFiles/ufs_model.dir/DependInfo.cmake" is newer than depender "/Users/michael.barlage/src/models/macos_test/natalie_test/build/CMakeFiles/ufs_model.dir/depend.internal".
Dependee "/Users/michael.barlage/src/models/macos_test/natalie_test/build/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/Users/michael.barlage/src/models/macos_test/natalie_test/build/CMakeFiles/ufs_model.dir/depend.internal".
Scanning dependencies of target ufs_model
[100%] Building Fortran object CMakeFiles/ufs_model.dir/driver/UFS.F90.o
[100%] Linking CXX executable ufs_model
[100%] Built target ufs_model

@natalie-perlin
Copy link
Collaborator Author

@barlage - Are you using the older UFS model code, or the code from this PR?..
The runtime error that you are seeing used to be due to the ./ufs-weather-model/CMakeLists.txt using Fortran as a linker language; it needs to be set to CXX for MacOS to link it properly, see: #2371 (comment)

So yes, the previous discussion resolved that issue, but the current PR is the one addresses and implements these changes , in partucular, to the ./ufs-weather-model/CMakeLists.txt
This PR addresses this issue!

@barlage
Copy link
Collaborator

barlage commented Jan 14, 2025

@natalie-perlin I also added to the end of the previous comment, i.e., it looks like the CXX linker is being used.

Here's my set-up:

[~/src/models/macos_test/natalie_test]$ gitb
* dev_macosx 22d5dbc5 [origin/dev_macosx] Merge branch 'develop' into dev_macosx
[~/src/models/macos_test/natalie_test]$ gitr
origin  https://github.com/natalie-perlin/ufs-weather-model.git (fetch)
origin  https://github.com/natalie-perlin/ufs-weather-model.git (push)

@natalie-perlin
Copy link
Collaborator Author

@barlage - It is possible that other additional libraries installed are getting in the way? In contrary to the sequence of errors in #2371 (comment) , there is no need to install llvm_openmp and to use "-DCMAKE_SHARED_LINKER_FLAGS="${llvm_openmp_ROOT}/lib/libomp.dylib" flag.

@natalie-perlin
Copy link
Collaborator Author

@barlage - is there a chance to look at the spack-stack-1.8.0 build log, and at the ufs_model build log (with the BUILD_VERBOSE=1 option), to see the paths and the libraries are being linked against?

@barlage
Copy link
Collaborator

barlage commented Jan 14, 2025

@barlage - It is possible that other additional libraries installed are getting in the way? In contrary to the sequence of errors in #2371 (comment) , there is no need to install llvm_openmp and to use "-DCMAKE_SHARED_LINKER_FLAGS="${llvm_openmp_ROOT}/lib/libomp.dylib" flag.

I did not use any of these previous CMAKE flags.

I'll rebuild ufs_weather_model and upload the build logs.

@natalie-perlin
Copy link
Collaborator Author

Adding the logs from the SRW runs that are based on ATM-only UFS-WM, one machine uses openmpi/4.1.6 , another uses openmpi/5.0.3:

x86_64, Sonoma OS, openmpi/4.1.6: SRW_log.fcst.001.txt
M2, Ventura (NOAA AWS EC2 instance), openmpi/5.0.3:SRW_log.fcst.002.txt

@barlage
Copy link
Collaborator

barlage commented Jan 14, 2025

@barlage - is there a chance to look at the spack-stack-1.8.0 build log, and at the ufs_model build log (with the BUILD_VERBOSE=1 option), to see the paths and the libraries are being linked against?

log.build.ufs.002.txt

The spack-stack build log is too big so I put it here.

@natalie-perlin
Copy link
Collaborator Author

@barlage - is there a chance to look at the spack-stack-1.8.0 build log, and at the ufs_model build log (with the BUILD_VERBOSE=1 option), to see the paths and the libraries are being linked against?

log.build.ufs.002.txt

The spack-stack build log is too big so I put it here.

Thank you!.. Let me look through the logs for any clues.

@natalie-perlin
Copy link
Collaborator Author

@barlage - Thank you for the logs!.. They look totally fine and as expected

I've found a culprit that changes the runtime outcome, it's an additional LDFLAG =" -Wl,-no_compact_unwind" added at a later stage in my testing.

The flag " -Wl,-no_compact_unwind" prevents the ld warnings during the build, but results in the runtime error. If not used for linking, there are several warnings generated, but the ufs_model executable assembled works fine.

There may still be some other compiler/linker flags, other than "-Wl, -no_compact_unwind" to prevent numerous linker warnings, but so far they are not causing any issues during the runtime.
As for the SRW, even if this flag is used, all other binaries except for the ufs_model work fine as well.

Will update my PR momentarily, after a couple of more things to try.

The bottom line, the ufs_macos.gnu.lua should have the following (note there is no ldflags_add variable used):

local libjpeg_ROOT = os.getenv("libjpeg_turbo_ROOT")
local jasper_ROOT = os.getenv("jasper_ROOT")
local libpng_ROOT = os.getenv("libpng_ROOT")
local ldflags0 = os.getenv("LDFLAGS") or ""

if jasper_ROOT and libpng_ROOT and libjpeg_ROOT then
   local ldflags1 = " -L" .. libjpeg_ROOT .. "/lib -ljpeg -Wl,-rpath," .. libjpeg_ROOT .. "/lib"
   local ldflags2 = " -L" .. jasper_ROOT .. "/lib -ljasper -Wl,-rpath," .. jasper_ROOT .. "/lib"
   local ldflags3 = " -L" .. libpng_ROOT .. "/lib -lpng -Wl,-rpath," .. libpng_ROOT .. "/lib"
   local ldflags = ldflags0 .. ldflags_add .. ldflags1 .. ldflags2 .. ldflags3
   setenv("LDFLAGS", ldflags)
end

@GeorgeVandenberghe-NOAA
Copy link
Collaborator

@natalie-perlin
Copy link
Collaborator Author

What does this flag actually do at load time?
-- George W Vandenberghe Lynker Technologies at * NOAA/NWS/NCEP/EMC 5830 University Research Ct., Rm. 2141 College Park, MD 20740 @.** 301-683-3769(work) 3017751547(cell)

The flag "-Wl,-no_compact_unwind " is used during the linking time, or rather it is need not to be used for this case. The info found on error warnings generated at a linking stage when this flag is not used are below. All the issues are related to additional CXX libraries required by the ESMF. Note that all ESMF unit tests all pass successfully as they use mpicxx linker.


The warning: ld: warning: could not create compact unwind
occurs during the linking phase on macOS when the linker (ld) cannot generate compact unwind(*) information for some parts of the code.

(*) Compact unwind information is a data structure used by macOS for efficient stack unwinding during:

  • Exception handling: For languages like C++ or Objective-C that use exceptions.
  • Debugging and profiling: Tools like lldb and Instruments rely on accurate unwind information.
    This compact representation is a space-saving alternative to full unwind tables, allowing the system to perform faster and more efficient stack trace analysis.

Why the Warning Occurs:
The warning indicates that for certain parts of the code, the linker cannot create compact unwind information. This can happen for several reasons:

  • Inline Assembly: If the code includes inline assembly or uses constructs that do not conform to macOS’s calling conventions, the linker might struggle to generate compact unwind data.
  • Unsupported Compiler Options: Certain compiler flags or attributes (e.g., __attribute__((naked))) may prevent the generation of unwind tables.
  • Third-Party Libraries: If you're linking against libraries that lack proper unwind information, the linker may issue this warning.
  • Custom Stack Manipulation: Low-level stack manipulation (e.g., via assembly or setjmp/longjmp) can interfere with unwind generation.
  • Mismatched Architectures: Building for an architecture that doesn't fully support compact unwind (e.g., ARM64 vs. x86_64) may result in this issue.
  • Unusual Linker Behavior: Rare cases in which the linker simply cannot resolve certain code paths for compact unwind generation.

What Are the Consequences?

  • For Most Applications: This warning is usually harmless if you’re not relying on exception handling or stack unwinding in the affected code.
  • For Applications Using Exceptions or Debugging: The lack of compact unwind information could lead to:

-- Crashes or undefined behavior when exceptions are thrown.
-- Inaccurate stack traces in debugging tools.

How to Resolve the Warning
Here are the potential fixes, depending on your project:

  • Disable Compact Unwind Tables: If compact unwind information is unnecessary for your project:
    clang++ -Xlinker -no_compact_unwind -o my_program my_program.cpp
    This suppresses the generation of compact unwind tables and removes the warning.
  • Avoid Inline Assembly: Replace any inline assembly with high-level constructs (or ensure the assembly adheres to macOS ABI conventions).
  • Ensure Proper Compiler and Linker Flags: Use consistent flags like -fexceptions or -funwind-tables for parts of the code that require exception handling. Conversely, use -fno-exceptions and -fno-unwind-tables for parts that don’t.
  • Update Third-Party Libraries: Ensure that all libraries linked in your project are up-to-date and compatible with macOS’s unwind system.
  • Debug Verbosely: Use the -v flag during compilation and linking to identify the specific file or symbol causing the issue: clang++ -v -o my_program my_program.cpp
  • Check for Architecture Compatibility: Ensure that all components (source code, libraries, etc.) are built for the same target architecture.
  • Consult Apple Documentation: For low-level details on compact unwind and ABI requirements, consult Apple's macOS ABI documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants