缺少OpenMP功能:线程优先级 [英] Missing OpenMP feature: Thread Priority
问题描述
任何人都想一想. OpenMP功能可调节cpu肌肉以处理dumbbel.在我对openmp的研究中,我们无法设置线程优先级来执行功能强大的块代码.只有一种方法(_beginthreadex或具有5.参数的CreateThread函数)可以创建具有最高优先级的线程.
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.
以下是此问题的代码:
这是手动设置.
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 pls设置优先级.
I dont know if there was a way to setup priority with openmp pls inform us.
推荐答案
您可以在循环体内执行SetThreadPriority
,而无需OpenMP的特殊支持:
You can do SetThreadPriority
in the body of the loop without requiring special support from OpenMP:
for (...)
{
DWORD priority=GetThreadPriority(...);
SetThreadPriority(...);
// stuff
SetThreadPriority(priority);
}
这篇关于缺少OpenMP功能:线程优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!