The formula for the area of a circle is, as you probably remember from middle-school; . In english, it's radius squared times pi. Here it is in code:
auto circle_area_cpu(const Circle& c) { const auto pi = 3.14f; return c.r * c.r * pi;}
Using the circle_area_cpu() function, we can calculate the full area using std::transform() and std::reduce() in C++:
auto sum_circle_areas_cpu() { constexpr auto n = 1024; auto circles = make_circles(n); auto areas = std::vector<float>(n); std::transform(circles.begin(), circles.end(), areas.begin(), circle_area_cpu); auto plus = std::plus<float>{}; auto area = std::reduce(areas.begin(), ...