一个 LAPACKE 示例,可以gdb进 lapack fortran77源代码

一个 LAPACKE 示例,可以gdb进 lapack fortran77源代码_第1张图片

将lapack lib和示例代码都编译成为 debug 类型,

源文件: hello_dsyevd.c

/*
   DSYEVD Example.
   ==============

   Program computes all eigenvalues and eigenvectors of a real symmetric
   matrix A using divide and conquer algorithm, where A is:

     6.39   0.13  -8.23   5.71  -3.18
     0.13   8.37  -4.46  -6.10   7.21
    -8.23  -4.46  -9.58  -9.25  -7.42
     5.71  -6.10  -9.25   3.72   8.54
    -3.18   7.21  -7.42   8.54   2.51

   Description.
   ============

   The routine computes all eigenvalues and, optionally, eigenvectors of an
   n-by-n real symmetric matrix A. The eigenvector v(j) of A satisfies

   A*v(j) = lambda(j)*v(j)

   where lambda(j) is its eigenvalue. The computed eigenvectors are
   orthonormal.
   If the eigenvectors are requested, then this routine uses a divide and
   conquer algorithm to compute eigenvalues and eigenvectors.

   Example Program Results.
   ========================

 DSYEVD Example Program Results

 Eigenvalues
 -17.44 -11.96   6.72  14.25  19.84

 Eigenvectors (stored columnwise)
  -0.26   0.31  -0.74   0.33   0.42
  -0.17  -0.39  -0.38  -0.80   0.16
  -0.89   0.04   0.09   0.03  -0.45
  -0.29  -0.59   0.34   0.31   0.60
  -0.19   0.63   0.44  -0.38   0.48
*/
#include 
#include 
#include "lapacke.h"

/* Auxiliary routines prototypes */
extern void print_matrix( char* desc, int m, int n, double* a, int lda );

/* Parameters */
#define N 5
#define LDA N

/* Main program */
int main() {
        /* Locals */
        int n = N, lda = LDA, info;
        /* Local arrays */
        double w[N];
        double a[LDA*N] = {
            6.39,  0.00,  0.00,  0.00,  0.00,
            0.13,  8.37,  0.00,  0.00,  0.00,
           -8.23, -4.46, -9.58,  0.00,  0.00,
            5.71, -6.10, -9.25,  3.72,  0.00,
           -3.18,  7.21, -7.42,  8.54,  2.51
        };
        /* Executable statements */
        printf( " DSYEVD Example Program Results\n" );

        //      LAPACK_COL_MAJOR,  [N|V], [U|L],
        //lapack_int LAPACKE_dsyevd( int matrix_layout, char jobz, char uplo, lapack_int n, double* a, lapack_int lda, double* w );
        info = LAPACKE_dsyevd(LAPACK_COL_MAJOR,'V', 'U', n, a, lda, w);

        /* Check for convergence */
        if( info > 0 ) {
                printf( "The algorithm failed to compute eigenvalues.\n" );
                exit( 1 );
        }
        /* Print eigenvalues */
        print_matrix( "Eigenvalues", 1, n, w, 1 );
        /* Print eigenvectors */
        print_matrix( "Eigenvectors (stored columnwise)", n, n, a, lda );
        /* Free workspace */
        exit( 0 );
} /* End of DSYEVD Example */

/* Auxiliary routine: printing a matrix */
void print_matrix( char* desc, int m, int n, double* a, int lda ) {
        int i, j;
        printf( "\n %s\n", desc );
        for( i = 0; i < m; i++ ) {
                for( j = 0; j < n; j++ ) printf( " %6.2f", a[i+j*lda] );
                printf( "\n" );
        }
}

Makefile:

TOPSRCDIR = ../..
include $(TOPSRCDIR)/make.inc

.SUFFIXES: .c .o
.c.o:
        $(CC) $(CFLAGS) -I. -I../include -c -o $@ $<

.PHONY: all
all:hello_dsyevd

LIBRARIES = $(LAPACKELIB) $(LAPACKLIB) $(BLASLIB)

# Double Precision Examples

hello_dsyevd: hello_dsyevd.o $(LIBRARIES)
        $(FC) $(FFLAGS) $(LDFLAGS) -o $@ $^
        ./$@

.PHONY: clean cleanobj cleanexe
clean: cleanobj cleanexe
cleanobj:
        rm -f *.o
cleanexe:
        rm -f x*

借用了lapack本身的make.inc

####################################################################
#  LAPACK make include file.                                       #
####################################################################

SHELL = /bin/sh

#  CC is the C compiler, normally invoked with options CFLAGS.
#
CC = gcc
#LL:: CFLAGS = -O3
CFLAGS = -g

#  Modify the FC and FFLAGS definitions to the desired compiler
#  and desired compiler options for your machine.  NOOPT refers to
#  the compiler options desired when NO OPTIMIZATION is selected.
#
#  Note: During a regular execution, LAPACK might create NaN and Inf
#  and handle these quantities appropriately. As a consequence, one
#  should not compile LAPACK with flags such as -ffpe-trap=overflow.
#
FC = gfortran
#LL:: FFLAGS = -O2 -frecursive
FFLAGS = -g -frecursive
FFLAGS_DRV = $(FFLAGS)
FFLAGS_NOOPT = -O0 -frecursive

#  Define LDFLAGS to the desired linker options for your machine.
#
LDFLAGS =

#  The archiver and the flag(s) to use when building an archive
#  (library).  If your system has no ranlib, set RANLIB = echo.
#
AR = ar
ARFLAGS = cr
RANLIB = ranlib

#  Timer for the SECOND and DSECND routines
#
#  Default:  SECOND and DSECND will use a call to the
#  EXTERNAL FUNCTION ETIME
#TIMER = EXT_ETIME
#  For RS6K:  SECOND and DSECND will use a call to the
#  EXTERNAL FUNCTION ETIME_
#TIMER = EXT_ETIME_
#  For gfortran compiler:  SECOND and DSECND will use a call to the
#  INTERNAL FUNCTION ETIME
TIMER = INT_ETIME
#  If your Fortran compiler does not provide etime (like Nag Fortran
#  Compiler, etc...) SECOND and DSECND will use a call to the
#  INTERNAL FUNCTION CPU_TIME
#TIMER = INT_CPU_TIME
#  If none of these work, you can use the NONE value.
#  In that case, SECOND and DSECND will always return 0.
#TIMER = NONE

#  Uncomment the following line to include deprecated routines in
#  the LAPACK library.
#
#BUILD_DEPRECATED = Yes

#  LAPACKE has the interface to some routines from tmglib.
#  If LAPACKE_WITH_TMG is defined, add those routines to LAPACKE.
#
#LAPACKE_WITH_TMG = Yes

#  Location of the extended-precision BLAS (XBLAS) Fortran library
#  used for building and testing extended-precision routines.  The
#  relevant routines will be compiled and XBLAS will be linked only
#  if USEXBLAS is defined.
#
#USEXBLAS = Yes
#XBLASLIB = -lxblas

#  The location of the libraries to which you will link.  (The
#  machine-specific, optimized BLAS library should be used whenever
#  possible.)
#
BLASLIB      = $(TOPSRCDIR)/librefblas.a
CBLASLIB     = $(TOPSRCDIR)/libcblas.a
LAPACKLIB    = $(TOPSRCDIR)/liblapack.a
TMGLIB       = $(TOPSRCDIR)/libtmglib.a
LAPACKELIB   = $(TOPSRCDIR)/liblapacke.a

#  DOCUMENTATION DIRECTORY
# If you generate html pages (make html), documentation will be placed in $(DOCSDIR)/explore-html
# If you generate man pages (make man), documentation will be placed in $(DOCSDIR)/man
DOCSDIR       = $(TOPSRCDIR)/DOCS

运行:

一个 LAPACKE 示例,可以gdb进 lapack fortran77源代码_第2张图片

使用gdb来单步追踪 fortran代码:

一个 LAPACKE 示例,可以gdb进 lapack fortran77源代码_第3张图片 

 

你可能感兴趣的:(算法,c语言,开发语言)