Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

omp_set_num_threads

Intel_C_Intel
Employee
706 Views
I tried the following code section on one of the Dell computers equipped with dual P4 CPUs running linux. It resulted in "segmentation fault" after executing the function "omp_set_num_threads(t)", no matter what value t assumes. Other omp operations are fine. The compiler is intel C++ 9.x for linux. Is this a known bug?

{
int nthreads, tid;
int nCPU;

nCPU = omp_get_num_procs();
printf("number of CPUs is %d ",nCPU);
omp_set_num_threads(nCPU);
printf("number of threads is%d ", omp_get_num_threads());

#pragma omp parallel private(tid)
{
tid = omp_get_thread_num();
if(tid == 0) {
nthreads = omp_get_num_threads();
printf("number of threads is %d ", nthreads);
}
printf("hello from thread %d ", tid);
}
}

My one year free support must have ended. So, thank you for any input.
0 Kudos
2 Replies
TimP
Honored Contributor III
706 Views
Prefixing your code with my guess at part of what you left out:
#include "omp.h"
#include "stdio.h"
main ()


I don't see an evident immediate problem.
0 Kudos
steven_manos
Beginner
706 Views
Generally speaking just because the segmentation fault occured after a particular line using printf() it doesn't mean that's where the error is.

omp_get_num_procs returns 'the number of of processor available to the program'. I really don't know how this is evaluated on your system - it might even return null.

What is your program output? i.e. what's the value of omp_get_num_procs()?

Maybe try setting (export/setenv) OMP_NUM_THREADS to 2 in your shell before running the code.

IT seems to work fine here.

> icc -openmp test.c -o test
test.c(12) : (col. 1) remark: OpenMP DEFINED REGION WAS PARALLELIZED.
> ./test
number of CPUs is 8
number of threads is1
hello from thread 2
number of threads is 8
hello from thread 0
hello from thread 5
hello from thread 7
hello from thread 3
hello from thread 4
hello from thread 6
hello from thread 1
0 Kudos
Reply