運行我在C想我的第一個OpenMP程序++,我的代碼是:OpenMP的似乎不是在並行
#pragma omp parallel for num_threads(2)
for (int i=0;i<16;++i)
{
printf("Thread %d works with idx %d\n", omp_get_thread_num(), i);
}
我使用g ++ -O3 -fopenmp -std =編譯C++ 11
然而,當我運行程序時,我得到:
Thread 0 works with idx 0
Thread 0 works with idx 1
Thread 0 works with idx 2
Thread 0 works with idx 3
Thread 0 works with idx 4
Thread 0 works with idx 5
Thread 0 works with idx 6
Thread 0 works with idx 7
Thread 1 works with idx 8
Thread 1 works with idx 9
Thread 1 works with idx 10
Thread 1 works with idx 11
Thread 1 works with idx 12
Thread 1 works with idx 13
Thread 1 works with idx 14
Thread 1 works with idx 15
它是否並行運行?我一直在等待thread0 - thread1 - thread0 - thread1之類的東西。
這裏會出現什麼問題?先謝謝你!
難道我的回答可以幫助您? – dreamcrash