使用OpenMP如何让指定让处理器做相应的任务

avrilvv521 2011-11-26 01:47:26
我想将一个数组分块,每个处理器处理几行,那应该如何设定让某个处理器处理几行呢?这个编译指导语句应该如何写
...全文
367 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
intel_iclifort 2011-11-29
  • 打赏
  • 举报
回复
查一下OMP spec,parallel for 共有四种调度方式

static - Iterations are divided into chunks of size chunk_size, and
the chunks are assigned to the threads in the team in a
round-robin fashion in the order of the thread number.

dynamic - Each thread executes a chunk of iterations, then requests
another chunk, until no chunks remain to be distributed.

guided - Each thread executes a chunk of iterations, then requests
another chunk, until no chunks remain to be assigned.
The chunk sizes start large and shrink to the indicated
chunk_size as chunks are scheduled.

auto - The decision regarding scheduling is delegated to the
compiler and/or runtime system.
intel_iclifort 2011-11-29
  • 打赏
  • 举报
回复
首先必须明确的是,如果用parallel for的话,OMP 运行库自动生成的线程,在每个处理器/核上运行的程序代码是完全一样的, 区别只是在于原先的数组会根据下标变量分成几块,然后分配到不同的处理器/核上运行。

至于如何分配,缺省是平均分配,两个核就二分,四个核就各自按照顺序拿四分之一。 如果出现不同核负载不均衡,计算量不均的现象,可以考虑采用动态的分配方式

对于程序员而言,这个分配过程是透明的,一般情况下你只可以控制数据分配到某个OMP线程,而不是具体的物理的处理器/核。

当然,一些OMP 运行库的实现还可以支持处理器绑定(affinity),可以提高数据的局部性。但只能指定某个OMP线程运行在某个指定的操作系统提供的逻辑处理器/核 (OS Proc )上。 关于Intel OMP RTL 更详细的例子,可以参考 Intel Software Network: http://software.intel.com/en-us/articles/using-kmp_affinity-to-create-openmp-thread-mapping-to-os-proc-ids/ , 还有

http://software.intel.com/en-us/articles/intel-thread-affinity-environment-variable-for-openmp/

567

社区成员

发帖
与我相关
我的任务
社区描述
英特尔® 边缘计算,聚焦于边缘计算、AI、IoT等领域,为开发者提供丰富的开发资源、创新技术、解决方案与行业活动。
社区管理员
  • 英特尔技术社区
  • shere_lin
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