43 lines · c
1// RUN: %libomptarget-compile-run-and-check-generic2// RUN: %libomptarget-compileopt-run-and-check-generic3 4#include <omp.h>5#include <stdio.h>6#include <stdlib.h>7 8int main() {9 long unsigned **DP = 0;10 int N = 32;11 int Threads = 64;12 int Teams = 10;13 14#pragma omp target map(from : DP)15 DP = (long unsigned **)malloc(sizeof(long unsigned *) * Threads * Teams);16 17#pragma omp target teams distribute parallel for num_teams(Teams) \18 thread_limit(Threads)19 for (int i = 0; i < Threads * Teams; ++i)20 DP[i] = (long unsigned *)malloc(sizeof(long unsigned) * N);21 22#pragma omp target teams distribute parallel for num_teams(Teams) \23 thread_limit(Threads)24 for (int i = 0; i < Threads * Teams; ++i) {25 for (int j = 0; j < N; ++j) {26 DP[i][j] = i + j;27 }28 }29 30 long unsigned s = 0;31#pragma omp target teams distribute parallel for num_teams(Teams) \32 thread_limit(Threads) reduction(+ : s)33 for (int i = 0; i < Threads * Teams; ++i) {34 for (int j = 0; j < N; ++j) {35 s += DP[i][j];36 }37 }38 39 // CHECK: Sum: 686080040 printf("Sum: %li\n", s);41 return 0;42}43