cython - 一些标准 C 库数学运算不能与 noGIL 配合使用
问题描述
我有一个包含以下代码的 pyx 文件:
cimport cython
from libc.math cimport sqrt, abs
from libc.stdio cimport printf
from cython.parallel import prange
cdef double my_abs(double a):
return sqrt(a*a)
cpdef loop(int a):
cdef int i
cdef int sum = 0
for i in prange(a, nogil=True):
printf("%s %i %s %f\n", "The square root of ", i, " is ", sqrt(i))
#printf("%s %i %s %f\n", "The absolute value of ", i, " is ", abs(i))
#printf("%s %i %s %f\n", "The absolute value of ", i, " is ", my_abs(i))
return
当我取消注释循环中的两行中的任何一行时,它无法编译。
- 为什么当 sqrt、pow 等其他函数似乎与 nogil 一起使用时,libc.math abs 函数不能很好地发挥作用?
- 我必须向我的函数(和 .pxd 文件)添加什么才能使其成为 nogil?我已尝试在此页面https://lbolla.info/python-threads-cython-gil之后添加,但它仍然无法编译。
这个问题类似于:
提前致谢!
解决方案
推荐阅读
- android - 未使用 FirebaseInstanceId 获取令牌
- unity3d - Unity 2020 中的 BIM 模型裁剪问题
- python - Json 数据操作 (Discord.py)
- r - 合并名字/姓氏列并将名字更改为首字母
- ruby-on-rails - 在 Rails 视图中添加 css 类或 html 文本的最佳方法
- node.js - 如何在 react native 中复制 node.js 代码?
- ajax - Laravel 8 中的动态相关下拉菜单
- java - javac和JVM是一样的吗?我可以只使用 JRE 而不是 JDK 执行 file.class 吗?我怎样才能在 Windows 上做到这一点?
- sql-server - 我可以将可为空的列添加到 SQL Server 中的现有表吗
- python - Django不在视图上显示图像