简体   繁体   English

culagesvd()在CULA

[英]culagesvd() in CULA

I want to use the culadgesvd() function to compute SVD for a matrix. 我想使用culadgesvd()函数来计算矩阵的SVD。 It is not clear for me how to actually use it in C/C++ with the info in the documentation. 我不清楚如何使用文档中的信息在C / C ++中实际使用它。 Could anyone give me a complete small C program, a template, to show how basically the function is used? 任何人都可以给我一个完整的小C程序,一个模板,以显示该函数的基本使用方式吗? Just a couple of lines (with stuff like culaInitialize() and culaShutdown() ) will do, I just need to see how this function can run without error. 只需几行(使用culaInitialize()culaShutdown()类的东西),我只需要看看这个函数如何运行而不会出错。

I thought that SVD is not included in the free version (it is though). 我认为SVD不包含在免费版本中(尽管如此)。 Below is an example for a QR decomposition. 以下是QR分解的示例。 Put this in a .cpp file: 把它放在.cpp文件中:

#include<cula.h>
#include<iostream>

int main()
{       
    float x[] = {1, 2, 3, 4};
    int n_rows = 2, n_cols = 2;
    float scale[n_cols];

    culaInitialize();   
    culaSgeqrf(n_rows, n_cols, &(x[0]), n_rows, &(scale[0]));
    culaShutdown();

    for(int ii = 1; ii < n_rows; ii++)
    {
        for(int jj = 0; jj < n_cols; jj++)
        {
            if(ii > jj) { x[ii + jj * n_rows] *= scale[jj]; }
        }
    }

    for(int ii = 0; ii < n_rows * n_cols; ii++)
    {
        std::cout << x[ii] << std::endl;
    }

    return 0;
}

and compile it using: 并使用以下方法编译它

g++ -fPIC -c -I/usr/local/cula/include -Wl,-rpath,/usr/local/cula/lib64 -L/usr/local/cula/lib64 -lcula_lapack_basic gpuQR.cpp
g++ -o gpuQR gpuQR.o -Wl,-rpath,/usr/local/cula/lib64 -L/usr/local/cula/lib64 -lcula_lapack_basic

Then call the program using: 然后使用以下方法调用程序

./gpuQR
-2.23607
0.894427
-4.91935
-0.894427

Check my post about CULA and Rcpp here . 在这里查看我关于CULA和Rcpp的帖子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM