parallel-processing - 将功能分配给多个任务
问题描述
我想使用 OpenMP 将子例程分配给不同的任务。在我的代码中,我实现了这个:
!$omp parallel
!$omp single
do thread = 1, omp_get_num_threads()
!$omp task
write(*,*) "Task,", thread, "is computing"
call find_pairs(me, thread, points)
call count_neighbors(me, thread, neighbors(:, thread))
!$omp end task
end do
!$omp end single
!$omp end parallel
子程序 find_neighbors 和 count_neighbors 进行一些计算。我之前在我的程序中设置了线程数:
nr_threads = 4
call omp_set_num_threads(nr_threads)
用 GNU Fortran (Ubuntu 8.3.0-6ubuntu1) 8.3.0 编译它并运行,只给了我一个线程,当用 top 监视时,运行速度接近 100%。尽管如此,它打印的权利
任务,1是计算
任务,2是计算
任务,3是计算
任务,4是计算
我使用以下方法编译它:
gfortran -fopenmp main.f90 -o program
我想要的是根据OpenMP线程的数量分配子程序的不同调用,并行工作。
据我了解,创建了一个线程来创建不同的任务。
解决方案
推荐阅读
- c - C/C++ 中的巴特沃斯 BP 滤波,奇怪的频谱
- c - 了解结构内部的结构
- json - json.loads 和 pickle.loads 不能与 async 关键字一起使用?
- python - 使用 pdfminer,代码会卡在命令解释器.process_page(page) 上,并且永远不会终止或抛出错误
- android - 当用户在 RecyclerView + PagerSnapHelper 上卡住滑动时,ScrollListener 代码无法按预期工作
- python - 使用时间序列数据预测故障
- ruby - 宝石更新不起作用
- c++ - 在 Linux 中链接时库冲突,但不是 OSX
- delphi - 如何在delphi中获得拉伸TImage的新尺寸
- php - 如何使用 html5、css3 和 php 创建交互式搜索栏,结果构建并返回一个新的组合页面?