Linking Lapack and Blas Libraries with fortran and c code

zhaozj2021-02-16  107

Sender: MAS (Fangq), Word Area: Mathtools Title: Linking LaPack and Blas Libraries with Fortran and C C C code [Reserved] Send Station: Dama Biggreen BBS (Mon Nov 11 19:14:53 2002), station letter

Linking LAPACK and BLAS libraries with Fortran and C code Last update: Sat Nov 17 16:21:36 2001 Comments, and reports of errata or bugs, are welcome via e-mail to the author, Nelson HF Beebe In your report, please. Supprish Time Stamp Recorted Near The Top of The Document.

Table of Contents Documentation for LAPACK LINKING WITH LOCALLED LIBRARIES LINKING WITH NAG LIBRARIES LINKING WITH VENDOR-Provided Libraries Related Libraries: Linpack and Eispack

Documentation for LAPACK There is locally-provided online documentation for LAPACK inside the GNU Emacs info system. In emacs, type Ch i to enter the info system, then type MLocal and MLAPACK. You can do the same thing in the standalone xinfo viewer. That documentation is also available in HTML form for Web browsers The standard reference manual for LAPACK is @String {pub-SIAM = "Society for Industrial and Applied Mathematics"} @ String {pub-SIAM:. adr = "Philadelphia, PA, USA" }

@Book {Anderson: 1992: Lug, Author = "E. Anderson and Z. Bai and C. Bischof and J. Demmel and J. Dongarra and J. {du croz} and A. Greenbaum and S. Hammarling and A. Mckenney And S. Ostrouchov and D. Sorenson ", Title =" {LAPACK} Users' Guide ", Publisher = Pub-Siam, Address = Pub-Siam: ADR, PAGES =" XV 235 ", Year =" 1992 ", ISBN = "0-89871-294-7", lccn = "QA76.73.F25 L36 1992", BIBDATE = "Tue Dec 14 22:36:17 1993",} Lining with locally-installed libraries BECAUSE OF THE PROBLEMS DOCUMENTED BELOW in using vendor-provided LAPACK libraries, LAPACK and its associated BLAS (Basic Linear Algebra Subroutines) library have been installed separately on all local systems, so that Fortran code can be (almost) uniformly linked like this: f77 -o fcode fcode.f -L / usr / local / lib -llapack -lblas

f77 can be replaced by g77, f90, f95, fort, pgf77, pgf90, pghpf, xlf, xlf90, xlf90_r, xlf90_r7, xlf95, xlf95_r, xlf95_r7, xlf_r, or xlf_r7, where available. All build logs are preserved in / usr / Local / Math / LAPACK / LOGS / TYPEScript. *

There are regrettably a few unavoidable exceptions to the above simple recipe that are necessary if the compiler is not f77, or if the memory model is not the default, or if there is more than one version of the libraries: Compaq / DEC Alpha GNU / Linux: Reason: Two Incompatible Fortran Compilers: f77 -o fcode fcode.f -l / usr / local / lib -llapack -lblas f77 -o fcode fcode.f -L / usr / local / lib -llapackf77 -lblasf77 fort -o fcode fcode.f -L / usr / local / lib -llapackfort -lblasfortThe nonsuffixed and f77-suffixed libraries are hard links to the same files. It is easiest for users to make the library suffix match the compiler name. GNU / Linux on Intel X86: Reason: Two Different Lapack and Blas Libraries: PGF77 Foo.f -l / usr / local / lib - llapack -lblas # <- local libraries pgf77 foo.f -llapack -lblas # <- vendor libraries

PGF90 foo.f -l / usr / local / lib - llapack -lblas # <- local libraries pgf90 foo.f -Llapack -lblas # <- vendor libraries

PGHPF foo.f -l / usr / local / lib -llapack -lblas # <- local libraries pghpf foo.f -Llapack -lblas # <- vendor libraries

SGI IRIX 6.5 Reason: Three Different Memory Models: -O32, -N32 (Default), and -64: f77 -o fcode fcode.f -l / usr / local / lib -llapack -lblas # <- Same as -n32 Case Below F77 -O32 -O fcode fcode.f -l / usr / local / lib32 -llapack -lblas f77 -n32 -o fcode fcode.f -L / usr / local / libn32-llapack -lblas f77 -64 -o fcode Fcode.f -l / usr / local / lib64-llapack -lblas

