python高性能计算:cython使用openmp并行 —— 报错:undefined symbol: omp_get_thread_num
test.pyx文件:
from cython.parallel cimport parallel
from openmp cimport omp_get_thread_num
cpdef void long_running_task1() noexcept nogil:
while True:
pass
cpdef void long_running_task2() noexcept nogil:
while True:
pass
def do_two_tasks():
cdef int thread_num
with nogil, parallel(num_threads=2):
thread_num = omp_get_thread_num()
if thread_num == 0:
long_running_task1()
elif thread_num == 1:
long_running_task2()
do_two_tasks()
cython的编译文件:
test_setup.py
from distutils.core import setup, Extension
from Cython.Build import cythonize
ext_modules = [
Extension(
"test",
["test.pyx"],
extra_compile_args=['-fopenmp'],
extra_link_args=['-fopenmp'],
)
]
setup(
name = 'test v1',
ext_modules = cythonize(ext_modules,
#compiler_directives={'language_level' : "3"}
# or "2" or "3str"
),
)
编译test.pyx:
python test_setup.py build_ext --inplace
报错:
undefined symbol: omp_get_thread_num
修改代码:添加一行内容:cimport openmp
cimport openmp
from cython.parallel cimport parallel
from openmp cimport omp_get_thread_num
cpdef void long_running_task1() noexcept nogil:
while True:
pass
cpdef void long_running_task2() noexcept nogil:
while True:
pass
def do_two_tasks():
cdef int thread_num
with nogil, parallel(num_threads=2):
thread_num = omp_get_thread_num()
if thread_num == 0:
long_running_task1()
elif thread_num == 1:
long_running_task2()
do_two_tasks()
问题解决:
运行效果:
成功达到200%的进程CPU使用率。
python高性能计算:cython使用openmp并行 —— 报错:undefined symbol: omp_get_thread_num的更多相关文章
- 关于 xcode 工程编译报错 undefined symbol _res_9_init的解决办法
将libresolv.dylib 添加到工程引用中(通过build phases中).补充: _res_9_init定义在resolv.h中,可以参考http://www.opensource. ...
- python中引入包的时候报错AttributeError: module 'sys' has no attribute 'setdefaultencoding'解决方法?
python中引入包的时候报错:import unittestimport smtplibimport timeimport osimport sysimp.reload(sys)sys.setdef ...
- 记一次用python 的ConfigParser读取配置文件编码报错
记一次用python 的ConfigParser读取配置文件编码报错 ...... raise MissingSectionHeaderError(fpname, lineno, line)Confi ...
- vue组件,通过props父组件给子组件传值,WTF, 子组件报错undefined???
如果是正常操作,找了半天又找不到为什么undefined, 那很可能是props的命名出了问题: 不要用小驼峰式命名 例如这种childrenData 这种形式就会报错undefined 请尽量用全 ...
- Apache配置压缩优化时报错——undefined symbol: inflateEnd
Apache配置压缩优化时报错——undefined symbol: inflateEnd 环境:CentOS 6.4 软件版本:httpd-2.4.6 apr-1.4.8 apr-util-1.5. ...
- Python“Non-ASCII character 'xe5' in file”报错问题(转)
今天在编译一个Python程序的时候,一直出现"Non-ASCII character 'xe5' in file"报错问题 SyntaxError: Non-ASCII char ...
- Appnium+python实现手势密码为什么总是报错
最近一直在尝试Appnium实现Android手机自动化测试,一直一直卡在一个点上,那就是手势密码,因为所测应用的手势密码使用的不是单个的imageview实现的手势密码解锁窗,所以只能靠坐标点来定位 ...
- python 基础之pickle 与json 报错问题解决方案
Python 基础之pickle与json 有没有在搞pickle与json在进行数据储存的时候老是报错,这个有些让人烦恼,在之前有一篇介绍过它们的基本用法以及在使用过长中避免一些坑,但是今天在把对象 ...
- python+Django+test 测试数据库生成报错
前提: 使用Django自带的test进行单元测试. 问题描述: 运行:python manage.py test,报错,出现数据库乱码的现象,报错如下: Creating test database ...
- Python“Non-ASCII character 'xe5' in file”报错问题
今天在编译一个Python程序的时候,一直出现“Non-ASCII character 'xe5' in file”报错问题 SyntaxError: Non-ASCII character '\xe ...
随机推荐
- 再谈中断机制(APIC)
中断是硬件和软件交互的一种机制,可以说整个操作系统,整个架构都是由中断来驱动的.一个中断的起末会经历设备,中断控制器,CPU 三个阶段:设备产生中断信号,中断控制器翻译信号,CPU 来实际处理信号. ...
- LeetCode 207. Course Schedule 课程表 (C++/Java)
题目: There are a total of n courses you have to take, labeled from 0 to n-1. Some courses may have pr ...
- 夜莺中心端管理categraf采集规则并下发
痛点 市面上常见的采集器,比如 telegraf.grafana-agent.datadog-agent 等,通常内置了多种采集插件,比如可以采集操作系统的常规指标,也可以采集 mysql.redis ...
- Future集合会等线程池执行完才开始遍历吗?
先说结论:Future集合并不是等线程池执行完才开始遍历,而是线程池内的线程执行完一条Future集合就立即遍历一条 在使用线程池的业务场景下,我们经常需要获取线程执行的返回值,此时我们需要Calla ...
- xshell和xftp远程SSH密钥连接腾讯云服务器
1.在腾讯云中创建密钥,关机,绑定. 2.xshell和xftp导入密钥,填写的用户名和密码验证是 腾讯云的主机的root和密码(关键,而不是创建密钥的用户名和密码),该密码可以重置.
- 简约博客新主题Sina上线 - 魔改新浪
Tips:当你看到这个提示的时候,说明当前的文章是由原emlog博客系统搬迁至此的,文章发布时间已过于久远,编排和内容不一定完整,还请谅解` 简约博客新主题Sina上线 - 魔改新浪 日期:2018- ...
- JAVA-poi导出excel到http响应流
导出结果为excel是相对常见的业务需求,大部分情况下只需要导出简单的格式即可,所以有许多可以采用的方案.有些方案还是很容易实现的. 一.可用的解决方案 目前可以有几类解决方案: 字处理企业提供的解决 ...
- 08-Linux计划任务
什么是计划任务 周期性或者定时执行某个命令或者脚本. crontab 安装 yum install crontabs #安装crontabs systemctl enable crond #开机启动 ...
- 基于.NET Core + Jquery实现文件断点分片上传
基于.NET Core + Jquery实现文件断点分片上传 前言 该项目是基于.NET Core 和 Jquery实现的文件分片上传,没有经过测试,因为博主没有那么大的文件去测试,目前上传2G左右的 ...
- 信奥一本通1164:digit函数
1164:digit函数 时间限制: 1000 ms 内存限制: 65536 KB 提交数:41504 通过数: 26475 [题目描述] 在程序中定义一函数digit(n,k) ,它能分离出整数n ...