compiled LAPACK into shared library

Post here if you have having problem using the Makefile build process.

compiled LAPACK into shared library

Postby peng.du » Sat Feb 28, 2009 4:01 am

Per a user's request for a way of compiled LAPACK in shared library, I did a little homework for it. Post it here so it might be useful to some others.

http://pduwork.pbwiki.com/lapack-as-a-shared-library

This following applies to lapack3.1.1.

(1) Adding -fPIC to

OPTS & NOOPT in make.inc

(2) Change the names in make.inc

BLASLIB = ../../blas$(PLAT).so
LAPACKLIB = ../lapack$(PLAT).so
TMGLIB = tmglib$(PLAT).so

(3) In ./SRC, change the Makefile from

../$(LAPACKLIB): $(ALLOBJ)
$(ARCH) $(ARCHFLAGS) $@ $(ALLOBJ)
$(RANLIB) $@

to

../$(LAPACKLIB): $(ALLOBJ)
$(LOADER) $(LOADOPTS) -shared -Wl,-soname,liblapack.so -o $@ $(ALLOBJ)

(4) In ./BLAS/SRC, change the Makefile from

$(BLASLIB): $(ALLOBJ)
$(ARCH) $(ARCHFLAGS) $@ $(ALLOBJ)
$(RANLIB) $@

to

$(BLASLIB): $(ALLOBJ)
$(LOADER) $(LOADOPTS) -z muldefs -shared -Wl,-soname,libblas.so -o $@ $(ALLOBJ)

And "-z muldefs" is used to handle multiple definitions in $(ALLOBJ)...whew~! [see [2]]

(5) In ./TESTING/MATGEN, change the Makefile from

../../$(TMGLIB): $(SMATGEN) $(CMATGEN) $(SCATGEN) $(DMATGEN) \
$(ZMATGEN) $(DZATGEN)
$(ARCH) $(ARCHFLAGS) $@ $(ALLOBJ)
$(RANLIB) $@

to

../../$(TMGLIB): $(ALLOBJ)
$(LOADER) $(LOADOPTS) -shared -Wl,-soname,libtmglib.so -o $@ $(ALLOBJ)

(6) create a bunch of soft links:

ln -sf tmglib_LINUX.so libtmglib.so
ln -sf lapack_LINUX.so liblapack.so
ln -sf blas_LINUX.so libblas.so

Add these to ./Makefile
lib: blaslib lapacklib tmglib
ln -sf tmglib_LINUX.so libtmglib.so
ln -sf lapack_LINUX.so liblapack.so
ln -sf blas_LINUX.so libblas.so

which used to be just

lib: blaslib lapacklib tmglib

Note that for sure you could do it without having to do these softlinks, for example when create the refblas, instead of doing

$(LOADER) $(LOADOPTS) -z muldefs -shared -Wl,-soname,libblas.so -o $@ $(ALLOBJ)

you could do

$(LOADER) $(LOADOPTS) -z muldefs -shared -Wl,-soname,blas_LINUX.so -o $@ $(ALLOBJ)

But the softlink give a good view of how shared library is only loaded when executing a program that requires them, eg:

with the softlink liblapack.so, you'll get this:

du:/home/du/lib/tmp/lapack-3.1.1/TESTING@grig-compile ~> ./xlintstc

./xlintstc: error while loading shared libraries: liblapack.so: cannot open shared object file: No such file or directory

And without setting LD_LIBRARY_PATH, you might get:

du:/home/du/lib/tmp/lapack-3.1.1/TESTING@grig-compile ~> ./xlintstc

./xlintstc: error while loading shared libraries: libtmglib.so: cannot open shared object file: No such file or directory

(7) TO USE

i. Compile and create libblas.so, liblapack.so and libtmglib.so by typing make in the lapack directory
ii. Add the path of the three .so files to LD_LIBRARY_PATH, eg:
export LD_LIBRARY_PATH=/home/du/lib/lapack-3.1.1.shared_lib:LD_LIBRARY_PATH
iii. link with your own program using -llapack -lblas and maybe -ltmglib

That's it. And please let me know if something isn't right. I have a modified version of lapack3.1.1 that's been tested and works well. Ask if you need it. I don't have time for pushing it to 3.2, but it shouldn't be too much of a difference.


Reference:
[1] http://www.yolinux.com/TUTORIALS/Librar ... namic.html
[2] http://sources.redhat.com/binutils/docs ... tions.html
peng.du
 
Posts: 11
Joined: Tue Feb 17, 2009 4:14 pm

Re: compiled LAPACK into shared library

Postby linuxl4 » Mon Mar 09, 2009 3:23 pm

very good work!

I think this should be integrated into lapack's Makefile.
linuxl4
 
Posts: 10
Joined: Fri Dec 19, 2008 12:09 am

Re: compiled LAPACK into shared library

Postby mredu » Mon Jun 01, 2009 10:40 pm

./xlintstc: error while loading shared libraries: libtmglib.so: cannot open shared object file: No such file or directory

Is this error ok to ignore?
mredu
 
Posts: 2
Joined: Mon Jun 01, 2009 9:34 pm

Re: compiled LAPACK into shared library

Postby peng.du » Wed Jun 03, 2009 3:43 pm

this only means the compiling of lapack into shared library is done. you need to set the path so it can be loaded at run time.
peng.du
 
Posts: 11
Joined: Tue Feb 17, 2009 4:14 pm

Re: compiled LAPACK into shared library

Postby Jacques_Menu » Tue Jan 12, 2010 11:42 am

Hello,

I followed the above recommendations for Lapack 3.2.1, they worked fine, leading to the following differences.

