OpenMP-Examples/data_environment/sources/target_task_reduction.1.c
2021-08-17 09:11:55 -07:00

37 lines
735 B
C

/*
* @@name: target_task_reduction.1.c
* @@type: C
* @@compilable: yes
* @@linkable: yes
* @@expect: success
* @@version: omp_5.1
*/
#if _OPENMP < 202011
#define masked master
#endif
#include <stdio.h>
#pragma omp declare target to(device_compute)
void device_compute(int *);
void host_compute(int *);
int main()
{
int sum = 0;
#pragma omp parallel masked
#pragma omp taskgroup task_reduction(+:sum)
{
#pragma omp target in_reduction(+:sum) nowait
device_compute(&sum);
#pragma omp task in_reduction(+:sum)
host_compute(&sum);
}
printf( "sum = %d\n", sum);
//OUTPUT: sum = 2
return 0;
}
void device_compute(int *sum){ *sum = 1; }
void host_compute(int *sum){ *sum = 1; }