Sun Solaris 2.x: Reason: F77 .o Files Are Incompatible with Those from F90 and F95: F77 -o fcode fcode.f -l / usr / local / lib -llapack -lblas f77 -o fcode fcode.f -l / USR / local / lib -llapackf77 -lblasf77 f90 -o fcode fcode.f -L / usr / local / lib -llapackf90 -lblasf90 f95 -o fcode fcode.f -l / usr / local / lib -llapackf95 -lblasf95the f90 and F95 libraries are hard links to the same files, so they can be used interchangeably Similarly, the nonsuffixed and f77-suffixed libraries are hard links to the same files It is easiest for users to make the library suffix match the compiler name Caveat...: The LAPACK code on all systems has been compiled with -O optimization, and the LAPACK test suites have not yet been run. Vendor-provided libraries are likely to have been compiled with high optimization levels, and in some cases, may be replaced by assembly -Coded Routines with Even Higher Performance. They are also likely to have received extensive testing.

Linking with nag libraries Using the nag libraries is docute separately.

Linking with vendor-provided libraries Most commercial UNIX vendors now provide optimized versions of the LAPACK (and often also LINPACK and EISPACK) libraries, but alas, the library names and locations are vendor dependent. We also have the commercial NAG libraries installed on all local architectures for which they are available. Those libraries include all of EISPACK, LINPACK, LAPACK, and the BLAS. On some systems, it is even more complex, because the libraries have been built for Fortran 77 use in one version, and for Fortran 90 . in a later version Complexity is increased yet again when C code is linked against these libraries, because the C <-> Fortran interface is not standardized with respect to external names or data types (eg, Fortran function foo is C function foo_ on most UNIX systems, except IBM AIX and HP HP-UX, where the name remains unchanged, and on now-deceased Stardent, where it was C function FOO). C compilers do not know what Fortran libraries are needed, or where to find them. There are no standard C header files that define suitable prototypes for the Fortran libraries (although /usr/local/include/clapack.h has been installed to help out). The various GNU / Linux distributions for Apple / IBM PowerPC , Compaq / DEC Alpha, Intel x86, and Sun SPARC do not come with LAPACK support In a Makefile for C and Fortran code, you might have something like this:. DEFINES = INCLUDES = -I / usr / local / includeOPT = -OCFLAGS = $ (OPT) $ (defluddes) $ (defines) Clibs = -LM # systems with nag library: flibs = -lnag

# GNU / Linux Intel x86 systems with Portland Group compilers (pgcc, # pgCC, pgf77, pgf90, pghpf): CLIBS = -lpgftnrtl -lm -lpgc -lgccFLIBS = -llapack -lblas # Compaq / DEC Alpha OSF / 1 4.0: FLIBS = -LSCIPORT-LDXML

# Ibm aix 4.3: flib = -lesslfc = f77

# SGI Irix 6.5: flibs = -lcomplib.sgimathfc = F77

# Sun Solaris 2.7 with /opt/sunwspro/sc5.0/libflibs = -L / OPT / SUNWSPRO / SC5.0 / LIB -LSUNPERF -LF77 -LM77 -LSUNMATH -LMFC = F77

# Sun Solaris 2. [78] with / opt / sunwspro / ws6u1 (Compiled with fortren 90) Sunlib = -l / opt / sunwspro / ws6u1 / lib -l / opt / sunwspro / libf90libs = $ (sunlib) -lsunperf -LFUI -LFAI -LFAI2 -LFSUMAI / -LFPRODAI -LFMINLAI -LFMAXLAI -LFMINVAI -LFMAXVAI -LFSUFLIBS = $ (SunLib) -lsunperf -lsunmath -lmfc = f90

# Sun Solaris 2. [78] with / opt / sunwspro / ws6u2 (Compiled with fortren 90) Sunlib = -l / opt / sunwspro / ws6u2 / lib -l / opt / sunwspro / libf90libs = $ (sunlib) -lsunperf -LFUI -LFAI -LFAI2 -LFSUMAI / -LFPRODAI -LFMINLAI -LFMAXLAI -LFMINVAI -LFMAXVAI -LFSUFLIBS = $ (SunLib) -lsunperf -lsunmath -lmfc = f90

CCODE.O $ (CC) $ (cflags) -o ccode ccode.o $ (flibs) $ (ldflags)

Ccode.O: Ccode.c $ (cc) $ (cflags) -c ccode.c

Fcode: fcode.o $ (fc) -o Fcode Fcode.o $ (FLIBS) $ (LDFlags)

