link problem with a simple test program.

Post here if you have a question about linking your program with LAPACK or ScaLAPACK library

link problem with a simple test program.

Postby hdc1112 » Mon May 09, 2011 10:14 pm

Hi, this is my first time using CLAPACK, and the version is 3.2.1, my platform is Linux localhost.localdomain 2.6.35.6-45.fc14.x86_64 #1 SMP Mon Oct 18 23:57:44 UTC 2010 x86_64 x86_64 x86_64 GNU/Linux.

During my installation process, there is a problem:

cd TESTING; make

ZGG: Testing COMPLEX16 Nonsymmetric Generalized Eigenvalue Problem routines
./xeigtstz < zgg.in > zgg.out 2>&1
/bin/sh: line 1: 22252 segmentation fault (core dumped) ./xeigtstz < zgg.in > zgg.out 2>&1
make: *** [zgg.out] fault 139

I don't know whether this problem is the real cause for my following link problem, but maybe this information is helpful.

Although with the above testing problem, I still get blas_LINUX.a lapack_LINUX.a libcblaswr.a tmglib_LINUX.a, and I have correctly put them into /usr/local/lib, and put clapackh and f2c.h and blaswrap.h into /usr/local/include

then I tried to compile a simple program, but it has errors:

g++ clapacktest.cc -lcblas -lclapack -llibf2c

