Bump version to 19.1.0-rc3
[llvm-project.git] / offload / test / offloading / malloc.c
blob7b98e1f1110e5bf0b289b18c28085bdcb701a551
1 // RUN: %libomptarget-compile-generic && %libomptarget-run-generic
2 // RUN: %libomptarget-compileopt-generic && %libomptarget-run-generic
4 #include <stdio.h>
5 #include <stdlib.h>
7 int main() {
8 long unsigned *DP = 0;
9 int N = 32;
10 int Threads = 64;
11 int Teams = 10;
13 // Allocate ~55MB on the device.
14 #pragma omp target map(from : DP)
15 DP = (long unsigned *)malloc(sizeof(long unsigned) * N * Threads * Teams);
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;
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];
34 // CHECK: Sum: 6860800
35 printf("Sum: %li\n", s);
36 return 0;