[Openmp-dev] Issues with target regions in executable and library

Joachim Protze via Openmp-dev openmp-dev at lists.llvm.org
Tue Jul 3 10:11:59 PDT 2018

Hi all,

one of my colleagues reported an issue, when having target regions in 
the executable and a library.
The problem is that during the execution for both target regions the 
same code (coming from the library) is executed. Is this a bug, known 
bug, or does this not work by design?

I run below experiment with a quite recent trunk version of LLVM and the 
output is:

Hello from foo. 0
Hello from foo. 0

Which also suggests that the code was actually offloaded to the device.
Also specifying device(0) and device(1) doesn't help to see the right 

Only adding if(0) or executing the code on a machine with no device 
provides the expected result:

Hello from main. 1
Hello from foo. 1

We appreciate any hints how this could be fixed.


----- main.c -----

#include <stdio.h>
#include <omp.h>

void foo(){
   #pragma omp target
     printf("Hello from foo. %i\n",omp_is_initial_device());

----- lib.c -----

#include <stdio.h>
#include <omp.h>

void foo();

int main(){
   #pragma omp target
     printf("Hello from main. %i\n",omp_is_initial_device());

   return 0;

----- compile & run -----

clang -shared -fPIC -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda -g 
lib.c -o libmylib.so

clang -fopenmp -fopenmp-targets=nvptx64-nvidia-cuda main.c -L. -lmylib 


More information about the Openmp-dev mailing list