tech-pkg archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Deciding on wich variant(s) of OpenBLAS library to install

On 02/16/18 11:49, Dr. Thomas Orgis wrote:
Am Fri, 16 Feb 2018 07:40:50 -0600
schrieb Jason Bacon <>:

I think the potential failures you cited when using a multithreaded
library actually speak in favor of the openblas-devel approach.
[…] wonder if the pthread code is still being maintained faithfully.
Please note that in the case of numpy (maybe older pythons only, not
sure), the pthread variant works, while the openmp variant freezes …
under circumstances. See

There is no way to make everyone happy …
That's pretty old - last activity was 2014 referring to v0.2.8. However, it seems the FreeBSD port uses pthreads by default and offers an option to use openmp instead.

+[ ] OPENMP        Use OpenMP for threading
openblas-devel package is based on the FreeBSD port, which has been
around for a while and presumably has evolved a strategy to deal with
these issues.
How much is FreeBSD actually used in scenarios where people use BLAS? I
suspect that we are dealing only with a handful of sites, like us in
pkgsrc. Just observe the lively discussion here on tech-pkg;-)
Nevertheless, I am trying to look at what others do. There are
precedents for various approaches.
Science on FreeBSD is pretty strong and healthy.  I'm counting 1,312 ports in the science categories (astro,biology,cad,math,science), including blas, openblas, atlas, mpich, mpich, openmpi, openmpi2, openmpi3.   I've been using it for research for about 14 years and it has always been pretty solid.

I did some testing myself, and for our setup, the OpenMP variant as
default would work, partially because we have a default of
OMP_NUM_THREADS=1 in the environment. Users have to think a bit about
their application and then enable the multithreading as desired. With
the thread count of 1, the OpenMP version does not cause trouble. This
is preferrable to us having to build another instance of numpy and R
(and others).

It sounds like the most stable approach would be to install a serial
version of the library under the default name libopenblas.{a,so} and
offer a multithreaded version under a different name for those who want
to explicitly choose it.  Under this strategy, you could offer both
openmp and pthreads versions under different names, but I'm not sure
whenther this would actually benefit anyone.
See above … sadly, the openmp version is not clearly superior for
everyone. When we install 2 variants, we could just as well also offer 3.
Only argument against that would well-established usage of the name. I am not sure of that, besides Debian and FreeBSD.

Also, by following the FreeBSD port example, we can leverage examples of
how dependent ports utilize the parallel version.  A quick grep on the
FreeBSD ports tree reveals a few ports that are tuned to use openblasp:

lang/julia/Makefile: \
math/armadillo/Makefile: \
math/py-numpy/Makefile:        -e "s|%%BLASLIBS%%|openblasp, gfortran|" \
Of course you can hack them to use libopenblasp, while libopenblas
might be supported as a normal option already. But that is all
optional, right? Instead of offering choice of 'blas openblas', we need
to add options 'blas openblas openblas_pthread openblas_openmp' to all
packages. And the user must decide on each one, as each package can
have its own trouble with a parallel BLAS.

We can put openblas_openmp into PKG_DEFAULT_OPTIONS, right? Any
PKG_OPTIONS.package totally overwrites the default … or does it add to
it? I am not sure of that from reading the docs … testing … so: If I have


I need

PKG_OPTIONS.octave+=-openblas_openmp -openblas_pthread openblas_serial

to ensure that it uses the serial libopenblas? I'm presuming that
multiple occurences of exclusive options like that are an error. I am
trying to test that with my wip/OpenBLAS snapshot that I built
alongside 2017Q2 … how can

	bmake show-var varname=PKG_OPTIONS

(also PKG_DEFAULT_OPTIONS, PKG_OPTIONS.openblas) show nothing while
there are clearly options being applied (as shown by show-options)?
This is still too much of a mystery machine to me:-(

Anyway, it seems like the last value in the options list wins. Is this
intentional or an accident?

My point is this: We complicate the situation by adding the choice
of the openblas variant not just to the openblas package, but also to
every dependent package. If you built a program linking to the OpenMP
(or pthread, for that matter) openblas library, you can run it with
OMP_NUM_THREADS=1 in the environment and it will behave like the serial
one. Also it refuses spawning further threads if called inside OpenMP
parallel regions (no nesting).

My tentative assumption is that people who enable openblas at all could
be expected to read up on the possible pitfalls when they choose a
parallel build for pkgsrc. The default should still be a serial build.

I am not opposed to installing multiple libs in principle, but I do not
like what happens with the rest of the installation. Please have a look
at OpenBLAS/PLIST and openblas-devel/PLIST. There are things that
depend on build-time choices. And others that are just rudely dropped.
Do you agree that lapacke.h, cblas.h should be present? They might be
not really specific to OpenBLAS (not sure), but I don't see another
package offering them.

Also, what about


? I guess we'd need to add


but those probably will be in vain as any configure script most
probably will just look for openblas. Dunno about the cmake stuff, but
I guess it's the same.

There needs to be some brains put in to avoid shipping broken
auxilliary files that assist in using libopenblas when we install
multiple builds. The solution of FreeBSD apparently was to drop
everything besides the bare library. A valid approach, but it should be
discussed. I like my pkgconfig files, for example (need to push my
netcdf.pc/netcdf-fortran.pc upstream).

I see the great divide between people caring about openblas and people
not caring. I see the latter group being the large majority. The
further division into people who would like easy switchery between
libopenblas variants apart from a chosen version during pkg build …
seems rather nitpicky to me. Especially considering that people who
really care about own applications they build can build OpenBLAS easily,

Maybe we can have input from someone else intending to offer
R/numpy/octave with openblas from a common build out of pkgsrc to a set
of users? An individual workstation will have the user just choose one
version and be happy. A multi-user site may have differing preferences,
people needing serial OpenBLAS and others needing parallel. But on our
multi-user site that is catered for by one parallel build and a default
setting of OMP_NUM_THREADS=1 to be changed by people who want to do
parallel BLAS.

Is there an actual prospective user site not happy with deciding once
about OpenBLAS parallelism at build-time? If there is, I could be
convinced to integrate the openblas-devel approach. But lacking that, I
see only hackery around the upstream installation routine and
confguration space bloat for depending packages … more work for me,
more build time for the machines, for questionable gain.

Having pre-built packages only with the serial version is an acceptable
compromise, I guess. In HPC, we build from source. A user on a beefy
workstation might do that, too. And even on end-user PCs, the boost
from the vectorization itself is bigger than just running on 2 or 4
cores, even.

Alrighty then,


PS: Interesting entry in OpenBLAS change log (06-Mar-2014, Version
0.2.9.rc2, long time after adding OpenMP):

* Make OpenBLAS thread-pool resilient to fork via pthread_atfork.

So the pthread version appears to be maintained. OpenMP+fork trouble needs
non-existing workaround in GCC.

The FreeBSD strategy appears to be serial and with pthreads by default and an option to use openmp instead.  I think this is a reasonable approach that makes all options available in a safe way.  The serial version is safe for everyone and people will have to deliberately choose the parallel library and further deliberately choose openmp, which may cause some issues.
(A warning in the options would be good)

I think having a parallel library in the binary package is essential in case dependent packages use it by default.

Given the small number of initial users, I don't think we need to aim for perfection on the first commit.  Instead, we should pick a safe and reasonable approach that makes all options available and let it evolve according to



Earth is a beta site.

Home | Main Index | Thread Index | Old Index