This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How to measure time elapsed in openmp

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

  • Hi there,

    Someone could tell how to fix the problem with openmp.

    I really need to measure the real performance using openmp.

    Please.

  • Is there any reason you can't use TSC[L/H] to measure time?  Each core has an independent counter, but they are all driven from the same physical clock source (ie their units are the same, ~1ghz cycles).  Thus, find differences within the thread on each core, don't combine readings and try to find differences on just one of the cores.  In order to use them, you need to write TSCL (at least) once per core, so I'd make a special open mp thread to do this.  I'd then read TSCL at the beginning and end of each thread to get actual execution time of the work.  You can use TSCL on dispatch thread to see how long it takes for all the fork/join to complete as well.  This should let you measure performance with a few cycles of uncertainty. 

    You can google this forum for using TSCL/H.

  • Hi

    thanks for your advice I have tried using TSC[L/H] and it gives very close value to clock, in this case a little smallest.

    This value is greater than the value I get using NDK  demo , for the same functions, about 3 times greater but I read in other forums

    that is because of implementation or demo.

    Thanks you.

    Julian