Mathematica的库函数功能

Pla*_*iac 9 cuda gpu wolfram-mathematica linear-algebra numerics

我正在尝试使用CUSP作为Mathematica的外部线性求解器来使用GPU的强大功能.这是CUSP项目网页.我想问一下如何将CUSP与Mathematica集成.我相信你们中的许多人都有兴趣讨论这个问题.我认为编写输入矩阵然后将其提供给CUSP程序是不可取的.使用Mathematica LibrarayFunctionLoad将是一种更好的方法,可以将输入矩阵传输到基于GPU的求解器.直接从Mathematica提供矩阵和右侧矩阵的方法是什么?

这是一些CUSP代码片段.

#include <cusp/hyb_matrix.h>
#include <cusp/io/matrix_market.h>
#include <cusp/krylov/cg.h>

int main(void)
{
// create an empty sparse matrix structure (HYB format)
cusp::hyb_matrix<int, float, cusp::device_memory> A;

// load a matrix stored in MatrixMarket format
cusp::io::read_matrix_market_file(A, "5pt_10x10.mtx");

// allocate storage for solution (x) and right hand side (b)
cusp::array1d<float, cusp::device_memory> x(A.num_rows, 0);
cusp::array1d<float, cusp::device_memory> b(A.num_rows, 1);

// solve the linear system A * x = b with the Conjugate Gradient method
cusp::krylov::cg(A, x, b);

return 0;
}
Run Code Online (Sandbox Code Playgroud)

这个问题让我们有可能讨论Mathematica 8的编译功能.也可以调用MMA的mathlink接口主题.我希望这里的人们发现这个问题值得思考,有趣,值得思考.

BR

jfk*_*ein 1

如果你想使用 LibraryLink(LibraryFunctionLoad 用于访问动态库函数作为 Mathematica 下值),实际上没有太多讨论的空间,LibraryFunctions 可以接收机器双精度或机器整数的 Mathematica 张量,你就完成了。

Mathematica MTensor 格式是一个密集数组,就像您在 C 中自然使用的那样,因此如果 CUSP 使用其他格式,您将需要编写一些粘合代码来在表示之间进行转换。

有关完整详细信息, 请参阅LibraryLink 教程。

您需要特别注意“与 Mathematica 交互”页面中的“MTensors 内存管理”部分,并选择“共享”模式以仅通过引用传递 Mathematica 张量。