1
votes

**EDIT including update at the end of the question.

When I try to use dsymm from LAPACKE, I get a "linker command failed" error. (So, probably I am compiling the code wrong?) Here is the code in question:

#include "matrix_multiplication_attempt.h"
#include <stdio.h>
#include "lapacke.h"
int main ( )
{

/* 3x3 A matrix (symmetric) */
double a[] = {1,2,6,
              2,3,1,
              6,1,4};
/* 3x3 B Matrix */
double b[] = {2,3,4,
              3,6,7,
              4,7,4};
/* 3x3 C Matrix */
double c[] = {0,0,0,
              0,0,0,
              0,0,0};


char side, uplo;
int M,N, lda, ldb, ldc;
double alpha, beta,info;

side= 'L';
uplo='L';
M=3;
N=3;
alpha=1.0;
beta=0.0;
lda=3;
ldb=3;
info=8.0;

info=cblas_dsymm(side, uplo,
              M,N, alpha, a,lda,
              b,ldb,beta,c,ldc);
return info;

And here is the error I get:

matrix_multiplication_attempt.c:51:10: warning: implicit declaration of function 'lapacke_dsymm' is invalid in C99 [-Wimplicit-function-declaration] info=lapacke_dsymm(side, uplo, ^ 1 warning generated. Undefined symbols for architecture x86_64: "_lapacke_dsymm", referenced from: _main in matrix_multiplication_attempt-e2c0b9.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

I'm not experienced with C, so there is probably a simple mistake. Any insight is greatly appreciated.

EDIT: Thank you, francis, the issue was that dsymm is not part of LAPACK, but in BLAS and your solution works. Now, my updated question is: how can I link LAPACKE so that I can use both LAPACKE and BLAS routines in the same file? One of my attempts at compiling is:

gcc matrix_multiplication_attempt.c -o matrix_multiplication_attempt -lblas -Wall -I/usr/local/opt/lapack/include -L/usr/local/opt/lapack/lib/ -llapacke

but this gives the error Undefined symbols for architecture x86_64: "_cblas_dsymm", referenced from: _main in matrix_multiplication_attempt-76b8f6.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

1
well, considering that this post is the only occurrence ever in the web for LAPACKE_dsymm I very much suspect this is a typo!Antti Haapala -- Слава Україні
Wait, maybe you're right. Maybe it should be CBLAS_dsymm? But even when I do that, I get a linker error.Confused_physicist
well please add that into your question. I am not a Lapack user nor a physicist, confused or not, but as far as I could Google, dsymm wasn't exported by lapacke.Antti Haapala -- Слава Україні
Okay, I've updated my question. And, yes, it's probably for the best one of us isn't confused. Thanks for your help.Confused_physicist
I suspect that the directory /usr/local/opt/lapack/lib/ contains a blas library which does not contains cblas. If there is a cblas library, try to link against it. It may not be the case. Indeed, if Lapack has been compiled by cmake, the CmakeLists.txt contains option(CBLAS "Build CBLAS" OFF) : the default mode is to build Lapack and Lapacke without compiling cblas. Hence, to build the makefile and recompile Lapack with cblas, you can use something like cmake -DCBLAS=ON.francis

1 Answers

0
votes

Contrary to dsyev, the routine dsymm is not in the Lapack library. Indeed, it is implemented in the Blas library, in BLAS/SRC/dsymm.f. As a consequence, there is no interface to this routine in LAPACKE.

The best alternative for C programs is to link to CBLAS and use cblas_dsymm().

Here is a sample code:

#include<stdio.h>
#include<math.h>
#include<complex.h>
#include "cblas.h"

int main ( int argc, char **argv ){
    int i,j;

    int m=2;
    int n=3;
    double alpha=1.0;
    double beta=1.0;
    double AA[2][2]={{2,0},{0,1}};
    double BB[2][3]={{1,0,0},{1,0,0}};
    double CC[2][3]={{1,0,0},{1,0,0}};
    int lda=2;
    int ldb=n;
    int ldc=n;
    cblas_dsymm(CblasRowMajor,CblasLeft ,CblasUpper,m,n,alpha, &AA[0][0], lda, &BB[0][0], ldb, beta, &CC[0][0], ldc);

    for(i=0;i<m;++i)
    {
        for(j=0;j<n;++j)
            printf("%lf " ,CC[i][j]);
        printf("\n");
    }
    return 0;
}

I am surprized to see that I compiled it successfully by: gcc main.c -o main -lblas -Wall . Indeed, I though it was necessary to link cblas by gcc main.c -o main -lcblas -lblas -Wall but not in my case.