问题描述
我一直在探索需要对矩阵进行一些工作的算法,我已经在我的Linux机器上得到了一些简单的代码。下面是一段摘录:
I have been exploring algorithms that require some work on matrices, and I have gotten some straightforward code working on my Linux machine. Here is an excerpt:
extern "C" {
// link w/ LAPACK
extern void dpptrf_(const char *uplo, const int *n, double *ap, int *info);
extern void dpptri_(const char *uplo, const int *n, double *ap, int *info);
// BLAS todo: get sse2 up in here (ATLAS?)
extern void dgemm_(const char *transa, const char *transb, const int *m,
const int *n, const int *k, const double *alpha, const double *a,
const int *lda, const double *b, const int *ldb, const double *beta,
double *c, const int *ldc);
}
// in-place: be sure that (N*(N+1)/2) doubles have been initialized
inline void invert_mat_sym_packed(double *vd, int n) {
int out = 0;
dpptrf_("U",&n,vd,&out);
ASSERT(!out);
dpptri_("U",&n,vd,&out);
ASSERT(!out);
}
// use with col-major ordering!!!
inline void mult_cm(double *a, double *b, double alpha, int m, int k, int n, double *c) {
int lda = m, ldb = k, ldc = m; double beta = 1.0;
dgemm_("N","N",&m,&n,&k,&alpha,a,&lda,b,&ldb,&beta,c,&ldc);
}
所有我需要做的是 sudo apt-get安装liblapack
,并链接库。
all I had to do was sudo apt-get install liblapack
, and link against the library.
我现在试图让这个代码从MinGW使用32位的dll从,但我看到segfaults和无效的输出。我将继续使用gdb来确定错误的位置,但我怀疑有一个更好,更清洁,更便携的方式来完成这个。
I am now trying to get this code working from MinGW using the 32-bit dll's from here but I am seeing segfaults and invalid output. I will proceed with gdb to determine the location of the error but I suspect there's a better, cleaner, more portable way to get this done.
我做了什么,编译是安装fortran mingw( mingw-get install fortran
)并链接到32位BLAS和LAPACK DLL从早期的链接。
What I did to get it to compile was install fortran for mingw (mingw-get install fortran
) and link to the 32bit BLAS and LAPACK dll's from the earlier link.
我不知道我在这里丢失了多少...当用gcc编译win32编码时,其他人怎么会得到他们的LAPACK?
I'm not sure how much I'm missing here... How does everybody else get their LAPACK going when coding with gcc for win32?
我要找的是一个易于使用的C接口。我不想在所有的地方包装类。
What I'm looking for is an easy-to-use C interface. I don't want wrapper classes all over the place.
我试图找到一个英特尔MKL的下载...甚至是免费软件吗?
I tried to find a download for Intel MKL... Ain't even free software!?
推荐答案
我解决了这个问题。它与我调用例程的方式无关,我没有在将值累加到它们之前将 memset
我的缓冲区设置为零。
I solved the problem. It had nothing to do with the way I was calling the routines, I failed to memset
my buffers to zero prior to accumulating values onto them.
调用fortran例程基本上和从Linux做的一样简单。
Calling fortran routines is basically just as straightforward as it is to do from Linux.
但是,另一个相当严重的问题出现了:一旦我使用lapack例程,我的程序不再处理异常。请参见。
However, another rather serious problem has appeared: Once I use the lapack routines my program no longer handles exceptions. See here.
这篇关于LAPACK在Win32上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!