OpenMP offload: Unknown variable reference when using target teams loop


I’m working on an application using OpenMP offloading with nvc++. In particular, I’m using the target teams distribute parallel for and haven’t had any issues. However, I wanted to test the descriptive approach of using target teams loop but I’m getting a compilation error: Unknown variable reference. This is the code section I’m having issues with, specifically, line 449.

442 #pragma omp target enter data map(to:coils[0:size_3D],e_r[0:size_3D],leng_segment[0:size_2D],particles[0:size_particles])
444     #pragma omp parallel num_threads(2)
445     {
446         #pragma omp single
447         {
448             for (int i = 1; i <= steps; i++){
449                 #pragma omp target teams distribute parallel for (COMMENT: alternatively target teams loop)
450                 for(int p=0; p < particle_count ; p++){
451                     int base = p*DIMENSIONS;
452                     if((particles[base] == MINOR_RADIUS) && (particles[base+1] == MINOR_RADIUS) && (particles[base+2] == MINOR_RADIUS)){
453                         continue;
454                     }
455                     else{
456                         diverged = computeIteration(coils,e_r,leng_segment,&particles[base],step_size,mode,divergenceCounter);
457                     }
458                 }
460                 if(i%10 == 0){
461                     #pragma omp taskwait
462                     #pragma omp target update from(particles[0:size_particles])
463                     {
464                         #pragma omp task shared(particles) firstprivate(i,output,size_particles)
465                         printIterationFile(particles, i, output,particle_count);
466                     }
467                 }
468             }
469         }
470     }
471 #pragma omp target exit data map(release:coils[0:size_3D],e_r[0:size_3D],leng_segment[0:size_2D],particles[0:size_particles])

I’m using nvc++ 22.5-0 (NVHPCSDK 22.5), and I’m compiling with -mp=gpu -gpu=pinned,fastmath -Minfo=mp

Am I doing something wrong when changing from target teams distribute parallel for to target teams loop?

I’d appreciate any help.

Hi diejime01,

As you describe the issue, it appears to be same or similar issue to one I found while looking another post when using “loop” within a task region and reported as TPR #31928: OpenMP Target Offloading Bug - Making Target Region in Task

The problem has to do the generation of the multicore CPU version of the code (both a GPU and CPU version of the offload code is generated as required by the OpenMP standard). The problem being that multicore CPU code would be nested in this case so can’t be used and is disabled.

With “distribute”, the offload region is “outlined” (i.e. a function is created with the offload region and then handed off to the runtime), hence the CPU code generation isn’t an issue. Though with “loop”, the offload region is added in place, hence causing the undefined reference errors since no multicore CPU version was generated, but the reference still exists.

Our engineers are looking at the best way to fix the issue, so for know, keep using “distribute”. Note that in the other post the OP did get a seg fault when using “distribute” inside of a task region, which we’re also investigating.

Note if you can provide a minimal reproducing example, I can add it to TPR #31928 as an additional test case, as well as confirming that it is indeed the same issue.



Thanks @MatColgrove, I’ll stick to distribute for now. Where/how can I keep track of this bug report you created?

Sorry but our TPR system is not accessible externally. You can ping me on this post for updates, but I usually can’t give specifics as to which release a particular issue will be fixed. Though I do post a notification after the fix makes it into a release.

Again, I can’t be 100% sure that your issue is the same without a reproducing example, but I’ll add this post to TPR #31928 as a reminder to post notification.


1 Like