gcc/libgomp/testsuite/libgomp.oacc-c++/template-reduction.C
Thomas Schwinge 7fd549d24f OpenACC 2.5 default (present) clause
gcc/c/
	* c-parser.c (c_parser_omp_clause_default): Handle
	"OMP_CLAUSE_DEFAULT_PRESENT".
	gcc/cp/
	* parser.c (cp_parser_omp_clause_default): Handle
	"OMP_CLAUSE_DEFAULT_PRESENT".
	gcc/fortran/
	* gfortran.h (enum gfc_omp_default_sharing): Add
	"OMP_DEFAULT_PRESENT".
	* dump-parse-tree.c (show_omp_clauses): Handle it.
	* openmp.c (gfc_match_omp_clauses): Likewise.
	* trans-openmp.c (gfc_trans_omp_clauses): Likewise.
	gcc/
	* tree-core.h (enum omp_clause_default_kind): Add
	"OMP_CLAUSE_DEFAULT_PRESENT".
	* tree-pretty-print.c (dump_omp_clause): Handle it.
	* gimplify.c (enum gimplify_omp_var_data): Add
	"GOVD_MAP_FORCE_PRESENT".
	(gimplify_adjust_omp_clauses_1): Map it to
	"GOMP_MAP_FORCE_PRESENT".
	(oacc_default_clause): Handle "OMP_CLAUSE_DEFAULT_PRESENT".
	gcc/testsuite/
	* c-c++-common/goacc/default-1.c: Update.
	* c-c++-common/goacc/default-2.c: Likewise.
	* c-c++-common/goacc/default-4.c: Likewise.
	* gfortran.dg/goacc/default-1.f95: Likewise.
	* gfortran.dg/goacc/default-4.f: Likewise.
	* c-c++-common/goacc/default-5.c: New file.
	* gfortran.dg/goacc/default-5.f: Likewise.
	libgomp/
	* testsuite/libgomp.oacc-c++/template-reduction.C: Update.
	* testsuite/libgomp.oacc-c-c++-common/nested-2.c: Update.
	* testsuite/libgomp.oacc-fortran/data-4-2.f90: Likewise.
	* testsuite/libgomp.oacc-fortran/default-1.f90: Likewise.
	* testsuite/libgomp.oacc-fortran/non-scalar-data.f90: Likewise.

From-SVN: r248280
2017-05-19 15:32:48 +02:00

124 lines
2.1 KiB
C

const int n = 100;
// Check explicit template copy map
template<typename T> T
sum (T array[])
{
T s = 0;
#pragma acc parallel loop num_gangs (10) gang reduction (+:s) copy (array[0:n])
for (int i = 0; i < n; i++)
s += array[i];
return s;
}
// Check implicit template copy map
template<typename T> T
sum ()
{
T s = 0;
T array[n];
for (int i = 0; i < n; i++)
array[i] = i+1;
#pragma acc parallel loop num_gangs (10) gang reduction (+:s)
for (int i = 0; i < n; i++)
s += array[i];
return s;
}
// Check template with default (present)
template<typename T> T
sum_default_present ()
{
T s = 0;
T array[n];
for (int i = 0; i < n; i++)
array[i] = i+1;
#pragma acc enter data copyin (array)
#pragma acc parallel loop num_gangs (10) gang reduction (+:s) default (present)
for (int i = 0; i < n; i++)
s += array[i];
#pragma acc exit data delete (array)
return s;
}
// Check present and async
template<typename T> T
async_sum (T array[])
{
T s = 0;
#pragma acc parallel loop num_gangs (10) gang async (1) present (array[0:n])
for (int i = 0; i < n; i++)
array[i] = i+1;
#pragma acc parallel loop num_gangs (10) gang reduction (+:s) present (array[0:n]) async wait (1)
for (int i = 0; i < n; i++)
s += array[i];
#pragma acc wait
return s;
}
// Check present and async and an explicit firstprivate
template<typename T> T
async_sum (int c)
{
T s = 0;
#pragma acc parallel loop num_gangs (10) gang reduction (+:s) firstprivate (c) async wait (1)
for (int i = 0; i < n; i++)
s += i+c;
#pragma acc wait
return s;
}
int
main()
{
int a[n];
int result = 0;
for (int i = 0; i < n; i++)
{
a[i] = i+1;
result += i+1;
}
if (sum (a) != result)
__builtin_abort ();
if (sum<int> () != result)
__builtin_abort ();
if (sum_default_present<int> () != result)
__builtin_abort ();
#pragma acc enter data copyin (a)
if (async_sum (a) != result)
__builtin_abort ();
if (async_sum<int> (1) != result)
__builtin_abort ();
#pragma acc exit data delete (a)
return 0;
}