Skip to content

Instantly share code, notes, and snippets.

@xianyi
Created February 12, 2013 16:31
Show Gist options
  • Save xianyi/4771129 to your computer and use it in GitHub Desktop.
Save xianyi/4771129 to your computer and use it in GitHub Desktop.
Test dgetrf. gcc -o test test_dgetrf.c -I OpenBLAS_install/include OpenBLAS_install/lib/libopenblas.a -lpthread -lgfortran
#include <stdio.h>
#include "cblas.h"
#include "lapacke.h"
int main(int argc, char* argv[])
{
int* ipiv;
int info;
int i, j;
int n;
double * m, *x, *y;
int LDB,LDA, N, NRHS;
char transp = 'N';
if(argc<2){
printf("Error\n");
return 1;
}
n=atoi(argv[1]);
printf("n=%d\n",n);
m=(double*)malloc(sizeof(double)*n*n);
x=(double*)malloc(sizeof(double)*n);
y=(double*)malloc(sizeof(double)*n);
ipiv=(int*)malloc(sizeof(int)*n);
for (i=0; i<n; ++i) {
x[i]=1.0;
for (j=0; j<n; ++j) {
m[i*n+j]=(rand()%100+1)/10.0;
// printf("m[%d,%d]=%lf\n",i,j, m[i*n+j]);
}
}
/* test cblas.h */
cblas_dgemv(CblasColMajor, CblasNoTrans, n, n, 1.0, m, n,
x, 1, 0.0, y, 1);
// for (i=0; i<n; ++i) printf("x[%d]=%lf\n",i, x[i]);
//for (i=0; i<n; ++i) printf("y[%d]=%lf\n",i, y[i]);
LDB=n;
LDA=n;
N=n;
NRHS=1;
info=0;
LAPACK_dgetrf(&N, &N, m, &LDA,ipiv, &info);
if (info != 0) fprintf(stderr, "dgetrf failure with error %d\n", info);
LAPACK_dgetrs(&transp, &N, &NRHS, m, &LDA, ipiv, y, &LDB, &info);
if (info != 0) fprintf(stderr, "failure with error %d\n", info);
// for (i=0; i<n; ++i) printf("%lf\n", y[i]);
return 0;
}
@vtjnash
Copy link

vtjnash commented Feb 13, 2013

I'm having trouble compiling this (return type mismatch?). Please advise. Truncated error messages are below:

from gcc:

In file included from test_dgetrf.c:3:0:                                  
lapacke.h:11654:1: error: conflicting types for 'sgetrf_'                 
In file included from common.h:550:0,                                     
                 from cblas.h:10,                                         
                 from test_dgetrf.c:2:                                    
common_interface.h:654:1: note: previous declaration of 'sgetrf_' was here
In file included from test_dgetrf.c:3:0:                                  
lapacke.h:11656:1: error: conflicting types for 'dgetrf_'                 
In file included from common.h:550:0,                                     
                 from cblas.h:10,                                         
                 from test_dgetrf.c:2:                                    
common_interface.h:655:1: note: previous declaration of 'dgetrf_' was here
In file included from test_dgetrf.c:3:0:                                  
lapacke.h:11658:1: error: conflicting types for 'cgetrf_'                 
In file included from common.h:550:0,                                     
                 from cblas.h:10,                                         
                 from test_dgetrf.c:2:                                    
common_interface.h:657:1: note: previous declaration of 'cgetrf_' was here
In file included from test_dgetrf.c:3:0:                                  
lapacke.h:11660:1: error: conflicting types for 'zgetrf_'                 
In file included from common.h:550:0,                                     
                 from cblas.h:10,                                         
                 from test_dgetrf.c:2:                               

from clang:

In file included from test_dgetrf.c:3:
./lapacke.h:11654:6: error: conflicting types for 'sgetrf_'
void LAPACK_sgetrf( lapack_int* m, lapack_int* n, float* a, lapack_int* lda,
     ^
./lapacke.h:10620:37: note: expanded from macro 'LAPACK_sgetrf'
#define LAPACK_sgetrf LAPACK_GLOBAL(sgetrf,SGETRF)
                                    ^
./lapacke_mangling.h:12:39: note: expanded from macro 'LAPACK_GLOBAL'
#define LAPACK_GLOBAL(lcname,UCNAME)  lcname##_
                                      ^
<scratch space>:62:1: note: expanded from macro 'sgetrf'
sgetrf_
^
./common_interface.h:654:14: note: previous declaration is here
int BLASFUNC(sgetrf)(blasint *, blasint *, float  *, blasint *, blasint *, blasint *);
             ^
./common.h:170:24: note: expanded from macro 'BLASFUNC'
#define BLASFUNC(FUNC) FUNC##_
                       ^
<scratch space>:389:1: note: expanded from macro 'sgetrf'
sgetrf_
^
In file included from test_dgetrf.c:3:
./lapacke.h:11656:6: error: conflicting types for 'dgetrf_'
void LAPACK_dgetrf( lapack_int* m, lapack_int* n, double* a, lapack_int* lda,
     ^
./lapacke.h:10621:37: note: expanded from macro 'LAPACK_dgetrf'
#define LAPACK_dgetrf LAPACK_GLOBAL(dgetrf,DGETRF)
                                    ^
./lapacke_mangling.h:12:39: note: expanded from macro 'LAPACK_GLOBAL'
#define LAPACK_GLOBAL(lcname,UCNAME)  lcname##_
                                      ^
<scratch space>:62:1: note: expanded from macro 'dgetrf'
dgetrf_
^
./common_interface.h:655:14: note: previous declaration is here
int BLASFUNC(dgetrf)(blasint *, blasint *, double *, blasint *, blasint *, blasint *);
             ^
./common.h:170:24: note: expanded from macro 'BLASFUNC'
#define BLASFUNC(FUNC) FUNC##_

@vtjnash
Copy link

vtjnash commented Feb 13, 2013

If I comment out the cblas header and call, it compiles:

jameson@JNash /c/Users/jameson/Desktop/julia-64966d6e8c
$ test.exe 100 && echo "good"
n=100
<crash>
jameson@JNash /c/Users/jameson/Desktop/julia-64966d6e8c
$ test.exe 10 && echo "good"
n=10
good

edit I am using openblas-v0.2.5, not develop (yet)

@vtjnash
Copy link

vtjnash commented Feb 13, 2013

The results are the same with the development version of openblas: I get a crash for n > 65.

@vtjnash
Copy link

vtjnash commented Feb 13, 2013

If I include cblas.h and the corresponding function (and remove lapacke.h), it does not crash, even with N=10000

@vtjnash
Copy link

vtjnash commented Feb 13, 2013

if i export OPENBLAS_NUM_THREADS=1, test.exe works, even with N=3000

I do not have pthreads, so I did not link against it

@xianyi
Copy link
Author

xianyi commented Feb 13, 2013

Hi @vtjnash ,

Download OpenBLAS develop branch.

make
make PREFIX=/your/path/OpenBLAS install

gcc -o test test_dgetrf.c -I /your/path/OpenBLAS/include /your/path/OpenBLAS/lib/libopenblas.a -lpthread -lgfortran

Xianyi

@vtjnash
Copy link

vtjnash commented Feb 13, 2013

OK. Before I had tried copying the headers directly, which failed as shown. make install worked to fix the headers.

I invoked make with the following command (on a linux box):
make CC="i686-w64-mingw32-gcc" FC="i686-w64-mingw32-gfortran" RANLIB="i686-w64-mingw32-ranlib" CFLAGS="-g" FFLAGS="-g -O2 " USE_THREAD=1 TARGET= DYNAMIC_ARCH=1 OSNAME=WINNT CROSS=1 BINARY=32

then i compiled the test code (on the host machine):
gcc -g -Wall -I. -L. test_dgetrf.c -o test.exe -m32 -lopenblas

I still get the segfault for N > 65

(gdb) r 100
Starting program: c:\users\jameson\desktop\julia-64966d6e8c\test.exe 100
[New Thread 31900.0x80f8]
[New Thread 31900.0x83c0]
[New Thread 31900.0x8678]
n=100
[New Thread 31900.0x85e0]

Program received signal SIGSEGV, Segmentation fault.
0x6d7e9243 in zupmtr_ () from c:\users\jameson\desktop\julia-64966d6e8c\libopenblas.dll
(gdb) bt
#0  0x6d7e9243 in zupmtr_ () from c:\users\jameson\desktop\julia-64966d6e8c\libopenblas.dll
#1  0x6cc2c9f6 in zupmtr_ () from c:\users\jameson\desktop\julia-64966d6e8c\libopenblas.dll
#2  0x6cc2c9f6 in zupmtr_ () from c:\users\jameson\desktop\julia-64966d6e8c\libopenblas.dll
#3  0x6cc2c9f6 in zupmtr_ () from c:\users\jameson\desktop\julia-64966d6e8c\libopenblas.dll
#4  0x6cc2c9f6 in zupmtr_ () from c:\users\jameson\desktop\julia-64966d6e8c\libopenblas.dll
#5  0x6c4d6996 in libopenblas!DLANSB () from c:\users\jameson\desktop\julia-64966d6e8c\libopenblas.dll
#6  0x0028fde0 in ?? ()
#7  0x004013fa in __tmainCRTStartup ()
#8  0x749033aa in KERNEL32!BaseCleanupAppcompatCacheSupport () from C:\Windows\syswow64\kernel32.dll
#9  0x0028ffd4 in ?? ()
#10 0x77149ef2 in ntdll!RtlpNtSetValueKey () from C:\Windows\system32\ntdll.dll
#11 0x7efde000 in ?? ()
#12 0x77149ec5 in ntdll!RtlpNtSetValueKey () from C:\Windows\system32\ntdll.dll
#13 0x004014e0 in WinMainCRTStartup ()
#14 0x7efde000 in ?? ()
#15 0x00000000 in ?? ()
(gdb) info reg
eax            0x3440   13376
ecx            0x92b80  600960
edx            0x8      8
ebx            0x8      8
esp            0xf6b74  0xf6b74
ebp            0xf6bb8  0xf6bb8
esi            0x28fde0 2686432
edi            0xffffc000       -16384
eip            0x6d7e9243       0x6d7e9243 <zupmtr_+13701139>
eflags         0x10202  [ IF RF ]
cs             0x23     35
ss             0x2b     43
ds             0x2b     43
es             0x2b     43
fs             0x53     83
gs             0x2b     43
(gdb)

@xianyi
Copy link
Author

xianyi commented Feb 23, 2013

Hi @vtjnash ,

I think you use Mingwin32 compiler. Could you try Mingw64?

Xianyi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment