src/test/gpu-reduce.c
Reductions on GPUs
#include "utils.h"
int main (int argc, char * argv[])
{
(argc > 1 ? atoi(argv[1]) : 1024);
init_grid
periodic (right);
periodic (top);
(2.*pi);
size
scalar s[];
foreach (serial)
[] = sq (cos(2.*x)*cos(2.*y));
s
= timer_start();
timer t
double sum = 0.;
int iter;
for (iter = 0; iter < 400*1024/N; iter++) {
= 0.;
sum foreach(reduction(max:sum))
= max (sum, s[]);
sum }
double elapsed = timer_elapsed (t);
printf ("N: %d elapsed: %g speed: %g\n",
, elapsed, grid->tn*iter/elapsed);
N
fprintf (stderr, "result: %g\n", sum);
output_ppm (s, file = "s.png", n = 512, spread = -1);
Check that “inout” fields work.
foreach()
[] += sq (0.5*sin(8.*x)*sin(8.*y));
sforeach()
[] = s[] + sq (0.5*sin(8.*x)*sin(8.*y));
s
stats stat = statsf (s);
fprintf (stderr, "min: %g max: %g\n", stat.min, stat.max);
output_ppm (s, file = "s1.png", n = 512, spread = -1);
Check that reduction on levels works.