This source file includes following definitions.
- main
#include "Halide.h"
#include <stdio.h>
using namespace Halide;
int main(int argc, char **argv) {
Func f;
Var x;
f(x) = select((x % 7 == 0) || (x % 5 == 0), 1, 0);
f.compute_root();
Func cum_sum;
cum_sum(x) = 0;
RDom r(0, 1000);
cum_sum(r+1) = f(r) + cum_sum(r);
cum_sum.compute_root();
Func ones;
ones(x) = -1;
Expr bin = clamp(cum_sum(r), 0, 1000);
ones(bin) = select(f(r) == 1, r, undef<int>());
ones.update().allow_race_conditions().parallel(r, 50);
Buffer<int> result = ones.realize(1001);
int next = 0;
for (int i = 0; i < result.width(); i++) {
if (result(i) != next) {
printf("result(%d) = %d instead of %d\n", i, result(i), next);
return -1;
} else {
do {
next++;
} while ((next % 5) && (next % 7));
}
if (next >= 1000) break;
}
return 0;
}