Is MKL linked statically or shared?

Satish Balay balay at mcs.anl.gov
Fri Jan 26 00:17:51 CST 2007


On Fri, 26 Jan 2007, Ben Tay wrote:

> My school's server only has MKL installed on some nodes.  Hence I
> was told that if I need to use it, I'll have to link them
> statically. So how does PETSc use MKL?

I guess the question is - how do you work arround the problem [of
badly installed MKL] when using PETSc. For this you need to understand
a little bit about how compilers work. [wrt linking shared vs static
libraries]

When you specify: '-L/foo -lbar' the compiler first looks for The
library 'bar' in /foo. Here it first looks for the shared version [i.e
libbar.so]. If this version is not found - then it looks for the
static version. [i.e libbar.a]

However if you wish to force using the linker to use static version of
library [when the shared version is also present] - you have the
following options:

- specifiy the library as /foo/libbar.a in the link command.

- force linker to only use static libraries [for eg: 'gcc -static'].
  But then - if you don't have static version for any library [in the
  list of dependent libraries] - this link fails.

- specify linker options to mix static & sharedlibs. For ex: 'gcc
  -Wl,-Bstatic -lfoo -Wl,-Bdynamic -lbar'.

Neither of these approaches are supported by configure [as configure
assumes '-L/foo -lbar' always works]. So you'll have to edit
bmake/$PETSC_ARCH/petscconf - and make this change to the required
libraries manually.

For eg: I have the following in petscconf.h
BLASLAPACK_LIB = -llapack -lblas

The change would be either of the following [assumging gcc as the compiler]:

BLASLAPACK_LIB = /usr/lib/liblapack.a /usr/lib/libblas.a
or
BLASLAPACK_LIB = -Wl,-Bstatic -llapack -lblas -Wl,-Bdynamic

> Btw, I'm currently using shared PETSc library.

If you make changes to the link options [as above] then you'll have to
rebuild the PETSc shared libraries [with the following command]

make deleteshared shared

BTW: If PETSc sharedlibs are working across all machines [i.e PETSc
install is on common file system across all of them] - then you can
simply copy all the missing .so files into $PETSC_DIR/lib/$PETSC_ARCH
- and everything should just work.

cp /opt/intel/mkl/lib/ia32/*.so ${PETSC_DIR}/lib/${PETSC_ARCH]

Satish




More information about the petsc-users mailing list