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

Cflags in openblas.pc are not compatible with Apple Clang #209091

Closed
4 tasks done
dimpase opened this issue Feb 27, 2025 · 24 comments
Closed
4 tasks done

Cflags in openblas.pc are not compatible with Apple Clang #209091

dimpase opened this issue Feb 27, 2025 · 24 comments

Comments

@dimpase
Copy link
Contributor

dimpase commented Feb 27, 2025

brew gist-logs <formula> link OR brew config AND brew doctor output

HOMEBREW_VERSION: >=4.3.0 (shallow or no git repository)
ORIGIN: (none)
HEAD: (none)
Last commit: never
Branch: (none)
Core tap JSON: 01 Nov 13:19 UTC
Core cask tap JSON: 01 Feb 22:25 UTC
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 10
Homebrew Ruby: 3.3.7 => /opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.3.7/bin/ruby
CPU: deca-core 64-bit arm_firestorm_icestorm
Clang: 16.0.0 build 1600
Git: 2.39.5 => /Library/Developer/CommandLineTools/usr/bin/git
Curl: 8.7.1 => /usr/bin/curl
macOS: 15.3.1-arm64
CLT: 16.2.0.0.1.1733547573
Xcode: 16.1
Rosetta 2: false

(I'm not root on the machine, so I can't meaningfully run brew doctor)
I asked a root for the output of brew gist-logs openblas, still waiting.

EDIT: the root replied with

% brew gist-logs openblas
> Error: No logs.

Verification

  • My brew doctor output says Your system is ready to brew. and am still able to reproduce my issue.
  • I ran brew update and am still able to reproduce my issue.
  • I have resolved all warnings from brew doctor and that did not fix my problem.
  • I searched for recent similar issues at https://github.com/Homebrew/homebrew-core/issues?q=is%3Aissue and found no duplicates.

What were you trying to do (and why)?

I am trying to use Homebrew's openblas with XCode C compiler, Apple's clang:

Apple clang version 16.0.0 (clang-1600.0.26.6)
Target: arm64-apple-darwin24.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Openblas is located in /opt/homebrew/Cellar/openblas/0.3.29/ and its openblas.pc produces the following CFLAGS:

% PKG_CONFIG_PATH="/opt/homebrew/Cellar/openblas/0.3.29/lib/pkgconfig"  pkg-config -cflags openblas 
-I/opt/homebrew/Cellar/openblas/0.3.29/include -fopenmp

Such flags are not accepted by Apple's clang.
Specifically, on gets:

% clang -c foobar.c -fopenmp
   clang: error: unsupported option '-fopenmp'

The correct format for the OpenMP option is -Xclang -fopenmp,
as can be checked directly, or read on the R Project website: https://mac.r-project.org/openmp/

Thus, openblas.pc has to be fixed, but it's probably only opening a can of worms, as I have no idea whether
libgomp, against which libopenblas is linked, is compatible with Apple clang's support of OpenMP.

What happened (include all command output)?

% export PKG_CONFIG_PATH="/opt/homebrew/Cellar/openblas/0.3.29/lib/pkgconfig"
% clang -c foobar.c  `pkg-config -cflags openblas`

      clang: error: unsupported option '-fopenmp'

What did you expect to happen?

It should work.

Step-by-step reproduction instructions (by running brew commands)

let `foobar.c` contain valid C code.

brew install openblas
export PKG_CONFIG_PATH=<path to libopenblas.dylib location>/pkgconfig
clang -c foobar.c  `pkg-config -cflags openblas`


