Created
June 3, 2019 16:42
-
-
Save Prince781/9d5e4474c98f3b588c90b1b6d2613f92 to your computer and use it in GitHub Desktop.
pointer attachment example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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