OpenMP 4.0 target data directive

OpenMP 4.0 target data directive

Hello,

I am using the icc v14.0.0 compiler and I would like to use the #pragma omp target data directive as described here:

https://software.intel.com/en-us/node/514568

I have made a small example program that, to my eye, looks very similar to the example given in the above link. However, it produces a compile error.

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

int main(int argc, char* argv[])
{
  int *a, *b;
  a = (int *) malloc(sizeof(int));
  b = (int *) malloc(sizeof(int));
  *a = 1;
#pragma omp target data map(to:a) map(from:b)
  {
#pragma omp target
    {
      *b = *a;
    }   
  }
  printf("%d\n", *b);
  return 0;
}

The compile error is the following:

$ icc -openmp -o test test.c
test.c(13): error: pointer variable "b" in this offload region must be specified in an in/out/inout/nocopy clause
  #pragma omp target
  ^

test.c(13): error: pointer variable "a" in this offload region must be specified in an in/out/inout/nocopy clause
  #pragma omp target
  ^

compilation aborted for test.c (code 2)

If I remove the 'target data' pragma and move the two map() clauses to the 'target' pragma, it compiles and runs on the target device as expected (according to the OFFLOAD_REPORT output).

What is the correct syntax for using the 'target data' pragma in OpenMP 4.0? How should I modify the above code so that it compiles with the 'target data' pragma?

Thank you for your help!

-Dan

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

That compiler didn't support target update and target map in the same application.  This was fixed in at least one later compiler.  Maybe there was a similar restriction on the syntax you're trying.  It's important to use a current compiler when trying OpenMP 4.

Specifically, you need at least update #2 (14.0.2.14) to compile and run your example.

$ icc -V
Intel(R) C Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 14.0.2.144 Build 20140120
Copyright (C) 1985-2014 Intel Corporation.  All rights reserved.

$ icc U505063.c -openmp && ./a.out
1
$

Patrick

Leave a Comment

Please sign in to add a comment. Not a member? Join today