[Rd] hand compile; link to MKL fails at BLAS zdotu
Ivan Krylov
|kry|ov @end|ng |rom d|@root@org
Sat Mar 30 18:31:25 CET 2024
В Sat, 30 Mar 2024 10:55:48 +0000
Ramón Fallon <ramonfallon using gmail.com> пишет:
> In contrast to Dirk's solution, I've found R's configure script
> doesn't recognise the update-alternatives system on debian/ubuntu, if
> it's MKL.
It ought to work if configured with --with-blas=-lblas
--with-lapack=-llapack, but, as you found out (and I can confirm), if
libblas.so and liblapack.so already point to MKL, ./configure somehow
fails the test for zdotu and falls back to bundled Rblas and Rlapack.
If you'd like the built R to work with the update-alternatives system,
the workaround seems to help is to temporarily switch the alternatives
to reference BLAS & LAPACK, configure and build R, and then switch the
alternatives back to MKL.
> appending "-lmkl_gf_lp64" to the --with-blas option does not help
> (that's suggested by several posts out there).
MKL has an official "link line advisor" at
<https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl-link-line-advisor.html>,
which may suggest a completely different set of linker options
depending on what it is told. Here's how R's zdotu test always fails
when linking directly with MKL:
# pre-configure some variables
echo '#define HAVE_F77_UNDERSCORE 1' > confdefs.h
FC=gfortran
FFLAGS='-g -Og'
CC=gcc
CFLAGS='-g -Og'
CPPFLAGS=-I/usr/local/include
MAIN_LDFLAGS='-Wl,--export-dynamic -fopenmp'
LDFLAGS='-L/usr/local/lib'
LIBM=-lm
FLIBS=' -lgfortran -lm -lquadmath'
# copied & pasted from the Intel web page
BLAS_LIBS='-lmkl_rt -Wl,--no-as-needed -lpthread -lm -ldl'
# R prepares to call zdotu from Fortran...
cat > conftestf.f <<EOF
c Goto's BLAS at least needs a XERBLA
subroutine xerbla(srname, info)
character*6 srname
integer info
end
subroutine test1(iflag)
double complex zx(2), ztemp, zres, zdotu
integer iflag
zx(1) = (3.1d0,1.7d0)
zx(2) = (1.6d0,-0.6d0)
zres = zdotu(2, zx, 1, zx, 1)
ztemp = (0.0d0,0.0d0)
do 10 i = 1,2
ztemp = ztemp + zx(i)*zx(i)
10 continue
if(abs(zres - ztemp) > 1.0d-10) then
iflag = 1
else
iflag = 0
endif
end
EOF
${FC} ${FFLAGS} -c conftestf.f
# and then call the Fortran subroutine from the C runner...
cat > conftest.c <<EOF
#include <stdlib.h>
#include "confdefs.h"
#ifdef HAVE_F77_UNDERSCORE
# define F77_SYMBOL(x) x ## _
#else
# define F77_SYMBOL(x) x
#endif
extern void F77_SYMBOL(test1)(int *iflag);
int main () {
int iflag;
F77_SYMBOL(test1)(&iflag);
exit(iflag);
}
EOF
${CC} ${CPPFLAGS} ${CFLAGS} -c conftest.c
# and then finally link and execute the program
${CC} ${CPPFLAGS} ${CFLAGS} ${LDFLAGS} ${MAIN_LDFLAGS} \
-o conftest conftest.o conftestf.o \
${BLAS_LIBS} ${FLIBS} ${LIBM}
./conftest
It seems to crash inside MKL!
rax=ffffffffcccccccd rbx=00005590ee102008 rcx=00007ffdab2ddb20 rdx=00005590ee102008
rsi=00007ffdab2ddb18 rdi=00005590ee10200c rbp=00007ffdab2dd910 rsp=00007ffdab2db600
r8=00005590ee102008 r9=00007ffdab2ddb28 r10=00007f4086a99178 r11=00007f4086e02490
r12=00005590ee10200c r13=00007ffdab2ddb20 r14=00005590ee102008 r15=00007ffdab2ddb28
ip = 7f4086e02a60, sp = 7ffdab2db600 [mkl_blas_zdotu+1488]
ip = 7f4085dc5250, sp = 7ffdab2dd920 [zdotu+256]
ip = 5590ee1011cc, sp = 7ffdab2ddb40 [test1_+91]
ip = 5590ee101167, sp = 7ffdab2ddb70 [main+14]
It's especially strange that R does seem to work if you just
update-alternatives after linking it with the reference BLAS, but
./conftest starts crashing again in the same place. This is with
Debian's MKL version 2020.4.304-4, by the way.
--
Best regards,
Ivan
More information about the R-devel
mailing list