对 C 中链接库中的函数进行并行计算
我是并行计算和寻找选项和技巧的新手。
我当前的问题是找到 B = AX 类型的 232 个独立线性方程;其中 A[8x8]、B[8x1] 和 X[8x1] 的尺寸; A 是稠密矩阵。
我在 Intel core 7i 处理器、4 核、8 线程和 Mac 机器上按顺序使用 CLAPACK - zgelss 函数。
此外,我的矩阵大小似乎足够小,可以使用内部优化。
我想在这个循环上应用并行性:
for (n = 0; n < 2^32; n++)
{...}
我想问我有什么选择来做到这一点。
有一些人建议使用 OpenMP,但是在阅读了 OpenMP 后,我发现我们无法将 OpenMP 指令应用于部分代码这是预编译的。
如果我们这样做,它可以工作,但可能不安全,因为您无法将预编译函数内的临时变量私有化。 {请评论正确/错误/其他}
所以我想问一下如果可能的话,如何做到这一点。 一些技巧....任何东西...
I am new to parallel computing and searching for options and tricks.
My present problem is to find 232 independent linear equations of type B = AX; where dimensions of A[8x8], B[8x1] and X[8x1]; A is a Dense matrix.
I am using CLAPACK - zgelss function for this in a sequential order on a Intel core 7i processor, 4 core, 8 thread and a Mac machine.
Further it seems my matrix size is small enough to use internal optimization.
I want apply a parallelism over this the loop:
for (n = 0; n < 2^32; n++)
{...}
I want to ask what are my options to do that.
A few people suggested use OpenMP, but after reading about OpenMP I found out that we cannot apply OpenMP directives to the part of code which is precompiled.
If we do so, it works but it might not be safe because you can not privatize the temporary variables inside the precompiled functions.
{Please comment right/wrong/other}
So I want to ask how it can be done, if it is possible.
Some tricks.... anything...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确实,除非您知道要调用的库是线程安全的,否则您不能只对它进行线程调用。但是,从 Lapack 3.3 开始,所有 lapack 调用都是线程安全的(尽管如果如果您使用不同的底层 BLAS 包来驱动 lapack 例程,则必须确保它们也是线程安全的)。 Clapack 只是 lapack 调用的一层薄薄的包装器;它们应该是线程安全的[编辑:这是错误的,正如下面 janneb 所指出的; Clapack 是旧版本 Lapack 的直接自动 C 翻译,因此它可能不是线程安全的],但如果您在文档中找不到任何有关它的内容,那么它足够简单(如果有点繁琐)来调用直接使用 Fortran 例程。
另一种方法是在不同的进程而不是线程中进行各种函数调用。这需要多做一点,但很容易。规范的方法是使用 MPI - 它具有一定的优势,但在这种情况下可能有点过头了。
It's true that unless you know the library you want to call is thread-safe, you can't just thread calls to it. However, as of Lapack 3.3, all lapack calls are threadsafe (although if you're using a different underlying BLAS package to power the lapack routines, you'll have to make sure they too are threadsafe). Clapack is just a thin layer of wrappers around lapack calls; they ought to be threadsafe [Edit: This is wrong, as pointed out by janneb below; Clapack is a direct automatic C translation of an older version of Lapack, so it's likely not threadsafe] , but if you can't find anything about it in the documentation to be sure, it's straightforward enough (if a little fiddly) to call the Fortran routines directly.
The alternative would be to make the various function calls in different processes, rather than threads. That takes a bit more doing, but it's easy enough. The canonical way would be using MPI - which has certain advantages but may be somethig of overkill in this case.
在 Jonathan 和 janneb 提供的信息的帮助下,我能够使用 openMP 成功地并行化函数 zgelss。
我使用 LAPACK 3.3 并创建了自己的 FORTRAN 到 C 的接口。
with the help of information provided by Jonathan and janneb I am able to parallelize over the function zgelss successfully, using openMP.
I used LAPACK 3.3 and created my own FORTRAN to C interface.