- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
{
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.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
#include "omp.h"
#include "stdio.h"
main ()
I don't see an evident immediate problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page