openmpxeon-phicilk

thread numbers and time results consistency


I am trying to learn xeon phi programming.

I am running this code on cpu and I am using offload pragmas for the pieces I want to run on the coprocessors.

Since I am compiling on cpu and I use offloads , I am using :

export MIC_ENV_PREFIX=MIC
export MIC_OMP_NUM_THREADS=120

in order to specify the threads number.

My problems:

1) Running the code , shows always 40 threads been used.

2) Running again and again the code without compiling , I am getting different time results.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <omp.h>
#include <sys/time.h>

#include <cilk/cilk.h>
#include <cilk/reducer_opadd.h>


typedef CILK_C_DECLARE_REDUCER(float) reducer;


double dtime()
{
    double tseconds = 0.0;
    struct timeval mytime;
    gettimeofday(&mytime,(struct timezone*)0);
    tseconds = (double)(mytime.tv_sec + mytime.tv_usec*1.0e-6);
    return( tseconds * 1000 );
}

float openMPIntegration(

    int N,
    float * const ioA )
{

    float res = 0;

#if DOFFLOAD
    #pragma offload target (mic) 
    {
#endif

    #pragma omp parallel for reduction(+:res)
    for ( int i = 0; i < N; i++ )
    {
        res += ioA[ i ]; 
    }

#if DOFFLOAD
}
#endif

    return res;

}

float CilkIntegration(

    int N , 
    float * const ioA )
{


float res = 0;
#if DOFFLOAD
    #pragma offload target (mic) 
    {
#endif

    CILK_C_REDUCER_OPADD( sum, float , 0);
    CILK_C_REGISTER_REDUCER(sum);

    cilk_for ( int i = 0; i < N; i++ )
    {
        REDUCER_VIEW(sum) += ioA[ i ];
    }

    res = sum.value;
    CILK_C_UNREGISTER_REDUCER(sum);

#if DOFFLOAD
}
#endif

    return res;
}    

int main()
{
    int NbOfThreads;
    double tstart, tstop, ttime;

    int N = 1000000;
    float * A = (float*) _mm_malloc( N * sizeof(*A) , 32 );

    //fill A
    for ( int i = 0; i < N; i++ )
        A[ i ] = i;

#if DOFFLOAD
    #pragma offload target (mic)
#endif

    #pragma omp parallel
    #pragma omp master
    NbOfThreads = omp_get_num_threads();

    printf("\nUsing %d threads\r\n",NbOfThreads);

    tstart = dtime();   

    float openMPRes = openMPIntegration( N , A );

    tstop = dtime();    
    ttime = tstop - tstart;
    printf("\nopenMP integration = %10.3lf msecs \t value = %10.3f", ttime ,openMPRes);


    tstart = dtime();   
    float CilkRes = CilkIntegration( N , A );

    tstop = dtime();    
    ttime = tstop - tstart;
    printf("\nCilk   integration = %10.3lf msecs \t value = %10.3f", ttime,CilkRes);

    printf("\n");
    _mm_free( A );

    return 0;

}

I am compiling:

icc -std=c99 -DOFFLOAD -openmp -qopt-report -O3 xeon.c -o xeon

Solution

  • This isn't strictly an OpenMP question, as it involves a disrecommended combination of disparate parallel run-time models, and I think you aren't using the openmp standardized offload syntax. The short answer is that no implementation recommends combining OpenMP and cilkplus parallel run-time models. The next step beyond that is that typical OpenMP models, by default, block availability of hardware thread context to a threading model outside OpenMP for a time, typically defaulting to 0.200 seconds. It would seem stylistically more consistent to use omp reduction rather than cilkplus reducers, but in present implementations that may not be a show stopping decision. I would guess that you might be using the Intel offload model so as to have both openmp standard and non-standard offload syntax available.