[Omp] openMP threads not starting simultaneously
Chandan Basu
cbasu at rediffmail.com
Wed Oct 17 22:51:20 PDT 2007
Hi all,
Please help me with a question related to openMP parallelization. I am running the following code on a 8 core intel clovertown machine. The code is compiled by intel c compiler, icc, with -openmp option. The code compiles and runs without trouble. It also creates 8 openmp threads as set in the program. But If I look at the processor utilization (by using top command) it shows that only one core is being used. Timing wise also the 8 thread case is taking more time than one thread case. It seems threads are running sequentially. Can any one explain if there is a bug in the code :
----------------------------------
/*
The following code runs a random number generator funtion fun1 on all the threads. The purpose of this code is to see if all the processor cores are fully utilized.
*/
#include<stdio.h>
#include<omp.h>
int fun1();
int main(int argc, char *argv[])
{
int provided;
int rank;
int size;
int id;
int i, cnt[10];
int flag;
int n;
for(i = 0; i< 10; i++)
cnt[i] = 0;
omp_set_num_threads(8);
#pragma omp parallel private(id)
{
id = omp_get_thread_num();
cnt[id] = fun1();
#pragma omp barrier
}
omp_set_num_threads(1);
}
/*This function runs a random generator for some time*/
int fun1()
{
int i, col, cnt;
cnt = 0;
for(i=0; i< MAX; i++)
for(col = 0; col < 200; col++)
cnt += rand();
return cnt;
}
--------------------------
Thanks
Chandan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://openmp.org/pipermail/omp/attachments/20071018/f21f8848/attachment.html
More information about the Omp
mailing list