Hi,
I am using openmp for test a couple of functions and to know
how fast is using openmp multicore schema. So 1) I was wondering
how to measure the maximum time that take 8 cores to execute the for.
Or maybe the answer is more easy and I have to use clock and measure it
in every core.
2) Other thing is that I measure the time openmp consume in a for loop and it takes
13x106 cycles while when i was using one core takes ~4x106 cycles and the
expected time for a core, distributing the for in 8 cores, is 0.5x106 for each core. So why
is this happening?
This is the code I am using:
#define NTHREADS 8
void main()
{
int nthreads, tid;
int a[1000];
int b[1000];
int c[1000];
double path_lat[8];
double path_lon[8];
int i;
double lat_ut=0, lon_ut=0;
nzero_candidates candidates[8];
ClosestPop nearestpop[8];
nthreads = NTHREADS;
path_lat[ 0 ] = 19.614445; path_lon[ 0 ] = -99.190552;
path_lat[ 1 ] = 19.589445; path_lon[ 1 ] = -99.201942;
path_lat[ 2 ] = 19.5875; path_lon[ 2 ] = -99.203056;
path_lat[ 3 ] = 19.585278; path_lon[ 3 ] = -99.205002;
path_lat[ 4 ] = 19.582222; path_lon[ 4 ] = -99.205002;
path_lat[ 5 ] = 19.554167; path_lon[ 5 ] = -99.205002;
path_lat[ 6 ] = 19.533333; path_lon[ 6 ] = -99.208336;
path_lat[ 7 ] = 19.525; path_lon[ 7 ] = -99.209167;
ini_idxed_arrays();
lat_ut = 19.554167;
lon_ut = -99.205002;
for(i=0;i<1000;i++)
{
a[i]=i;
b[i]=1;
}
omp_set_num_threads(NTHREADS);
/* Fork a team of threads giving them their own copies of variables */
#pragma omp parallel private(nthreads, tid)
{
#pragma omp for
for (i=0;i<8;i++){
find_nearest_candidates_halfdgres(path_lat[i],path_lon[i],&candidates[i]); //Using half degree resolution
nearestpop[i] = geo_dist_1p2centroids_alg_halfdgres( path_lat[i], path_lon[i], &candidates[i]); //Using half degree resolution
}
/* Obtain thread number */
tid = omp_get_thread_num();
printf("Hello World from thread = %d\n", tid);
/* Only master thread does this */
if (tid == 0)
{
nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}
} /* All threads join master thread and disband */
}
I expect someone could tell me what is the way to
solve these two issues.
Any help would be appreciated.
Julian
