4

I am trying to compile a program that uses lapack.

First, I installed lapack by installing all the packages using 'sudo apt-get install' on this link: https://launchpad.net/ubuntu/precise/+source/lapack

I am trying to compile the code on this page: http://www.nag.com/lapack-ex/examples/source/dgbsv-ex.f

I got this program from: http://www.nag.com/lapack-ex/lapack-ex.html

I tried to compile the program by typing

$gfortran dbgsv-ex.f -llapack -lblas

into a terminal

I get a bunch of error messages, all of the form

/usr/lib/gcc/i686-linux-gnu/4.6/../../../../lib/liblapack.so: undefined reference to         
`ATL_strsv'

i.e. the error messages end with ATL_xxxx. Note also that when I look in my /usr/lib/ I see a file called liblapack.so

db1234
  • 797
  • 2
  • 11
  • 28
  • 3
    Looks like your LAPACK library is built on ATLAS. Check if ATLAS is installed and add reference to `-latlas` or link directly with `-llapack_atlas`. – Hristo Iliev May 18 '12 at 21:34
  • I installed atlas by typing `sudo apt-get install libatlas-dev libatlas-doc libatlas-test libatlas-base-dev libatlas3gf-base libatlas-cpp-0.6-dev libatlas-cpp-0.6-1 libatlas-cpp-0.6-1-dbg` Then tried to compile as before and got the same error messages, then I tried to compile by typing `gfortran dbgsv-ex.f -L/usr/local/lib -llapack -lblas -latlas` and I got an error saying `/usr/bin/ld: cannot find -latlas` In case the order mattered, I even tried to put -latlas before -lblas or before -llapack. I got the same error with -llapack_atlas – db1234 May 19 '12 at 03:39
  • 2
    It appears to be some old bug in the Debian/Ubuntu packages. You can read more [here](http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=598638). – Hristo Iliev May 19 '12 at 10:42
  • I tried to change the alternatives using `sudo update-alternatives --config libblas.so.3gf` and similarly for lapack, but it still wasn't working. Is there some way I can get lapack working? – db1234 May 19 '12 at 15:03
  • I would suggest that you remove all BLAS and LAPACK related packages and reinstall ATLAS. – Hristo Iliev May 19 '12 at 15:05
  • If I do that, I won't need to reinstall BLAS or LAPACK? – db1234 May 19 '12 at 15:12
  • ATLAS provides full BLAS implementation and lots of LAPACK routines. Probably it will be enough for your needs. – Hristo Iliev May 19 '12 at 15:15
  • Well...it took a while to unintsall BLAS and LAPACK (not sure if it was me or Ubuntu, but it was downloading at a pace of about 2,000 B/s!). When I install ATLAS, which components should I install, i.e. -dev, 3gf-base, -base-dev, etc. – db1234 May 19 '12 at 15:44
  • `libatlas-dev` and `libatlas-base-dev` for sure. Then `libatlas3gf-base` provides basic version of ATLAS that is compiled without any hardware optimisations. Ubuntu suggests that you build your own version that will be optimised for your specific processor. – Hristo Iliev May 19 '12 at 18:35
  • I removed any BLAS, LAPACK and reinstalled ATLAS. This also took a while going at about 10KB/s, and I even moved to a new location with better internet. I did not build my own version. Also it seems that BLAS and LAPACK were installed in the process according to what the Ubuntu software center says is installed on my laptop. I still have the same problem. With the link you posted about the alternative way to configure the libraries, is there any one I should choose? – db1234 May 19 '12 at 19:04
  • Unfortunately I don't have access to a Linux machine at the moment and my list of hypotheses has ended. I would do `dpkg -L ...` to see what is the content of each `libatlas` package. Problaby some additional library paths have to provided. – Hristo Iliev May 19 '12 at 20:20
  • Actually, I did not try to reconfigure LAPACK or BLAS after I removed then and reinstalled ATLAS. I reconfigured BLAS, and it compiles and works now!... well kind of.. The original program does not run, I get one small message `undefined reference to x04cef` instead of hundreds of messages, but this program ( http://www.physics.orst.edu/~rubin/nacphy/lapack/codes/linear-f.html ) initially had the *exact same* error messages before reconfiguring BLAS, but compiled and ran after reconfiguring BLAS. Thanks for your help! – db1234 May 19 '12 at 20:25
  • [X04CEF](http://www.nag.co.uk/numeric/FL/nagdoc_fl22/xhtml/X04/x04cef.xml) is part of the NAG Fortran Library. You won't find it in the `gfortran` runtime and would have to replace it with some other code that prints the matrix. – Hristo Iliev May 19 '12 at 20:29
  • Shameless plug: depending on what you are trying to build, EasyBuild might help out. It solves a lot of this BLAS/LAPACK/ATLAS linking crap for you. See http://hpcugent.github.com/easybuild. (disclaimer: I am a developer for EasyBuild) – Kenneth Hoste Nov 21 '12 at 20:22

1 Answers1

1

As other comments already indicate, your system has an ATLAS implementation of LAPACK. The correct order of library linking (for the non-threaded version of ATLAS) would be then:

-llapack -lf77blas -lcblas -latlas

Also note, that your Fortran code seems to contain also a routine from the NAG Library (x04cef), so you would have to link the NAG Library as well.

Bálint Aradi
  • 3,754
  • 16
  • 22