Skip to content

Instantly share code, notes, and snippets.

@Prince781
Created June 3, 2019 16:42
Show Gist options
  • Save Prince781/9d5e4474c98f3b588c90b1b6d2613f92 to your computer and use it in GitHub Desktop.
Save Prince781/9d5e4474c98f3b588c90b1b6d2613f92 to your computer and use it in GitHub Desktop.
pointer attachment example
// clang -fopenmp ptr-atmt.c -o ptr-atmt
#include <omp.h>
#include <stdio.h>
#pragma omp declare target
double *ptr;
void work(int i)
{
// work on ptr[i]
// ...
printf("[dev] work(%d): ptr = %p\n", i, ptr);
}
#pragma omp end declare target
// work() is a device kernel, and ptr is also on the device
void foo(double arr[], size_t sz)
{
ptr = arr;
#pragma omp target map(ptr[0:sz])
#pragma omp teams distribute
for (int i = 0; i < sz; i++) {
printf("[host] will work(%d): ptr = %p\n", i, ptr);
work( i );
}
}
int main(void) {
double array[] = { 1, 2 };
foo(array, 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment