LAPACK on Win32

寵の児 提交于 2019-12-01 12:44:14

问题


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);
}

all I had to do was sudo apt-get install liblapack, and link against the library.

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.

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.

I'm not sure how much I'm missing here... How does everybody else get their LAPACK going when coding with gcc for win32?

What I'm looking for is an easy-to-use C interface. I don't want wrapper classes all over the place.

I tried to find a download for Intel MKL... Ain't even free software!?


回答1:


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.

Calling fortran routines is basically just as straightforward as it is to do from Linux.

However, another rather serious problem has appeared: Once I use the lapack routines my program no longer handles exceptions. See here.



来源:https://stackoverflow.com/questions/8640351/lapack-on-win32

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!