Quantcast
Channel: Intel® oneAPI Math Kernel Library & Intel® Math Kernel Library
Viewing all articles
Browse latest Browse all 2652

using gcc compile this sample program

$
0
0

I am testing a program which diagnalize a hermitian matrix, using LAPACKE_zheev function describe in the MKL manual.

When I try to compile this program, using gcc myprogram.c command. I got an error message saying that:

 /tmp/cc4Xdq1R.o: In function `diag':

zheev_mkl.c:(.text+0x3c): undefined reference to `LAPACKE_zheev'

collect2: ld returned 1 exit status

I don't know how to solve this problem. I have used fortran zheev(F77) and heev(F90) before, and I succeed in compiling the program. In fortran program I use ifort compiler when using F77 interface I just type ifort myprogram.f . Using F90 interface I have a Makefile which is complicated and not written by myself. I will paste that to provide more information to you.

By the way, in my Unbuntu system, I have only installed the intel fortran composer, i didn't install any C compiler other than gcc and g++.

Here is my C program I want to compile:

 

#include    <complex.h>
#include    <math.h>
#include    <stdlib.h>
#include    <stdint.h>
#include    <stdio.h>
#include    <mkl.h>

lapack_int LAPACKE_zheev( int matrix_order, char jobz, char uplo, lapack_int n, lapack_complex_double* a, lapack_int lda, double* w );
//hermitian matrix, each row in output is an eigenvector, the input matrix is stored in column-major
void    diag(lapack_complex_double *mat, double *e, lapack_int n)
{
    char    jobz='V';   //also eigenvectors
    char    uplo='U';   //upper triangle
    lapack_int  info;

    info=LAPACKE_zheev(n,jobz,uplo,n,mat,n,e);
    if(info!=0){
        printf("matrix diag fail\n");
        exit(1);
    }

}

int main()
{
    lapack_complex_double *mat;
    double  *e;

    mat=(lapack_complex_double *)malloc(sizeof(lapack_complex_double)*16);
    e=(double *)malloc(sizeof(double)*4);

    mat[0].real=1.0;    mat[0].imag=0.0;
    mat[1].real=1.0;    mat[1].imag=-1.0;
    mat[2].real=1.0;    mat[2].imag=-2.0;
    mat[3].real=1.0;    mat[3].imag=-3.0;
    mat[4].real=1.0;    mat[4].imag=1.0;
    mat[5].real=2.0;    mat[5].imag=0.;
    mat[6].real=1.0;    mat[6].imag=-4.0;
    mat[7].real=1.0;    mat[7].imag=-5.0;
    mat[8].real=1.0;    mat[8].imag=2.0;
    mat[9].real=1.0;    mat[9].imag=4.0;
    mat[10].real=3.0;   mat[10].imag=0.;
    mat[11].real=1.0;   mat[11].imag=-6.0;
    mat[12].real=1.0;   mat[12].imag=3.0;
    mat[13].real=1.0;   mat[13].imag=5.0;
    mat[14].real=1.0;   mat[14].imag=6.0;
    mat[15].real=4.0;   mat[15].imag=0.;

    diag(mat,e,4);

    printf("the eigenvalue is %f,%f,%f,%f\n",e[1],e[2],e[3],e[4]);
    printf("");

    free(mat);
    free(e);
}

 

And Here is my fortran Makefile which I think may provide some useful information:

NAME=zg
OBJECTS = $(NAME).f90
cc = ifort
MKLPATH=/opt/intel/composer_xe_2013.5.192/mkl/lib/intel64
MKLINCLUDE=/opt/intel/composer_xe_2013.5.192/mkl/include
MODPATH=/opt/intel/composer_xe_2013.5.192/mkl/include/intel64/lp64
FLAGS= -module $(MODPATH) \
 -assume byterecl -L$(MKLPATH) -I$(MKLINCLUDE)  -I$(MODPATH) -lmkl_lapack95_lp64 -lmkl_blas95_lp64  -Wl,--start-group $(MKLPATH)/libmkl_intel_lp64.a $(MKLPATH)/libmkl_intel_thread.a $(MKLPATH)/libmkl_core.a -Wl,--end-group -liomp5 -lpthread

OUTNAME=zg.out

$(NAME): $(OBJECTS)
    $(cc) -o $(OUTNAME) $(OBJECTS) $(FLAGS)
clean:
    rm -f $(OUTNAME)

 

Thanks for you help in advance.


Viewing all articles
Browse latest Browse all 2652

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>