One needs a recent XCode on arm64 (I tested on M1, other people tell me that on M4 it's the same).
@SMillerDev
Copy link
Member

Homebrew only runs make for openblas, so if something is generated wrong there it should be reported upstream to be fixed.

@carlocab
Copy link
Member

This is probably a consequence of our using GCC to build on macOS. Using -Xclang -fopenmp won't work for GCC, of course. Not convinced upstream will want to do anything about this (or that they even can).

@dimpase
Copy link
Contributor Author

dimpase commented Feb 27, 2025

Upstream doesn't seem to be aware of a possibility to use -Xclang -fopenmp, there is nothing in their repo or github that indicates otherwise. Should they be told? Perhaps what R project is doing makes sense for openblas.

I tried building the current git version of openblas with just make, with Homebrew gfortan and Apple clang (i.e. their fake gcc), the result doesn't use openmp or gopenmp, and there is no -fopenmp in the resulting openblas.pc

I also tried to remove -fopenmp from Homebrew's openblas.pc, and the result is usable for us, it doesn't seem to affect the resulting application using Homebrew openblas in a bad way (but that's with limited testing). An openmp expert might be needed to confirm that this is OK as a solution for this bug.

@carlocab
Copy link
Member

I tried building the current git version of openblas with just make, with Homebrew gfortan and Apple clang (i.e. their fake gcc), the result doesn't use openmp or gopenmp, and there is no -fopenmp in the resulting openblas.pc

You need to enable OpenMP for a comparable build with:

export USE_OPENMP=1

@dimpase
Copy link
Contributor Author

dimpase commented Feb 27, 2025

I tried building the current git version of openblas with just make, with Homebrew gfortan and Apple clang (i.e. their fake gcc), the result doesn't use openmp or gopenmp, and there is no -fopenmp in the resulting openblas.pc

You need to enable OpenMP for a comparable build with:

export USE_OPENMP=1

this leads to an error as above in such a configuration, almost immediately.

EDIT2. I was slightly sloppy again. Now, with checkout of 0.3.29 (or with today's main), I get

make[1]: warning: -jN forced in submake: disabling jobserver mode.
cc -O2 -DSMALL_MATRIX_OPT -DGEMM_GEMV_FORWARD -DMAX_STACK_ALLOC=2048 -fopenmp -Wall -DF_INTERFACE_GFORT -fPIC -DSMP_SERVER -DUSE_OPENMP -DNO_WARMUP -DMAX_CPU_NUMBER=10 -DMAX_PARALLEL_NUMBER=1 -DBUILD_SINGLE=1 -DBUILD_DOUBLE=1 -DBUILD_COMPLEX=1 -DBUILD_COMPLEX16=1 -DVERSION=\"0.3.29\" -march=armv8.3-a -UASMNAME -UASMFNAME -UNAME -UCNAME -UCHAR_NAME -UCHAR_CNAME -DASMNAME=_saxpy -DASMFNAME=_saxpy_ -DNAME=saxpy_ -DCNAME=saxpy -DCHAR_NAME=\"saxpy_\" -DCHAR_CNAME=\"saxpy\" -DNO_AFFINITY -I.. -I. -UDOUBLE  -UCOMPLEX -c axpy.c -o saxpy.o
cc -O2 -DSMALL_MATRIX_OPT -DGEMM_GEMV_FORWARD -DMAX_STACK_ALLOC=2048 -fopenmp -Wall -DF_INTERFACE_GFORT -fPIC -DSMP_SERVER -DUSE_OPENMP -DNO_WARMUP -DMAX_CPU_NUMBER=10 -DMAX_PARALLEL_NUMBER=1 -DBUILD_SINGLE=1 -DBUILD_DOUBLE=1 -DBUILD_COMPLEX=1 -DBUILD_COMPLEX16=1 -DVERSION=\"0.3.29\" -march=armv8.3-a -UASMNAME -UASMFNAME -UNAME -UCNAME -UCHAR_NAME -UCHAR_CNAME -DASMNAME=_sswap -DASMFNAME=_sswap_ -DNAME=sswap_ -DCNAME=sswap -DCHAR_NAME=\"sswap_\" -DCHAR_CNAME=\"sswap\" -DNO_AFFINITY -I.. -I. -UDOUBLE  -UCOMPLEX -c swap.c -o sswap.o
cc -O2 -DSMALL_MATRIX_OPT -DGEMM_GEMV_FORWARD -DMAX_STACK_ALLOC=2048 -fopenmp -Wall -DF_INTERFACE_GFORT -fPIC -DSMP_SERVER -DUSE_OPENMP -DNO_WARMUP -DMAX_CPU_NUMBER=10 -DMAX_PARALLEL_NUMBER=1 -DBUILD_SINGLE=1 -DBUILD_DOUBLE=1 -DBUILD_COMPLEX=1 -DBUILD_COMPLEX16=1 -DVERSION=\"0.3.29\" -march=armv8.3-a -UASMNAME -UASMFNAME -UNAME -UCNAME -UCHAR_NAME -UCHAR_CNAME -DASMNAME=_scopy -DASMFNAME=_scopy_ -DNAME=scopy_ -DCNAME=scopy -DCHAR_NAME=\"scopy_\" -DCHAR_CNAME=\"scopy\" -DNO_AFFINITY -I.. -I. -UDOUBLE  -UCOMPLEX -c copy.c -o scopy.o
cc -O2 -DSMALL_MATRIX_OPT -DGEMM_GEMV_FORWARD -DMAX_STACK_ALLOC=2048 -fopenmp -Wall -DF_INTERFACE_GFORT -fPIC -DSMP_SERVER -DUSE_OPENMP -DNO_WARMUP -DMAX_CPU_NUMBER=10 -DMAX_PARALLEL_NUMBER=1 -DBUILD_SINGLE=1 -DBUILD_DOUBLE=1 -DBUILD_COMPLEX=1 -DBUILD_COMPLEX16=1 -DVERSION=\"0.3.29\" -march=armv8.3-a -UASMNAME -UASMFNAME -UNAME -UCNAME -UCHAR_NAME -UCHAR_CNAME -DASMNAME=_sscal -DASMFNAME=_sscal_ -DNAME=sscal_ -DCNAME=sscal -DCHAR_NAME=\"sscal_\" -DCHAR_CNAME=\"sscal\" -DNO_AFFINITY -I.. -I. -UDOUBLE  -UCOMPLEX -c scal.c -o sscal.o
cc -O2 -DSMALL_MATRIX_OPT -DGEMM_GEMV_FORWARD -DMAX_STACK_ALLOC=2048 -fopenmp -Wall -DF_INTERFACE_GFORT -fPIC -DSMP_SERVER -DUSE_OPENMP -DNO_WARMUP -DMAX_CPU_NUMBER=10 -DMAX_PARALLEL_NUMBER=1 -DBUILD_SINGLE=1 -DBUILD_DOUBLE=1 -DBUILD_COMPLEX=1 -DBUILD_COMPLEX16=1 -DVERSION=\"0.3.29\" -march=armv8.3-a -UASMNAME -UASMFNAME -UNAME -UCNAME -UCHAR_NAME -UCHAR_CNAME -DASMNAME=_sdot -DASMFNAME=_sdot_ -DNAME=sdot_ -DCNAME=sdot -DCHAR_NAME=\"sdot_\" -DCHAR_CNAME=\"sdot\" -DNO_AFFINITY -I.. -I. -UDOUBLE  -UCOMPLEX -c dot.c -o sdot.o
cc -O2 -DSMALL_MATRIX_OPT -DGEMM_GEMV_FORWARD -DMAX_STACK_ALLOC=2048 -fopenmp -Wall -DF_INTERFACE_GFORT -fPIC -DSMP_SERVER -DUSE_OPENMP -DNO_WARMUP -DMAX_CPU_NUMBER=10 -DMAX_PARALLEL_NUMBER=1 -DBUILD_SINGLE=1 -DBUILD_DOUBLE=1 -DBUILD_COMPLEX=1 -DBUILD_COMPLEX16=1 -DVERSION=\"0.3.29\" -march=armv8.3-a -UASMNAME -UASMFNAME -UNAME -UCNAME -UCHAR_NAME -UCHAR_CNAME -DASMNAME=_sdsdot -DASMFNAME=_sdsdot_ -DNAME=sdsdot_ -DCNAME=sdsdot -DCHAR_NAME=\"sdsdot_\" -DCHAR_CNAME=\"sdsdot\" -DNO_AFFINITY -I.. -I. -UDOUBLE  -UCOMPLEX -c sdsdot.c -o sdsdot.o
cc -O2 -DSMALL_MATRIX_OPT -DGEMM_GEMV_FORWARD -DMAX_STACK_ALLOC=2048 -fopenmp -Wall -DF_INTERFACE_GFORT -fPIC -DSMP_SERVER -DUSE_OPENMP -DNO_WARMUP -DMAX_CPU_NUMBER=10 -DMAX_PARALLEL_NUMBER=1 -DBUILD_SINGLE=1 -DBUILD_DOUBLE=1 -DBUILD_COMPLEX=1 -DBUILD_COMPLEX16=1 -DVERSION=\"0.3.29\" -march=armv8.3-a -UASMNAME -UASMFNAME -UNAME -UCNAME -UCHAR_NAME -UCHAR_CNAME -DASMNAME=_dsdot -DASMFNAME=_dsdot_ -DNAME=dsdot_ -DCNAME=dsdot -DCHAR_NAME=\"dsdot_\" -DCHAR_CNAME=\"dsdot\" -DNO_AFFINITY -I.. -I. -UDOUBLE  -UCOMPLEX -c dsdot.c -o dsdot.o
cc -O2 -DSMALL_MATRIX_OPT -DGEMM_GEMV_FORWARD -DMAX_STACK_ALLOC=2048 -fopenmp -Wall -DF_INTERFACE_GFORT -fPIC -DSMP_SERVER -DUSE_OPENMP -DNO_WARMUP -DMAX_CPU_NUMBER=10 -DMAX_PARALLEL_NUMBER=1 -DBUILD_SINGLE=1 -DBUILD_DOUBLE=1 -DBUILD_COMPLEX=1 -DBUILD_COMPLEX16=1 -DVERSION=\"0.3.29\" -march=armv8.3-a -UASMNAME -UASMFNAME -UNAME -UCNAME -UCHAR_NAME -UCHAR_CNAME -DASMNAME=_sasum -DASMFNAME=_sasum_ -DNAME=sasum_ -DCNAME=sasum -DCHAR_NAME=\"sasum_\" -DCHAR_CNAME=\"sasum\" -DNO_AFFINITY -I.. -I. -UDOUBLE  -UCOMPLEX -c asum.c -o sasum.o
cc -O2 -DSMALL_MATRIX_OPT -DGEMM_GEMV_FORWARD -DMAX_STACK_ALLOC=2048 -fopenmp -Wall -DF_INTERFACE_GFORT -fPIC -DSMP_SERVER -DUSE_OPENMP -DNO_WARMUP -DMAX_CPU_NUMBER=10 -DMAX_PARALLEL_NUMBER=1 -DBUILD_SINGLE=1 -DBUILD_DOUBLE=1 -DBUILD_COMPLEX=1 -DBUILD_COMPLEX16=1 -DVERSION=\"0.3.29\" -march=armv8.3-a -UASMNAME -UASMFNAME -UNAME -UCNAME -UCHAR_NAME -UCHAR_CNAME -DASMNAME=_ssum -DASMFNAME=_ssum_ -DNAME=ssum_ -DCNAME=ssum -DCHAR_NAME=\"ssum_\" -DCHAR_CNAME=\"ssum\" -DNO_AFFINITY -I.. -I. -UDOUBLE  -UCOMPLEX -c sum.c -o ssum.o
cc -O2 -DSMALL_MATRIX_OPT -DGEMM_GEMV_FORWARD -DMAX_STACK_ALLOC=2048 -fopenmp -Wall -DF_INTERFACE_GFORT -fPIC -DSMP_SERVER -DUSE_OPENMP -DNO_WARMUP -DMAX_CPU_NUMBER=10 -DMAX_PARALLEL_NUMBER=1 -DBUILD_SINGLE=1 -DBUILD_DOUBLE=1 -DBUILD_COMPLEX=1 -DBUILD_COMPLEX16=1 -DVERSION=\"0.3.29\" -march=armv8.3-a -UASMNAME -UASMFNAME -UNAME -UCNAME -UCHAR_NAME -UCHAR_CNAME -DASMNAME=_snrm2 -DASMFNAME=_snrm2_ -DNAME=snrm2_ -DCNAME=snrm2 -DCHAR_NAME=\"snrm2_\" -DCHAR_CNAME=\"snrm2\" -DNO_AFFINITY -I.. -I. -UDOUBLE  -UCOMPLEX -c nrm2.c -o snrm2.o
clang: error: unsupported option '-fopenmp'
clang: error: unsupported option '-fopenmp'
clang: error: unsupported option '-fopenmp'
clang: error: unsupported option '-fopenmp'
make[1]: *** [scopy.o] Error 1
make[1]: *** Waiting for unfinished jobs....
clang: error: unsupported option '-fopenmp'
clang: error: unsupported option '-fopenmp'
make[1]: *** [sswap.o] Error 1
make[1]: *** [sscal.o] Error 1
clang: error: unsupported option '-fopenmp'
clang: error: make[1]: *** [saxpy.o] Error 1
unsupported option '-fopenmp'
make[1]: *** [sdot.o] Error 1
make[1]: *** [sdsdot.o] Error 1
make[1]: *** [ssum.o] Error 1
make[1]: *** [sasum.o] Error 1
clang: error: unsupported option '-fopenmp'
make[1]: *** [snrm2.o] Error 1
clang: error: unsupported option '-fopenmp'
make[1]: *** [dsdot.o] Error 1
make: *** [libs] Error 1

@cho-m cho-m changed the title incorrect cflags in openblas.pc Cflags in openblas.pc are not compatible with Apple Clang Feb 27, 2025
@dimpase
Copy link
Contributor Author

dimpase commented Feb 27, 2025

another option might be to have openblas linked to libomp, not libgomp.
How does one setup cmake bindings for libomp using brew? I can't figure it out.

@dimpase
Copy link
Contributor Author

dimpase commented Feb 28, 2025

another option might be to have openblas linked to libomp, not libgomp. How does one setup cmake bindings for libomp using brew? I can't figure it out.

This actually appears doable, except that it's linking to both of them, libomp (for C) and libgomp (for Fortran). Modulo a couple cmake quirks, it appears to work, see
OpenMathLib/OpenBLAS#5156 (comment)

Would you be interested in a PR switching this build to such a setup?

@carlocab
Copy link
Member

I don't think we want to link to both libomp and libgomp, I'm afraid. Mixing OpenMP runtimes is a huge no-no.

@dimpase
Copy link
Contributor Author

dimpase commented Feb 28, 2025

Python people deal with multiple libomp's in one application on a regular basis. Perhaps @rgommers can comment on this.

I also don't know whether there is any C OpenMP in openblas.

@rgommers
Copy link

Mixing OpenMP runtimes is a huge no-no.

This is correct, it's a recipe for major trouble.

Python people deal with multiple libomp's in one application on a regular basis.

The only reason for this is that wheels uploaded to PyPI cannot depend on a common shared library, and aren't built as a coherent stack. To make it work at all, extensive symbol mangling machinery is used. The end result is lower performance without any real upside, because you have two OpenMP runtimes that don't know about each other and hence won't manage resources as well as a single runtime could in multithreading or multiprocessing use cases.

@dimpase
Copy link
Contributor Author

dimpase commented Feb 28, 2025

Does this mean that merely correcting flags acceptable by clang (by adding -Xclang in front of -fopenmp) will allow the use of GNU openmp (and openblas with GNU openmp) in clang-compiled C/C++ code?

@ywwry66
Copy link
Contributor

ywwry66 commented Mar 1, 2025

Does this mean that merely correcting flags acceptable by clang (by adding -Xclang in front of -fopenmp) will allow the use of GNU openmp (and openblas with GNU openmp) in clang-compiled C/C++ code?

For openmp to work using Apple clang, you need to build openblas as in https://gist.github.com/ywwry66/19d0f280632fb5b8c296e8a6ca06b6d7. However, you might still need to patch the .pc files to include -Xclang or -Xpreprocessor.

In my opinion, there is no ideal solution for now. Two ways that can possibly improve the current situation is: 1. Homebrew using Apple clang to build openblas when Apple adds flang frontend. 2. Homebrew using Apple's Accelerate framework instead of openblas to build python, R, etc (see #181251), unless your workflow requires direct usage of openblas.

@carlocab
Copy link
Member

carlocab commented Mar 1, 2025

Homebrew use Apple clang to build openblas when Apple adds flang frontend.

I doubt Apple will ship their own build of flang in the foreseeable future.

@dimpase
Copy link
Contributor Author

dimpase commented Mar 2, 2025

For openmp to work using Apple clang, you need to build openblas as in https://gist.github.com/ywwry66/19d0f280632fb5b8c296e8a6ca06b6d7. However, you might still need to patch the .pc files to include -Xclang or -Xpreprocessor.

So this does work with gfortan and Apple clang, right?
I just found out that libgomp wouldn't work with clang, does this mean that libomp does work with gfortan?

@cho-m
Copy link
Member

cho-m commented Mar 3, 2025

I would consider this issue an unsupported use case as pkg-config isn't flexible enough to allow multiple toolchains here. Can wait for other maintainer responses but likely will be closed as "not planned". Upstream seems to have made similar decision.


As previously mentioned, it isn't possible to create a single pkg-config file that works across GCC and Clang when using OpenMP. The instant you add flags for Apple Clang it will break GCC (and negatively impact LLVM Clang which natively supports -fopenmp).

Similar situation for flags needed by GCC and LLVM Clang as -fopenmp is set up to link in their corresponding OpenMP library. Using a non-standard combination means manually handling the flags and/or the compile/link phases, e.g. see https://cpufun.substack.com/p/is-mixing-openmp-runtimes-safe

When working in a build system, it will often require fighting with the defaults like overriding CMake's OpenMP_Fortran_LIB_NAMES (not documented as cache variable so no guarantee this will remain overridable). Not sure if possible in Meson.


Additionally, switching OpenMP runtime in openblas is not an isolated change. It requires modifying formulae in the connected dependents/dependencies that currently use libgomp, like gromacs, cp2k, dynare and fftw (as dependency of prior formulae). This means finding ways to get each build to correctly use same OpenMP.

Further discussion on switching from GCC to Apple Clang should be done in a PR as this is a breaking feature change rather than a bug fix. It will negatively impact GCC users and resulting binaries may require users to use more hacks/workarounds to build Fortran code. So this may not be a viable option until Flang is stable enough to try using as a dependency.


As side note, if you don't care about OpenMP and don't need static compilation, then you can try overriding the variable:

PKG_CONFIG_PATH=$(brew --prefix openblas)/lib/pkgconfig pkg-config --define-variable=omp_opt= --cflags --libs openblas
-I/opt/homebrew/Cellar/openblas/0.3.29/include -L/opt/homebrew/Cellar/openblas/0.3.29/lib -lopenblas

Beyond this, you may want to create a modified copy of OpenBLAS in your own tap either with your own patches or using pthreads.

@dimpase
Copy link
Contributor Author

dimpase commented Mar 5, 2025

pkg-config isn't flexible enough to allow multiple toolchains here

Certainly, but how about creating an alternative formula which uses openblas linked to libomp (and eventually similar formulae for packages using openblas) ? [one can also think about openblas built completely without OpenMP - that's probably an overkill]

This would allow the use of the clang+gfortran toolchain (not 100% sure whether it matters which clang it is, Apple or Homebrew/llvm, hopefully these two are interchangeable) without extra worries about libomp/libgomp combo, and it won't break anything existing.

@cho-m
Copy link
Member

cho-m commented Mar 5, 2025

That's something you should use a tap for - https://docs.brew.sh/How-to-Create-and-Maintain-a-Tap

@dimpase
Copy link
Contributor Author

dimpase commented Mar 5, 2025

Sure, but why would the more usual toolchain support be delegated to a tab, while an admittedly niche gcc-only toolchain be imposed by default ?

And, in particular, without any documentation, any warnings in this regard ? Do you really expect that everyone knows not to mix two different OpenMP libraries?

@cho-m
Copy link
Member

cho-m commented Mar 7, 2025

In the past, we supported 2 variants, a default "Apple clang + pthreads" and an optional "GCC + libgomp". When we removed support for options, we chose the most popular variant based on analytics data:

So not a niche choice when majority of Homebrew users chose that and have been using it for at least 6 years now.


Anyways, closing this issue as we don't use issues for new formula requests. And marking original headline topic as unsupported.

If you want to discuss further about new formula, please open a pull request.


I will note that "Apple clang + libomp" will probably require a minimum of upstream agreement for support at OpenMathLib/OpenBLAS#5169. Currently doesn't seem to be planned.

libomp is a pain on Apple clang since it is not only Cflags but also needs to manually handle -lomp. So both Libs and Cflags will need update.

Also, I don't think *BSD would have issues as long as they do a complete LLVM build. As example, the brew llvm formula is capable of handling clang -fopenmp correctly

$(brew --prefix llvm)/bin/clang -fopenmp test.c -o testotool -L test
test:
	/opt/homebrew/opt/llvm/lib/libomp.dylib (compatibility version 5.0.0, current version 5.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1351.0.0)

@cho-m cho-m closed this as not planned Won't fix, can't repro, duplicate, stale Mar 7, 2025
@dimpase
Copy link
Contributor Author

dimpase commented Mar 7, 2025

So not a niche choice when majority of Homebrew users chose that and have been using it for at least 6 years now.

This is a very skewed way to measure popularity.
It could be that the majority actually didn't use openblas.pc in their builds.
(and some of them since fought a mystery bug which came from libomp clashing with libgomp).

And you haven't said anything about improving documentation. How would another user not run into the same trap as I did ? You cannot expect a user to know that once there were 2 versions of the formula, and the surviving formula is just one of them remaining, while the other one is gone, and to know which one of the 2 actually survived, as the important information: the platform, once encoded in the options, is gone.

@ywwry66
Copy link
Contributor

ywwry66 commented Mar 9, 2025

So this does work with gfortan and Apple clang, right? I just found out that libgomp wouldn't work with clang, does this mean that libomp does work with gfortan?

@dimpase Since openblas uses openmp almost exclusively with C, this approach (Apple clang + libomp) is pretty safe for openblas. For general usage of libomp with gfortran, I don't have an answer. I tried the following toy example and it works:

gfortran -fopenmp -c test.f90 -o test.o
gfortran -L/opt/homebrew/opt/libomp/lib -lomp test.o -o test

test.f90:

PROGRAM Test
USE OMP_LIB

!$OMP PARALLEL

    CALL SLEEP(10)
    PRINT *, "Hello from process: ", OMP_GET_THREAD_NUM()

!$OMP END PARALLEL

END

@dimpase
Copy link
Contributor Author

dimpase commented Mar 9, 2025

Conda people say that they simply make libgomp.dylib a symlink to libomp.dylib, and it all works.

@ywwry66
Copy link
Contributor

ywwry66 commented Mar 10, 2025

Conda people say that they simply make libgomp.dylib a symlink to libomp.dylib, and it all works.

Then the "Apple clang + libomp" build of openblas should just work if you are willing to compile from source. I have updated my build script to patch the pkg-config file. It is certainly a hack so I don't expect it to become part of the Homebrew core unless we see some major changes (e.g., upstream support, Apple adopting flang, etc.)

@dimpase
Copy link
Contributor Author

dimpase commented Mar 19, 2025

Please have a look at OpenMathLib/OpenBLAS#5180 where one can build openblas with the Brew apple-clang + gfortran + libomp toolchain, using cmake.

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

No branches or pull requests

6 participants