Config : Windows 10, mingw-x64, Core 2 (4 logical)
The following code
#include <cstdio>
#include <omp.h>
#include <windows.h>
int main() {
    #pragma omp parallel
    {
        std::printf ("Doing Stuff on thread: %d  on Core #%d\n", omp_get_thread_num(),\
                      GetCurrentProcessorNumber());
    }
    return 0;
}
Sometimes it gives output:
Doing Stuff on thread: 1  on Core #1
Doing Stuff on thread: 0  on Core #2
Doing Stuff on thread: 2  on Core #2
Doing Stuff on thread: 3  on Core #2
Although most of the times it gives
Doing Stuff on thread: 2  on Core #1
Doing Stuff on thread: 1  on Core #3
Doing Stuff on thread: 0  on Core #2
Doing Stuff on thread: 3  on Core #0
which is expected.
How can I make sure that the threads have their affinity set for a different core? Is there a way to force the scheduler to do this?
 
    