ralna / GALAHAD

A library of modern Fortran modules for nonlinear optimization
https://www.galahad.rl.ac.uk
Other
115 stars 15 forks source link

Build error on Apple M1 Max with gcc/g++/ifort #148

Closed dpo closed 9 months ago

dpo commented 1 year ago

I installed the Intel binaries for hwloc and made sure to unlink the aarch64 version so meson does not accidentally pick it up. I did the same for pkg-config. I also made sure to use the Intel version of gcc/g++-13:

~/dev/ralna/GALAHAD master *3 ?9 ❯ CC=/usr/local/bin/gcc-13 CXX=/usr/local/bin/g++-13 FC=ifort meson setup builddir_intel -Dciface=true
The Meson build system
Version: 1.1.1
Source dir: /Users/dpo/dev/ralna/GALAHAD
Build dir: /Users/dpo/dev/ralna/GALAHAD/builddir_intel
Build type: native build
Project name: GALAHAD
Project version: 5.0.0
Fortran compiler for the host machine: ifort (intel 2021.9.0 "ifort (IFORT) 2021.9.0 20230302")
Fortran linker for the host machine: ifort ld64 857.1
C compiler for the host machine: /usr/local/bin/gcc-13 (gcc 13.1.0 "gcc-13 (Homebrew GCC 13.1.0) 13.1.0")
C linker for the host machine: /usr/local/bin/gcc-13 ld64 857.1
C++ compiler for the host machine: /usr/local/bin/g++-13 (gcc 13.1.0 "g++-13 (Homebrew GCC 13.1.0) 13.1.0")
C++ linker for the host machine: /usr/local/bin/g++-13 ld64 857.1
Host machine cpu family: aarch64
Host machine cpu: aarch64
Program ifort found: YES (/opt/intel/oneapi/compiler/2023.1.0/mac/bin/intel64/ifort)
Library openblas found: NO
Library openblas found: NO
Library metis found: NO
Library hsl found: NO
Library cutest found: NO
Library wsmp found: NO
Library umfpack found: NO
Library pardiso found: NO
Library spmf found: NO
Library pastix found: NO
Library smumps found: NO
Library dmumps found: NO
Library mkl_rt found: YES
Library ampl found: NO
Library m found: YES
mpiifort found: NO
Run-time dependency MPI for fortran found: NO (tried config-tool and system)
Found pkg-config: /usr/local/bin/pkg-config (0.29.2)
Run-time dependency hwloc found: YES 2.9.1
src/lapack/meson.build:4: WARNING: building our own BLAS; consider providing an optimized BLAS library
src/lapack/meson.build:9: WARNING: building our own LAPACK; consider providing an optimized LAPACK library
Build targets in project: 591

GALAHAD 5.0.0

  User defined options
    ciface: true

Found ninja-1.11.1 at /opt/homebrew/bin/ninja

Note the lines

Found pkg-config: /usr/local/bin/pkg-config (0.29.2)
Run-time dependency hwloc found: YES 2.9.1

Looking through build.ninja confirms that the Intel version of hwloc is picked up. Here's build.ninja.

Running ~/dev/ralna/GALAHAD master *3 ?9 ❯ meson compile -C builddir_intel results in

[707/2601] Linking target libgalahad_single.dylib
FAILED: libgalahad_single.dylib

...

Undefined symbols for architecture x86_64:
  "__ZSt20__throw_length_errorPKc", referenced from:
      __ZNSt6vectorIP9hwloc_objSaIS1_EE7reserveEm in src_spral_guess_topology.cxx.o
      __ZNKSt6vectorIP9hwloc_objSaIS1_EE12_M_check_lenEmPKc in src_spral_guess_topology.cxx.o
      __ZNSt6vectorIiN5spral5ssids3cpu14BuddyAllocatorIiSaIfEEEE17_S_check_init_lenEmRKS5_ in src_ssids_ldlt_app.cxx.o
      __ZNSt6vectorIfN5spral5ssids3cpu14BuddyAllocatorIfSaIfEEEE17_S_check_init_lenEmRKS5_ in src_ssids_ldlt_app.cxx.o
      __ZNKSt6vectorIN5spral5ssids3cpu20buddy_alloc_internal4PageISaIcEEESaIS6_EE12_M_check_lenEmPKc in src_ssids_ldlt_app.cxx.o
      __ZNSt6vectorIN5spral5ssids3cpu11NumericNodeIfNS2_14BuddyAllocatorIfSaIfEEEEESaIS7_EE7reserveEm in src_ssids_NumericSubtree.cxx.o
      __ZNSt6vectorIN5spral5ssids3cpu9WorkspaceESaIS3_EE7reserveEm in src_ssids_NumericSubtree.cxx.o
      ...
  "__ZSt28__throw_bad_array_new_lengthv", referenced from:
      __ZNSt15__new_allocatorIP9hwloc_objE8allocateEmPKv in src_spral_guess_topology.cxx.o
      __ZNSt15__new_allocatorIN5spral5ssids3cpu20buddy_alloc_internal4PageISaIcEEEE8allocateEmPKv in src_ssids_ldlt_app.cxx.o
      __ZNSt15__new_allocatorIiE8allocateEmPKv in src_ssids_ldlt_app.cxx.o
      __ZNSt15__new_allocatorIiE8allocateEmPKv in src_ssids_NumericSubtree.cxx.o
      __ZNSt15__new_allocatorIN5spral5ssids3cpu11NumericNodeIfNS2_14BuddyAllocatorIfSaIfEEEEEE8allocateEmPKv in src_ssids_NumericSubtree.cxx.o
      __ZNSt15__new_allocatorIN5spral5ssids3cpu9WorkspaceEE8allocateEmPKv in src_ssids_NumericSubtree.cxx.o
      __ZNSt15__new_allocatorIN5spral5ssids3cpu11ThreadStatsEE8allocateEmPKv in src_ssids_NumericSubtree.cxx.o
      ...
ld: symbol(s) not found for architecture x86_64

I notice messages of the form

ld: warning: dylib (/usr/local/Cellar/hwloc/2.9.1/lib/libhwloc.dylib) was built for newer macOS version (13.0) than being linked (10.16)

Looking through meson-log.txt, it looks like it wants to build for aarch64 for a reason that's unclear to me at this time.

I tried adding LDFLAGS='-arch x86_64' to the setup step, but with no success. It looks like meson uses ifort as linker anyways.

Finally, I also tried installing meson/ninja/python3 for Intel and unlinking the aarch64 versions, but the result is the same.

Perhaps this architecture is hopeless.

nimgould commented 1 year ago

From the wilds of South Devon... there is a preprocessing variable (hwloc?? Sorry no code access here) that you can turn off, might be worth a try?

Sent from Outlook for Androidhttps://aka.ms/AAb9ysg


From: Dominique @.> Sent: Monday, June 26, 2023 7:31:08 PM To: ralna/GALAHAD @.> Cc: Subscribed @.***> Subject: [ralna/GALAHAD] Build error on Apple M1 Max with gcc/g++/ifort (Issue #148)

I installed the Intel binaries for hwloc and made sure to unlink the aarch64 version so meson does not accidentally pick it up. I did the same for pkg-config. I also made sure to use the Intel version of gcc/g++-13:

~/dev/ralna/GALAHAD master *3 ?9 ❯ CC=/usr/local/bin/gcc-13 CXX=/usr/local/bin/g++-13 FC=ifort meson setup builddir_intel -Dciface=true The Meson build system Version: 1.1.1 Source dir: /Users/dpo/dev/ralna/GALAHAD Build dir: /Users/dpo/dev/ralna/GALAHAD/builddir_intel Build type: native build Project name: GALAHAD Project version: 5.0.0 Fortran compiler for the host machine: ifort (intel 2021.9.0 "ifort (IFORT) 2021.9.0 20230302") Fortran linker for the host machine: ifort ld64 857.1 C compiler for the host machine: /usr/local/bin/gcc-13 (gcc 13.1.0 "gcc-13 (Homebrew GCC 13.1.0) 13.1.0") C linker for the host machine: /usr/local/bin/gcc-13 ld64 857.1 C++ compiler for the host machine: /usr/local/bin/g++-13 (gcc 13.1.0 "g++-13 (Homebrew GCC 13.1.0) 13.1.0") C++ linker for the host machine: /usr/local/bin/g++-13 ld64 857.1 Host machine cpu family: aarch64 Host machine cpu: aarch64 Program ifort found: YES (/opt/intel/oneapi/compiler/2023.1.0/mac/bin/intel64/ifort) Library openblas found: NO Library openblas found: NO Library metis found: NO Library hsl found: NO Library cutest found: NO Library wsmp found: NO Library umfpack found: NO Library pardiso found: NO Library spmf found: NO Library pastix found: NO Library smumps found: NO Library dmumps found: NO Library mkl_rt found: YES Library ampl found: NO Library m found: YES mpiifort found: NO Run-time dependency MPI for fortran found: NO (tried config-tool and system) Found pkg-config: /usr/local/bin/pkg-config (0.29.2) Run-time dependency hwloc found: YES 2.9.1 src/lapack/meson.build:4: WARNING: building our own BLAS; consider providing an optimized BLAS library src/lapack/meson.build:9: WARNING: building our own LAPACK; consider providing an optimized LAPACK library Build targets in project: 591

GALAHAD 5.0.0

User defined options ciface: true

Found ninja-1.11.1 at /opt/homebrew/bin/ninja

Note the lines

Found pkg-config: /usr/local/bin/pkg-config (0.29.2) Run-time dependency hwloc found: YES 2.9.1

Looking through build.ninja confirms that the Intel version of hwloc is picked up. Here's build.ninjahttps://gist.github.com/dpo/f94a1dfde515dcee0d63e3bc492e03c0.

Running ~/dev/ralna/GALAHAD master *3 ?9 ❯ meson compile -C builddir_intel results in

[707/2601] Linking target libgalahad_single.dylib FAILED: libgalahad_single.dylib

...

Undefined symbols for architecture x86_64: "ZSt20throw_length_errorPKc", referenced from: ZNSt6vectorIP9hwloc_objSaIS1_EE7reserveEm in src_spral_guess_topology.cxx.o ZNKSt6vectorIP9hwloc_objSaIS1_EE12_M_check_lenEmPKc in src_spral_guess_topology.cxx.o ZNSt6vectorIiN5spral5ssids3cpu14BuddyAllocatorIiSaIfEEEE17_S_check_initlenEmRKS5 in src_ssids_ldlt_app.cxx.o ZNSt6vectorIfN5spral5ssids3cpu14BuddyAllocatorIfSaIfEEEE17_S_check_initlenEmRKS5 in src_ssids_ldlt_app.cxx.o ZNKSt6vectorIN5spral5ssids3cpu20buddy_alloc_internal4PageISaIcEEESaIS6_EE12_M_check_lenEmPKc in src_ssids_ldlt_app.cxx.o ZNSt6vectorIN5spral5ssids3cpu11NumericNodeIfNS2_14BuddyAllocatorIfSaIfEEEEESaIS7_EE7reserveEm in src_ssids_NumericSubtree.cxx.o ZNSt6vectorIN5spral5ssids3cpu9WorkspaceESaIS3_EE7reserveEm in src_ssids_NumericSubtree.cxx.o ... "ZSt28throw_bad_array_new_lengthv", referenced from: ZNSt15new_allocatorIP9hwloc_objE8allocateEmPKv in src_spral_guess_topology.cxx.o ZNSt15new_allocatorIN5spral5ssids3cpu20buddy_alloc_internal4PageISaIcEEEE8allocateEmPKv in src_ssids_ldlt_app.cxx.o ZNSt15new_allocatorIiE8allocateEmPKv in src_ssids_ldlt_app.cxx.o ZNSt15new_allocatorIiE8allocateEmPKv in src_ssids_NumericSubtree.cxx.o ZNSt15new_allocatorIN5spral5ssids3cpu11NumericNodeIfNS2_14BuddyAllocatorIfSaIfEEEEEE8allocateEmPKv in src_ssids_NumericSubtree.cxx.o ZNSt15new_allocatorIN5spral5ssids3cpu9WorkspaceEE8allocateEmPKv in src_ssids_NumericSubtree.cxx.o ZNSt15__new_allocatorIN5spral5ssids3cpu11ThreadStatsEE8allocateEmPKv in src_ssids_NumericSubtree.cxx.o ... ld: symbol(s) not found for architecture x86_64

I notice messages of the form

ld: warning: dylib (/usr/local/Cellar/hwloc/2.9.1/lib/libhwloc.dylib) was built for newer macOS version (13.0) than being linked (10.16)

Looking through meson-log.txthttps://gist.github.com/dpo/6700d3aeeb388ab11738a8951454a23a, it looks like it wants to build for aarch64 for a reason that's unclear to me at this time.

I tried adding LDFLAGS='-arch x86_64' to the setup step, but with no success. It looks like meson uses ifort as linker anyways.

Finally, I also tried installing meson/ninja/python3 for Intel and unlinking the aarch64 versions, but the result is the same.

Perhaps this architecture is hopeless.

— Reply to this email directly, view it on GitHubhttps://github.com/ralna/GALAHAD/issues/148, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACW4A6XFBPTVDK4TSQ5MI2TXNHIOZANCNFSM6AAAAAAZURH4HA. You are receiving this because you are subscribed to this thread.Message ID: @.***>

amontoison commented 1 year ago

In the main meson.build, I added (lines 165--169):

if libhwloc.found()
  extra_args += '-DSPRAL_HAVE_HWLOC'
else
  extra_args += '-DSPRAL_NO_HWLOC'
endif

Maybe the support of hwloc is incomplete on Mac? If it's the case we do something like this:

host_system = host_machine.system()
if libhwloc.found() and host_system != 'darwin'
  extra_args += '-DSPRAL_HAVE_HWLOC'
else
  extra_args += '-DSPRAL_NO_HWLOC'
endif
amontoison commented 9 months ago

We can compile GALAHAD on Mac with Intel compilers now.

CC=icc CXX=icpc FC=ifort meson setup builddir -Dssids=false

I close the issue.