CPARK 1.0
A light-weighted, distributed computing framework for C++ that offers a fast and general-purpose large data processing solution.
All Classes Functions Typedefs Friends Modules Pages Concepts
calculate_pi.cpp

This is an example use case of calculate the value of pi by series with n terms.

#include <iostream>
#include <random>
#include "cpark.h"
#include "generator_rdd.h"
#include "reduce.h"
int main() {
// Parallelly calculate the value of pi by series with n terms.
int n = 100000000;
cpark::ExecutionContext context(cpark::Config().setParallelTaskNum(8));
double pi =
0, n, [&](int i) -> double { return 4.0 / (2 * i + 1) * ((i & 1) ? -1 : 1); }, &context) |
cpark::Reduce([](auto x, auto y) { return x + y; });
std::cout << "The value of pi is roughly " << pi << std::endl;
}
Definition cpark.h:35
Definition cpark.h:148
Definition generator_rdd.h:27
Definition reduce.h:24