CPARK
1.0
A light-weighted, distributed computing framework for C++ that offers a fast and general-purpose large data processing solution.
Toggle main menu visibility
Main Page
Related Pages
Topics
Concepts
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
a
b
c
d
e
f
g
i
m
o
p
r
s
u
Functions
a
b
c
d
e
f
g
i
m
o
p
r
s
u
Typedefs
Related Symbols
Files
File List
Examples
•
All
Classes
Functions
Typedefs
Friends
Modules
Pages
Concepts
Loading...
Searching...
No Matches
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 =
cpark::GeneratorRdd
(
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;
}
cpark::Config
Definition
cpark.h:35
cpark::ExecutionContext
Definition
cpark.h:148
cpark::GeneratorRdd
Definition
generator_rdd.h:27
cpark::Reduce
Definition
reduce.h:24
Generated by
1.9.8