Numerical Libraries and Linking
As listed under the software section we have a variety of numerical libraries. Before going any further you will need to be aware of the different methods for linking: static (file extention = .a) and dynamic (extention=.so) linking.
Static Linking: This is where the whole library is linked into your code at compile-link time. The size of the binary grows accordingly to accomodate the whole library and the amount of memory your binary requires to run will also be correspondingly bigger. This is useful if you compile on machine A but want to run it on machine B which has identical architecture but no access to the libraries during runtime
Dynamic Linking: (RECOMMENDED) The machine is made aware of the presence of the library and that it will need it during runtime. It does not load the library at this time. Instead it is loaded on the fly during runtime as required. This has the advantage that memory requirements will only increase at those stages during runtime which are necessary. For example, say you are doing a matrix multiplication but you only need it for 2percent of the time during execution. It is more efficient to dynamically link it as your memory requirements will only increase during this 2percent of runtime leaving memory available to other processes and users on the same node.
Linker Paths
Unfortunately there is no such thing as a $LIBPATH in the same way as there is a binary $PATH. You must therefore be aware of the methods required for library linking, particularly for static linking.
If your sys-admin has put the paths of all the places where dynamic libraries are to be found in /etc/ld.so.conf then all you should have to do to link in a dynamic library is add -lacml during compile time, to link the ACML for example. If not then you would specify the linker path during compile time (you would have to know where the library is to begin with of course):
pgf90 mycode.g90 -L/usr/pgi/linux86-64/5.2/libso -lacml
or
pgf90 mycode.f90 -L/usr/pgi/linux86-64/5.2/libso/libacml.so
To link in static libraries, eg LAPACK that comes with PGI, do
pgf90 mycode.f90 /usr/pgi/linux86-64/5.2/lib/liblapack.a
(note the missing -L)
By convention libraries always begin with lib in their title, eg libacml.so , liblapack.a etc. If you do not have to specify the library path and just want to use the -l flag then you can drop the lib and file extention.
A couple of useful tools:
-
ldd: check what libraries are compiled into your binary, ldd a.out
-
ar: check the contents of a static library (an archive), ar tf liblapack.a