Shared vendor libraries are a nuisance if gcc, g , or g77 are used, because those compilers do not know about the location of some vendor-provided libraries, and except on IBM AIX, most UNIX linkers regrettably do not by default record the location of libraries used at link time. This means that even if linking succeeds, your program may fail to run because the run-time loader can not find the necessary libraries. One solution is to define the environment variable LD_LIBRARY_PATH (or LPATH on Hewlett-Packad HP- UX) to a colon-separated list of shared-library directory paths. This is hardly satisfactory, since each user who runs that executable must do the same, and, on SGI IRIX 6.x systems, there are three variants of that variable, depending on the memory model chosen. A better solution to this problem is to supply additional flags that instruct the linker to record the shared-library paths in the executable program. Unfortunately, these flags are highly compiler dependent (and not nee Ded at all ibm aix: ### compaq / dec compilers: ldflags = -wl, -rpath directory-path ### gnu compilers: ldflags = -wl, -rpath directory-path ### sgi compilers: ldflags = -YL, directory-path ### Sun compilers: LDFLAGS = -R directory-pathOnly one directory can be specified with each option, so you might need to do something like this: LDFLAGS = -Wl, -rpath / opt / SUNWspro / WS6U2 / LIB / -WL, -RPATH / OPT / SUNWSPRO / LIB

On some UNIX systems, you can use the ldd command to check whether your executable has recorded the location of all needed libraries (taking care to undefine LD_LIBRARY_PATH for the duration of the command):% env LD_LIBRARY_PATH = ldd fcode libF77.so.4 = > /Opt/sunwsprob/lib/libf77.so.4 libm77.so.2 => /opt/sunwsprob/lib/libm77.so.2 libsunmath.so.1 => /opt/sunwsprob/lib/libsunmath.so. 1 libm.so.1 => /opt/sunwspro/lib/libm.so.1 libc.so.1 => /usr/lib/libc.so.1 libdl.so.1 => / usr / lib / libdl .sso.1 /usr/platform/sunw ,ultra-enterprise/lib/libc_psr.so.1on Others, You'll Merely Be Told At Run Time That A Certain Library Cannot Be Found, Sigh ...

Related libraries: linpack and eispack here is some Old Related Mail: Date: Thu, 12 APR 2001 08:58:11 -0600 (MDT) from: "Nelson H. F. Beebe" to: Peter Alfeld Subject: Re: Linpack

>> do we have a double precision version of LINPACK Yes:? Unlike EISPACK, which used the same names for single and double precision, preventing using both flavors in one program, LINPACK and LAPACK both use a naming convention that identifies the precision:> From the emacs info path Local -> Linpack -> NAMING-CONVENTIONS:. NAMING-CONVENTIONS A subroutine naming convention is employed in which each subroutine name is a coded specification of the computation done by that subroutine All names consist of five letter in the form TXXYY. The First Letter, T, Indicates The Matrix Data Type. Standard fortran Allows the Use of Three Such Types:

S REAL D DOUBLE PRECISION C Complexin Addition, Some Fortran Systems (Alas, NOT The DEC-20!) Allow A Double Precision Complex Type:

Z Complex * 16

Thus, if you had, the double-precision version would be dgeco.f. Linpack Sources Are IN / USR / local / math / linpack /, AND Each System Has -llinpack Available for Linking. I Haven 'T Done That for lapack, But Most Vendors Have Tuned LAPACK IMPLEMENTATIONS AVAILABLE: Sun Solaris -lsunmath SGI IRIX -LCOMPLIB.SGIMATH COMPAQ / DEC OSF / 1 -LDXML AND -LSCIPORT IBM AIX -SSSL

We do not have such a standard library on GNU / Linux systems, but the Portland Group compilers (pgcc, pgCC, pghpf, pgf77, and pgf90) provide -llapack on wasatch.math.utah.edu, a 600MHz dual-CPU Intel x86 Pentium system III. Also, on all systems, we have -lnag, which includes LAPACK. In most cases, we can expect that the vendor implementations of LAPACK include highly-tuned BLAS levels 1, 2, and 3, to produce better performance . than a straightforward Fortran LAPACK compilation could produce IBM's ESSL is a shining example of this: you might enjoy reading this new article which is available in PDF form at the URL cited @String {j-IBM-JRD = "IBM Journal of Research. And development "}

@Article {Gustavson: 2000: MSH, author = "FG Gustavson and I. Jonsson", title = "Minimal-storage high-performance {Cholesky} factorization via blocking and recursion", journal = j-IBM-JRD, volume = " 44, Number = "6", Pages = "823--850", MONTH = NOV, YEAR = "2000", CODEN = "IBMJAE", ISSN = "0018-8646", BIBDATE = "SAT Feb 24 09: 44:45 MST 2001 ", BibSource =" http://www.research.ibm.com/journal/ ", URL =" http://www.research.ibm.com/journal /RD/446/gustavson.html ", ACKNOWLEDGEMENT = Ack-NHfb, ORDERNUMBER =" G322-0224 ",} You Should Also Look At http://www.math.utah.edu/software

Calendars? Contents? Dept info? Outreach? College of science? What's new?? Newsletter

Department of Mathematics University of Utah 155 South 1400 East, JWB 233 Salt Lake City, UTAH 84112-0090 Tel: 801 581 6851, Fax: 801 581 4148 WebMaster

- ☆ Source:. Green bbs.dartmouth.edu. [From: mars.bbs@bbs.dartmou]

转载请注明原文地址:https://www.9cbs.com/read-10980.html

New Post(0)