OpenMP线程映射到物理核心 [英] OpenMP thread mapping to physical cores

查看:53
本文介绍了OpenMP线程映射到物理核心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我在网上四处逛逛已经无济于事了.我是使用OpenMP的新手,因此不确定此处的术语,但是是否有办法从OMPThread(由omp_get_thread_num();给出)以及运行线程的物理核心中找出特定计算机的映射? /p>

我还对OMP分配的线程的精确度感兴趣,例如,当在同一台计算机上运行相同的代码时,线程0是否总是在同一位置运行?谢谢.

解决方案

通常,操作系统负责为内核分配线程,包括使用OpenMP.这是设计使然,也是一件好事-您通常希望操作系统能够根据需要跨内核(对您的应用程序透明)移动线程,因为它有时会中断您的应用程序.

某些操作系统API将允许设置线程相似性.例如,在Windows上,您可以使用 SetThreadAffinityMask 将线程强制到特定的内核上.

So I've looked around online for some time to no avail. I'm new to using OpenMP and so not sure of the terminology here, but is there a way to figure out a specific machine's mapping from OMPThread (given by omp_get_thread_num();) and the physical cores on which the threads will run?

Also I was interested in how exactly OMP assigned threads, for example is thread 0 always going to run in the same location when the same code is run on the same machine? Thanks.

解决方案

Typically, the OS takes care of assigning threads to cores, including with OpenMP. This is by design, and a good thing - you normally would want the OS to be able to move a thread across cores (transparently to your application) as required, since it will interrupt your application at times.

Certain operating system APIs will allow thread affinity to be set. For example, on Windows, you can use SetThreadAffinityMask to force a thread onto a specific core.

这篇关于OpenMP线程映射到物理核心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