For some reason, my previous implementation wasn't giving understandable results in lapacke, after having been running it correctly under lapack. Using Matlab as a check, I'd try running row major implementation of dgesv and get garbage, even though column major settings would check off with Matlab. Needless to say, it was frustrating. Attached is my older code
- Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
//#include <cblas.h>
#include <lapacke.h>
double A[36] =
{
4, 3, 0, 4, 0, 3,
2, 3, 3, 2, 2, 0,
0, 3, 2, 2, 0, 3,
3, 3, 2, 3, 0, 0,
1, 2, 3, 4, 0, 2,
2, 4, 2, 4, 3, 2
};
double C[24] =
{
34, 36, 33, 39,
33, 18, 26, 23,
28, 24, 17, 23,
30, 22, 29, 21,
31, 32, 24, 28,
44, 32, 35, 44
};
double B[24] =
{
2, 2, 3, 2,
4, 0, 3, 1,
3, 2, 1, 0,
2, 4, 3, 4,
2, 0, 1, 4,
2, 4, 0, 4
};
void eq_solve(double *a, double *b, int n, int m)
{
int info, i;
int lda, ldb, *ipiv;
lda = n;
ldb = n;
ipiv = malloc(sizeof(int)*n);
info = LAPACKE_dgesv(LAPACK_ROW_MAJOR, n, nrhs, a, lda, ipiv, b, ldb);
if (info != 0)
{
fprintf(stderr, "dgesv: info = %d\n", info);
}
assert(info==0);
free(ipiv);
}
int main(void)
{
eq_solve(A,C,6,4);
// Print and compare B and C here
return 0;
}
This was compiled with the lapacke.h header and the libraries in folder under command: gcc test.c -I../include lapacke.a -llblas -llapack
The garbage answer that I kept getting was:
14.2353, 14.1176, 9.17647, 14.4118,
33, 18, 5.48416, 4.97285,
14.8824, 5.90498, 17, 23,
8.85068, 6.88688, 4.17647, 6.10407,
31, 32, -17.6199, -14.3484,
-12.1765, -13.7195, 35, 44,
After extensive research, I stumbled onto a file from intel's MKL website.
http://software.intel.com/sites/product ... _row.c.htm
I was doing a direct translation of my old Lapack call to the Lapacke call without considering col-major to row-major. LDB is no longer equal to n. Instead it is nrhs now. *facepalm*
Aside from that, I spent a good deal of timing trying to get both Lapacke and Cblas working for my C code so that all my matrices can now be supported in row major form. No more pre and post processing of transposing matrices :).
I got it to work, but not without a bunch of initial errors. For some reason, my makefile MUST link the libraries in a specific order - that is :
- Code: Select all
LDLIBS := -lm -lgfortran -lmetis -lpthread -lcblas_LINUX -llapacke_LINUX -llapack_LINUX -lblas_LINUX
Switching the order always results in some undefined reference to dgemm_ or dgetrf_ or something like this: http://icl.cs.utk.edu/lapack-forum/viewtopic.php?f=2&t=1669 .
I hope this helps.