Thanks peng.du!

--

root@cal1:/Download/lapack-3.2.1 > diff make.inc INSTALL/make.inc.gfortran
20c20
< OPTS = -O2 -fPIC
---
> OPTS = -O2
22c22
< NOOPT = -O0 -fPIC
---
> NOOPT = -O0
24c24
< LOADOPTS = -lpthread
---
> LOADOPTS =
60,66c60,64
< #BLASLIB = ../../blas$(PLAT).a
< #gotoblas2 used instead:
< BLASLIB = /opt/gotoblas2/1.10/gcc-4.2.3/libgoto2.so
< LAPACKLIB = lapack$(PLAT).so
< TMGLIB = tmglib$(PLAT).so
< EIGSRCLIB = eigsrc$(PLAT).so
< LINSRCLIB = linsrc$(PLAT).so
---
> BLASLIB = ../../blas$(PLAT).a
> LAPACKLIB = lapack$(PLAT).a
> TMGLIB = tmglib$(PLAT).a
> EIGSRCLIB = eigsrc$(PLAT).a
> LINSRCLIB = linsrc$(PLAT).a

--

root@cal1:/Download/lapack-3.2.1/SRC > diff Makefile Makefile_ORG
369,371d368
< # ../$(LAPACKLIB): $(ALLOBJ) $(ALLXOBJ)
< # $(ARCH) $(ARCHFLAGS) $@ $(ALLOBJ) $(ALLXOBJ)
< # $(RANLIB) $@
373c370
< $(LOADER) $(LOADOPTS) -shared -Wl,-soname,liblapack.so -o $@ $(ALLOBJ) $(ALLXOBJ)
---
> $(ARCH) $(ARCHFLAGS) $@ $(ALLOBJ) $(ALLXOBJ)

--

root@cal1:/Download/lapack-3.2.1/BLAS/SRC > diff Makefile Makefile_ORG
140,142d139
< # $(BLASLIB): $(ALLOBJ)
< # $(ARCH) $(ARCHFLAGS) $@ $(ALLOBJ)
< # $(RANLIB) $@
144c141
< $(LOADER) $(LOADOPTS) -z muldefs -shared -Wl,-soname,libblas.so -o $@ $(ALLOBJ)
---
> $(ARCH) $(ARCHFLAGS) $@ $(ALLOBJ)

--

root@cal1:/Download/lapack-3.2.1/TESTING/MATGEN > diff Makefile Makefile_ORG
61,66c61,64
< # ../../$(TMGLIB): $(SMATGEN) $(CMATGEN) $(SCATGEN) $(DMATGEN) \
< # $(ZMATGEN) $(DZATGEN)
< # $(ARCH) $(ARCHFLAGS) $@ $(ALLOBJ)
< # $(RANLIB) $@
< ../../$(TMGLIB): $(ALLOBJ)
< $(LOADER) $(LOADOPTS) -shared -Wl,-soname,libtmglib.so -o $@ $(ALLOBJ)
---
> ../../$(TMGLIB): $(SMATGEN) $(CMATGEN) $(SCATGEN) $(DMATGEN) \
> $(ZMATGEN) $(DZATGEN)
> $(ARCH) $(ARCHFLAGS) $@ $(ALLOBJ)
> $(RANLIB) $@
Jacques_Menu
 
Posts: 1
Joined: Tue Jan 12, 2010 11:36 am

Re: compiled LAPACK into shared library

Postby linuxl4 » Wed May 05, 2010 6:08 am

what about to support xblas and "make cleanall" ?

so ALLXOBJS should be added to gcc -shared line,

as to make cleanall,
rm *.so should be added.
linuxl4
 
Posts: 10
Joined: Fri Dec 19, 2008 12:09 am

Re: compiled LAPACK into shared library

Postby linuxl4 » Wed May 05, 2010 7:06 am

I have a question also. Why don't you change LAPACKLIB to liblapack.so directly in make.inc to avoiding making those soft links?
linuxl4
 
Posts: 10
Joined: Fri Dec 19, 2008 12:09 am

Re: compiled LAPACK into shared library

Postby mikeross » Wed May 19, 2010 3:02 am

Thanks for sharing peng! very helpful..
mikeross
 
Posts: 1
Joined: Tue May 18, 2010 10:53 pm

Re: compiled LAPACK into shared library

Postby helium » Thu Jul 01, 2010 7:57 am

cheers man will try it out in a few days
helium
 
Posts: 1
Joined: Thu Jul 01, 2010 7:53 am

Re: compiled LAPACK into shared library

Postby cottrell » Thu Jul 08, 2010 11:32 am

Those wanting to compile lapack/blas as shared libraries
might like to take a look at the forum item
viewtopic.php?f=2&t=1895
which announces lapack-autoconf, available at
http://www.wfu.edu/~cottrell/lapack/

Allin Cottrell
cottrell
 
Posts: 68
Joined: Thu Jan 15, 2009 1:40 pm

Re: compiled LAPACK into shared library

Postby admin » Mon Jul 12, 2010 2:52 pm

Greenfun,
you want to set LD_LIBRARY_PATH to where you shared library is.
admin
Site Admin
 
Posts: 498
Joined: Wed Dec 08, 2004 7:07 pm

Re: compiled LAPACK into shared library

Postby tzartzar » Sun Jan 23, 2011 6:36 pm

Works for me. Thanks alot.
tzartzar
 
Posts: 1
Joined: Thu Jan 20, 2011 11:40 am


Return to Makefile

Who is online

Users browsing this forum: No registered users and 0 guests

cron