/usr/local/lib/libclapack.a(sgetrf.o): In function `sgetrf_':
sgetrf.c:(.text+0x45c): undefined reference to `f2c_strsm'
sgetrf.c:(.text+0x524): undefined reference to `f2c_sgemm'
/usr/local/lib/libclapack.a(sgetrs.o): In function `sgetrs_':
sgetrs.c:(.text+0x194): undefined reference to `f2c_strsm'
sgetrs.c:(.text+0x1cf): undefined reference to `f2c_strsm'
sgetrs.c:(.text+0x303): undefined reference to `f2c_strsm'
sgetrs.c:(.text+0x33e): undefined reference to `f2c_strsm'
/usr/local/lib/libclapack.a(sgetf2.o): In function `sgetf2_':
sgetf2.c:(.text+0x180): undefined reference to `f2c_isamax'
sgetf2.c:(.text+0x1ca): undefined reference to `f2c_sswap'
sgetf2.c:(.text+0x329): undefined reference to `f2c_sger'
sgetf2.c:(.text+0x3b5): undefined reference to `f2c_sscal'
collect2: ld return 1

what is the problem? thanks in advance ! and my program is pasted below FYI.

#include <iostream>
using namespace std;
extern "C"
{
#include <f2c.h>
#include <clapack.h>
}

int
main (void)
{
integer M = 3;
integer N = 1;
real a[9] = { 4, 3, 11, 2, -1, 0, -1, 2, 3 };
real b[3] = { 2, 10, 8 };
integer lda;
integer ldb;
integer INFO;
lda = M;
ldb = M;
integer ipiv[M];

sgesv_ (&M, &N, a, &lda, ipiv, b, &ldb, &INFO);
if (INFO == 0)
{
for (int i = 0; i < M; i++)
{
cout << b[i] << endl;
}
}
else
{
cout << "Failed." << endl;
}
return 0;
}
hdc1112
 
Posts: 8
Joined: Mon May 09, 2011 10:03 pm

Re: link problem with a simple test program.

Postby admin » Tue May 10, 2011 3:35 am

Hi,
Could you try changing the linking sequence and adding a BLAS library
The cblas is just a C wrapper, it needs a BLAS library.
Code: Select all
g++ clapacktest.cc -lclapack  -lcblas -lblas -llibf2c
admin
Site Admin
 
Posts: 501
Joined: Wed Dec 08, 2004 7:07 pm

Re: link problem with a simple test program.

Postby hdc1112 » Tue May 10, 2011 3:50 am

Thanks !
I put blas_LINUX.a to /usr/local/lib/libblas.a
and "g++ clapacktest.cc -lclapack -lcblas -lblas -llibf2c" works.
maybe this is a good start to CLAPACK, I'd like to try some matrix inversion program later. :)

admin wrote:Hi,
Could you try changing the linking sequence and adding a BLAS library
The cblas is just a C wrapper, it needs a BLAS library.
Code: Select all
g++ clapacktest.cc -lclapack  -lcblas -lblas -llibf2c
hdc1112
 
Posts: 8
Joined: Mon May 09, 2011 10:03 pm

Re: link problem with a simple test program.

Postby hdc1112 » Tue May 10, 2011 5:10 am

Could you please where is the guide documentation or programming tutorial for CLAPACK?
hdc1112
 
Posts: 8
Joined: Mon May 09, 2011 10:03 pm

Re: link problem with a simple test program.

Postby hdc1112 » Wed May 11, 2011 11:44 pm

sgemm_ can't be found. please help me how to solve this problem ..
My program first calculate the inversion of matrix A, and then calculate oldA * invertA.
the code before sgemm_ can be linked correctly.

[dachuan@localhost program]$ gcc large_matrix_invert.c -lclapack -lcblas -lblas -llibf2c -lm -Wall
/tmp/ccpP8lXp.o: In function `main':
large_matrix_invert.c:(.text+0x3a8): undefined reference to `sgemm_'
collect2: ld 返回 1
[dachuan@localhost program]$

thanks ! this is my program

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <time.h>

#include <f2c.h>
#include <clapack.h>

#define N 1000

real oldA[N*N];
real A[N*N];
real C[N*N];//for oldA * A

int main(void)
{
integer i, j, n;
integer lda, arows, acols;
//integer ipiv[4];
integer ipiv[N];
integer lwork;
integer info;
float work[N*N];

arows=acols=N;
lda=N;
memset(ipiv,0,sizeof(int)*N);
memset(work,0,sizeof(float)*N*N);
//memset(C,0,sizeof(float)*N*N);

srand(time(NULL));
for(i=0;i<N*N;i++)
{
A[i]=rand()%100;
oldA[i]=A[i];
}

printf("matrix A\r\n\r\n");
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
printf("A[%ld,%ld]:%f\t", i,j, A[j*N+i]);
printf("\r\n");
}

sgetrf_(&arows,&acols,A,&lda,ipiv,&info);
//sgetrf_(&arows,&acols,A,lda,ipiv,&info);
printf("\r\n\r\nmatrix A after sgetrf\r\n");
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
printf("A[%ld,%ld]:%f\t", i,j, A[j*N+i]);
printf("\r\n");
}
printf("\r\n\r\ninfo for sgetrf_:%ld\r\n\r\n", info);

//n=acols*arows;
n=N;
lda=N;
lwork=N*N;

sgetri_(&n,A,&lda,ipiv,work,&lwork,&info);
//sgetri_(&n,A,lda,ipiv,work,&lwork,&info);
printf("\r\n\r\nMatrix A after sgetri\r\n");
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
printf("A[%ld,%ld]:%f\t", i,j, A[j*N+i]);
printf("\r\n");
}
printf("\r\n\r\ninfo for sgetri_:%ld\r\n\r\n", info);


printf("\r\noldA * A = \r\n");
char c='n';
real alpha = 1.0;
real beta = 0.0;
sgemm_(&c,&c,&n,&n,&n,&alpha,oldA,&n,A,&n,&beta,C,&n);
for(i=0;i<N;i++)
{
for(j=0;j<N;j++)
printf("C[%ld,%ld]:%f\t", i,j, C[j*N+i]);
printf("\r\n");
}

return(0);
}
hdc1112
 
Posts: 8
Joined: Mon May 09, 2011 10:03 pm

Re: link problem with a simple test program.

Postby Julien Langou » Wed May 11, 2011 11:50 pm

Try to call sgemm or SGEMM instead of sgemm_.

If none of these works locate the libblas.a library and perform the command:
nm libblas.a | grep -i sgemm
and check which names comes out of that.

-JL
Julien Langou
 
Posts: 734
Joined: Thu Dec 09, 2004 12:32 pm
Location: Denver, CO, USA

Re: link problem with a simple test program.

Postby hdc1112 » Thu May 12, 2011 1:17 am

thanks, it's solved. the function's original name is f2c_sgemm, and I add #include <blaswrap.h>, then it's ok.
hdc1112
 
Posts: 8
Joined: Mon May 09, 2011 10:03 pm

Re: link problem with a simple test program.

Postby hdc1112 » Thu May 12, 2011 1:31 am

it seems the program is crazy fast, even under my fedora14@VMWare and not optmized BLAS, it only takes 0.6sec (620000clocks) to invert a 1000*1000 matrix... hope it's not an illusion.
hdc1112
 
Posts: 8
Joined: Mon May 09, 2011 10:03 pm

Re: link problem with a simple test program.

Postby Julien Langou » Thu May 12, 2011 8:41 am

I saw that you wrote a check at the end of your code.
What does it tell you?
Why don't you check that || I - A * inv(A) || is small enough?
If this number is small you can trust to have inv(A).

Numbers of operations for xGETRI is 4/3n^3, so with n=1,000 and t=.6s, you are performing at 2.22 GFlop/sec.

Cheers,
J
Julien Langou
 
Posts: 734
Joined: Thu Dec 09, 2004 12:32 pm
Location: Denver, CO, USA

Re: link problem with a simple test program.

Postby hdc1112 » Thu May 12, 2011 9:20 pm

my plan was checking every element in matrix A * inv(A), to make sure the diagonal element is 1, and the others 0.
When I tried to implement ||I - A*inv(A) || in lapack, I found it inconvenient finding a function who calculate the determinant of a matrix. is there a help file similar to javadoc to let me easily find every function's detail?

thanks for you huge help.
hdc1112
 
Posts: 8
Joined: Mon May 09, 2011 10:03 pm

Re: link problem with a simple test program.

Postby Julien Langou » Thu May 12, 2011 10:10 pm

The LAPACK function to compute the norm of a matrix is xLANGE. (In C do not forget to give the prototype of the function in the subroutine where you are using it.) If you prefer to check all the entires one by one, feel free to do so. J.
Julien Langou
 
Posts: 734
Joined: Thu Dec 09, 2004 12:32 pm
Location: Denver, CO, USA

Re: link problem with a simple test program.

Postby Julien Langou » Thu May 12, 2011 10:15 pm

You are using CLAPACK and single precision right? I am just remembering that the CLAPACK SLANGE function is kind of weird. I think that it returns a double. (The LAPACK SLANGE function returns a single.) One thing to be careful about. Julien.
Julien Langou
 
Posts: 734
Joined: Thu Dec 09, 2004 12:32 pm
Location: Denver, CO, USA

Re: link problem with a simple test program.

Postby hdc1112 » Thu May 12, 2011 10:29 pm

Julien Langou wrote:The LAPACK function to compute the norm of a matrix is xLANGE. (In C do not forget to give the prototype of the function in the subroutine where you are using it.) If you prefer to check all the entires one by one, feel free to do so. J.

good adivce, I will now add an "extern function prototype" in the subroutine.
hdc1112
 
Posts: 8
Joined: Mon May 09, 2011 10:03 pm

Re: link problem with a simple test program.

Postby faria2159 » Tue Jul 05, 2011 11:50 am

i have this kind of problem too. thanks all of them who answered the question. It helped me a lot.
faria2159
 
Posts: 1
Joined: Fri Jun 24, 2011 9:32 am

Re: link problem with a simple test program.

Postby lexybam » Wed Nov 23, 2011 7:53 am

Thank you to all that provided answers to the buging questions I was able to resolve my own issues as well using the information provided here. During my installation process, I got an error like this.:


ZGG: Testing COMPLEX16 Nonsymmetric Generalized Eigenvalue Problem routines
./xeigtstz < zgg.in > zgg.out 2>&1
/bin/sh: line 1: 22252 segmentation fault (core dumped) ./xeigtstz < zgg.in > zgg.out 2>&1
But I was able to resolve it now.
lexybam
 
Posts: 1
Joined: Sat Nov 19, 2011 11:46 am

Next

Return to Linking Problem

Who is online

Users browsing this forum: No registered users and 1 guest