1// RUN: %libomptarget-compile-generic && %libomptarget-run-generic
2// RUN: %libomptarget-compileopt-generic && %libomptarget-run-generic
3
4#include <stdio.h>
5#include <stdlib.h>
6
7int main() {
8 long unsigned *DP = 0;
9 int N = 32;
10 int Threads = 64;
11 int Teams = 10;
12
13 // Allocate ~55MB on the device.
14#pragma omp target map(from : DP)
15 DP = (long unsigned *)malloc(size: sizeof(long unsigned) * N * Threads * Teams);
16
17#pragma omp target teams distribute parallel for num_teams(Teams) \
18 thread_limit(Threads) is_device_ptr(DP)
19 for (int i = 0; i < Threads * Teams; ++i) {
20 for (int j = 0; j < N; ++j) {
21 DP[i * N + j] = i + j;
22 }
23 }
24
25 long unsigned s = 0;
26#pragma omp target teams distribute parallel for num_teams(Teams) \
27 thread_limit(Threads) reduction(+ : s)
28 for (int i = 0; i < Threads * Teams; ++i) {
29 for (int j = 0; j < N; ++j) {
30 s += DP[i * N + j];
31 }
32 }
33
34 // CHECK: Sum: 6860800
35 printf(format: "Sum: %li\n", s);
36 return 0;
37}
38

source code of offload/test/offloading/malloc.c