# Copyright (c) 2014, 2016 Dave Love, Liverpool University # Licence: BSD # This implements something effectively similar to Debian's handling # of linear algebra libraries # to # hack around the Fedora mess which might, say, mean four # implementations contending in an R application using assorted # libraries (Rblas, reference (essentially the same), openblas, atlas) # depending on how things were built. # soname version for reference libraries %global sover 3 # and for GSL %global gslsover 0 # For an R package that doesn't use openblas (see #1389724) %if 0%{?el6} %bcond_without rfix %else %bcond_with rfix %endif # 64-bit integer versions? %if 0%{?__isa_bits} == 64 %if !0%{?el6} # 64-bit integer reference libraries require a rebuild of version # 3.4+. We could actually provide the library shims, since we have # the "64" openblas libraries, but that would probably only cause # confusion. Build this "--with blas64" if required. %bcond_without blas64 %endif %endif %{!?openblas_arches:%global openblas_arches x86_64 %{ix86} armv7hl %{power64} aarch64 s390x} Name: openblas-compat Version: 1.0 Release: 12%{?dist} Summary: Openblas compatibility libraries for reference blas/lapack etc. # Inherit the openblas licence. License: BSD URL: https://loveshack.fedorapeople.org/blas-subversion.html BuildRequires: openblas-devel # As for openblas ExclusiveArch: %openblas_arches %description This package provides trivial shared LAPACK/BLAS libraries which can replace those from the reference blas, lapack, atlas, gsl, and R packages at run time so that binaries dynamically linked against those automatically get the benefit of the generally-faster openblas routines. This package can be installed in parallel with the reference versions and others. It overrides them via ldconfig configuration in the absence of a policy of using alternatives for BLAS/LAPACK in Fedora. (Note that the older atlas in EPEL already overrides the reference versions in the same way.) Use LD_LIBRARY_PATH to pick up the original versions for testing. In the case of R, profile.d files set R_LD_LIBRARY_PATH appropriately, since that's set in system startup files, overriding ldconfig. It is also possible to replace the vanilla serial libraries with the OpenMP version of OpenBLAS to provide SMP speed-up by pointing LD_LIBRARY_PATH at %_libdir/%name-openmp (with appropriate OMP_NUM_THREADS, of course). On Sandy Bridge with vanilla RHEL6.6/EPEL packages, running the linpack benchmark single-threaded, openblas is asymptotically around nine times faster than reference lapack/blas and four times faster than atlas-sse3 (the best variant for SB that is packaged). %if %{with blas64} Versions with both 32-bit and 64-bit indexing are included. %endif %prep rm -rf %name-%version mkdir %name-%version %build cd %name-%version # We need libraries with the right filename and soname, so build # trivial ones which just pull in openblas. (Debian builds # non-trivial versions as alternatives.) echo with %{with blas64} %if %{with blas64} %global lib64s blas64 lapack64 %else %global lib64s %nil %endif # ATLAS changed at 3.10 %if 0%{?el6} || 0%{?el5} %global atlibs cblas clapack f77blas %else %global atlibs satlas %endif for n in blas lapack lapacke %lib64s %atlibs; do cc -shared -o lib$n.so.%sover -Wl,-soname,lib$n.so.%sover -lopenblas done for n in %lib64s; do cc -shared -o lib$n.so.%sover -Wl,-soname,lib$n.so.%sover -lopenblas64 done cc -shared -o libgslcblas.so.%gslsover -Wl,-soname,libgslcblas.so.%gslsover -lopenblas # atlas threaded %if 0%{?fedora} > 20 cc -shared -o libtatlas.so.%sover -Wl,-soname,libtatlas.so.%sover -lopenblasp -pthread %else for n in ptf77blas ptcblas; do cc -shared -o lib$n.so.%sover -Wl,-soname,lib$n.so.%sover -lopenblasp -pthread done %endif # R 3.3.2-2 uses openblas; but not on el6... %if %{with rfix} # R sanctions linking optimized libraries to these in its library # area, but that gets a spurious link made to libopenblas.so by # ldconfig and this is cleaner and robust through package updates. cc -shared -o libRblas.so -lopenblas cc -shared -o libRlapack.so -lopenblas %endif # OpenMP variants with the serial names, installed in a sub-directory mkdir omp pushd omp for n in blas lapack lapacke %lib64s %atlibs; do cc -shared -o lib$n.so.%sover -Wl,-soname,lib$n.so.%sover -lopenblaso done cc -shared -o libgslcblas.so.%gslsover -Wl,-soname,libgslcblas.so.%gslsover -lopenblaso %if %{with rfix} cc -shared -o libRblas.so -lopenblaso cc -shared -o libRlapack.so -lopenblaso %endif popd %install cd %name-%version mkdir -p %buildroot%_libdir/openblas-compat{,-openmp} mkdir -p %buildroot%_sysconfdir/ld.so.conf.d %buildroot%_sysconfdir/profile.d install -m 755 *.so* %buildroot%_libdir/openblas-compat install -m 755 omp/*.so* %buildroot%_libdir/openblas-compat-openmp # needs to collate before atlas* echo %_libdir/openblas-compat > %buildroot%_sysconfdir/ld.so.conf.d/0openblas-compat-%_arch.conf mkdir -p %buildroot%_libdir/R/etc %post %if %{with rfix} # Fixme: does ldconfig actually use the locale? LC_COLLATE=C /sbin/ldconfig # It's unfortunate to have to do this, and I think it wasn't necessary # at some stage in the past. This file is somewhat redundant with the # ldconfig one that R installs, but we should probably retain # configuration via R_LD_LIBRARY_PATH; probably the R packaging should # be changed only to set LD_LIBRARY_PATH when R_LD_LIBRARY_PATH is # defined xternally. (Setting R_LD_LIBRARY_PATH in profile.d isn't # useful for HPC because that won't typically be used by batch jobs.) # See https://bugzilla.redhat.com/show_bug.cgi?id=1389719 mkdir -p %_libdir/R/etc cat <<\+ > %_libdir/R/etc/ldpaths if [ -n "$R_LD_LIBRARY_PATH" ]; then if [ -z "$LD_LIBRARY_PATH" ]; then LD_LIBRARY_PATH="$R_LD_LIBRARY_PATH" else LD_LIBRARY_PATH="$R_LD_LIBRARY_PATH:$LD_LIBRARY_PATH" fi export LD_LIBRARY_PATH fi + %endif %postun -p /sbin/ldconfig %files %_libdir/openblas-compat %_libdir/openblas-compat-openmp %config(noreplace) %_sysconfdir/ld.so.conf.d/* %if %{with rfix} %dir %_libdir/R %dir %_libdir/R/etc %endif %changelog * Fri Nov 17 2017 Dave Love - 1.0-12 - Drop el5 stuff - Use openblas_arches - Define rfix on el6 * Mon Nov 7 2016 Dave Love - 1.0-11 - Condition-out R stuff, assuming fix of #1389724 * Fri Oct 28 2016 Dave Love - 1.0-10 - Add URL tag * Tue Oct 25 2016 Dave Love - 1.0-9 - Avoid "64" versions on el5, 6 by default - Sync ExclusiveArch with openblas 0.2.19 - Worry about collation for ldconfig * Thu Oct 20 2016 Dave Love - 1.0-8 - Modify R's ldpaths rather than using profile. * Thu Oct 20 2016 Dave Love - 1.0-7 - Tidying and extra description - Use %%ghost for profile files * Thu Oct 20 2016 Dave Love - 1.0-6 - Fix up for current R - Provide OpenMP versions of the serial libraries * Thu May 19 2016 Dave Love - 1.0-5 - Use ExclusiveArch * Mon Apr 13 2015 Dave Love - 1.0-4 - Fix condition for atlas choice * Tue Feb 17 2015 Dave Love - 1.0-3 - Fix gsl soversion - Support recent Fedora atlas version - Add R libs * Wed Jan 28 2015 Dave Love - 1.0-2 - Make a build direectory - Add gslcblas * Fri Dec 19 2014 Dave Love - 1.0-1 - Initial packaging