缺少 OpenMP 功能:线程优先级
任何人都想想吧。 OpenMP 具有调整 CPU 能力来处理哑铃的功能。 在我对 openmp 的研究中,我们无法设置线程优先级来以强大的力量执行块代码。 5. 只有一种方法(_beginthreadex 或带参数的 CreateThread 函数)来创建具有最高优先级的线程。
这里有一些解决这个问题的代码:
这是手动设置。
int numberOfCore = ( execute __cpuid to obtain number of cores on your cpu ).
HANDLES* hThreads = new HANDLES[ numberOfCore ];
hThreads[0] = _beginthreadex( NULL, 0, someThreadFunc, NULL, 0, NULL );
SetThreadPriority( hThreads[0], HIGH_PRIORITY_CLASS );
WaitForMultipleObjects(...);
这是我想看这部分:
#pragma omp parallel
{
#pragma omp for ( threadpriority:HIGH_PRIORITY_CLASS )
for( ;; ) { ... }
}
或者
#pragma omp parallel
{
// Generally this function greatly appreciativable.
_omp_set_priority( HIGH_PRIORITY_CLASS );
#pragma omp for
for( ;; ) { ... }
}
我不知道是否有办法使用 openmp 设置优先级,请通知我们。
Anyone think about it. OpenMP features to adjust cpu muscles to handle dumbbel. In my research for openmp we cannot set thread priority to execute block code with powerfull muscle. Only one way(_beginthreadex or CreateThread function with 5. parameters) to create threads with highest priority.
Here some code for this issue:
This is manual setting.
int numberOfCore = ( execute __cpuid to obtain number of cores on your cpu ).
HANDLES* hThreads = new HANDLES[ numberOfCore ];
hThreads[0] = _beginthreadex( NULL, 0, someThreadFunc, NULL, 0, NULL );
SetThreadPriority( hThreads[0], HIGH_PRIORITY_CLASS );
WaitForMultipleObjects(...);
Here is i want to see this part:
#pragma omp parallel
{
#pragma omp for ( threadpriority:HIGH_PRIORITY_CLASS )
for( ;; ) { ... }
}
Or
#pragma omp parallel
{
// Generally this function greatly appreciativable.
_omp_set_priority( HIGH_PRIORITY_CLASS );
#pragma omp for
for( ;; ) { ... }
}
I dont know if there was a way to setup priority with openmp pls inform us.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在循环体中执行
SetThreadPriority
操作,而不需要 OpenMP 的特殊支持:You can do
SetThreadPriority
in the body of the loop without requiring special support from OpenMP:简单的测试揭示了意想不到的结果:
我在 Visual Studio 2010 (Windows 7) 中运行了一个简单的测试:
输出为:
说明:
OpenMP 主线程以主线程的优先级执行。
其他 OpenMP 线程保留普通优先级。
手动设置 OpenMP 线程的线程优先级时,线程将保持该优先级。
Simple test reveals unexpected results:
I have run a simple test in Visual Studio 2010 (Windows 7):
The output is:
Explanation:
The OpenMP master threads is executed with the thread priority of the main.
The other OpenMP threads are left in Normal priority.
When manually setting the thread priority of OpenMP threads, the threads remains with that priority.