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.

OpenMP environment variable support on device

Hi,

Does TI's compiler support environment variable for target devices? 

For instance, export OMP_NUM_THREADS=4

#pragma omp target

#pragma omp parallel for

for(...)

Will four threads running on the DSP? I have no clue because the current compiler version does not support print out to console from other cores except core 0. 

But from the performance angle, it seems not...?? 

If it supports parsing environment variable, for the case that I have two parallel regions running on the host and device, respectively,  e.g.,

//Running on the ARM

#pragma omp parallel 

{

 ...

}

//Running on the DSP

#pragma omp target

#pragma omp parallel

{

 ...

}

IF I set OMP_NUM_THREADS=4, both parallel regions will launch 4 threads, right? Does there any way to control via environment variable, a.k.a different threads? I think it is not hard to define extensions such as OMP_NUM_THREADS_HOST, OMP_NUM_THREADS_DEVICE in the omp runtime??

  • Cheng,

    You can call omp_set_num_threads() inside the target region to set the number of threads on DSP.  If you call the API outside the target region, if will set the number of threads on the host.

    Xiaohui

  • Thanks, Xiaohui. 

    Yes, that might be a way to set the # of threads for the target parallel region. But I think it is probably more convenient that users can set the environment variables from outside instead of modifying the code and change the input parameters each time they run the code... 

    But back to my second question, do you think technically it is a valid choice that we extend the OMP spec to have OMP_NUM_THREADS_HOST and OMP_NUM_THREADS_DEVICE, in order not to mess up the two parallel regions on host and target, respectively? 

    Thanks

    Cheng

    Xiaohui Li said:

    Cheng,

    You can call omp_set_num_threads() inside the target region to set the number of threads on DSP.  If you call the API outside the target region, if will set the number of threads on the host.

    Xiaohui

  • Cheng,

    The OpenMP 4.0 spec does not provide any environment variables to control the behavior of the target regions and leaves it up to the implementation. An aspect that complicated defining such environment variables is how they are interpreted by multiple distinct devices present in the system and whether there was a need for per device or per device id environment variables.

    We'll explore using environment variables to control target region behavior in a future release of the OpenMP Accelerator model tooling.

    Ajay