나는이 오래된 질문을하지만 대답은 온라인에서 나를 위해 작동하지 omp_get_num_threads 항상 GCC에 1을 반환있어, 코드는 다음과 같습니다 G ++ 4.4.5에서내가 (ICC에서 작동)
#include "stdio.h"
#include "omp.h"
main()
{
omp_set_num_threads(4); //initialise thread count for 4 core cpu
int j;
printf ("%d\n", omp_get_max_threads());
printf ("%d\n", omp_get_num_threads());
#pragma omp parallel for
for (int j=0; j<10; ++j)
{
printf ("%d\n", omp_get_num_threads());
int threadNum;
threadNum = omp_get_thread_num();
printf("This is thread %d\n", threadNum);
}
}
return 0;
}
, 리눅스 2.6. 32-5-AMD64, 그것은 생산 :
4
1
1
This is thread 0
1
This is thread 0
1
This is thread 0
1
This is thread 0
1
This is thread 0
1
This is thread 0
1
This is thread 0
1
This is thread 0
1
This is thread 0
1
This is thread 0
우리는 ICC 12.1.0로 이동하는 경우, 그것은 나에게 제공합니다
4
1
4
This is thread 0
4
This is thread 0
4
This is thread 0
4
This is thread 1
4
This is thread 1
4
This is thread 1
4
This is thread 2
4
This is thread 2
4
This is thread 3
4
This is thread 3
어떤 아이디어?
어떤 컴파일러 플래그를 사용 했습니까? –
또한 해당 코드는 컴파일되지 않습니다. 실제 코드를 게시하십시오. –