简体   繁体   中英

Set open mp threads for use 80% CPU

I am working on c++ loop and would like set threads for it use 80~85% of CPU. Example of loop:

#pragma omp parallel
    {
#pragma omp  for schedule (dynamic) 
        for (int i = 0; i < 1000000000; i++) {
            for (int j = 0; j < 10000000000; j++) {
                int toto = i + j;
            }
        }
    }
}

I want it work for all CPU, have you any suggestion?

Since you said you're on Windows, you need to get the thread handle, then use

int GetThreadPriority(HANDLE hThread);

system call, which returns a thread priority running, I think, from -15 to 15. Then call

BOOL SetThreadPriority(HANDLE hThread, int nPriority);

to set the new priority.

Higher priority numbers mean more CPU time is dedicated to that thread.

I haven't heard of an ability to set thread priority through OpenMP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM