Commit c28495fc authored by Neil Gershenfeld's avatar Neil Gershenfeld

wip

parent 6bacca84
Pipeline #5096 passed with stage
in 1 second
//
// threadpi.cpp
// Neil Gershenfeld 3/1/20
// calculation of pi by a C++ thread sum
// pi = 3.14159265358979323846
//
#include <iostream>
#include <chrono>
#include <thread>
#include <vector>
unsigned int npts = 2e7;
unsigned int nthreads = std::thread::hardware_concurrency();
std::vector<double> results(nthreads);
void sum(int index) {
unsigned int start = npts*index+1;
unsigned int end = npts*(index+1)+1;
double result = 0;
for (unsigned int i = start; i < end; ++i)
result += 0.5/((i-0.75)*(i-0.25));
results[index] = result;
}
int main(void) {
double pi = 0;
std::thread threads[nthreads];
auto tstart = std::chrono::high_resolution_clock::now();
for (int i = 0; i < nthreads; ++i)
threads[i] = std::thread(sum,i);
for (int i = 0; i < nthreads; ++i) {
threads[i].join();
pi += results[i];
}
auto tend = std::chrono::high_resolution_clock::now();
auto dt = std::chrono::duration_cast<std::chrono::microseconds>(tend-tstart).count();
auto mflops = npts*nthreads*5.0/dt;
std::cout << "npts: " << npts << " nthreads: " << nthreads << " pi: " << pi << '\n';
std::cout << "time: " << 1e-6*dt << " estimated MFlops: " << mflops << '\n';
return 0;
}
......@@ -10,6 +10,7 @@
|1,090|[numbapig.py](Python/numbapig.py)|Python, Numba, CUDA, 5120 cores|NVIDIA V100|March 1, 2020|
|315|[numbapip.py](Python/numbapip.py)|Python, Numba, parallel, fastmath<br>96 cores|Intel 2x Xeon Platinum 8175M|Feb 7, 2020|
|272|[threadpi.c](C/threadpi.c)|C, 96 threads<br>gcc threadpi.c -o threadpi -O3 -ffast-math -pthread|Intel 2x Xeon Platinum 8175M|Jun 3, 2019|
|267|[threadpi.cpp](C++/threadpi.cpp)|C++, 96 threads<br>g++ threadpi.cpp -o threadpi -O3 -ffast-math -pthread|Intel 2x Xeon Platinum 8175M|Mar 1, 2020|
|211|[mpipi2.c](MPI/mpipi2.c)|C, MPI, 1 node, 96 cores<br>mpicc mpipi2.c -o mpipi2 -O3 -ffast-math|Intel 2x Xeon Platinum 8175M|Oct 24, 2019|
|180|[mpipi2.py](Python/mpipi2.py)|Python, Numba, MPI<br>mpirun -np 96 python mpipi2.py|Intel 2x Xeon Platinum 8175M|Feb 6, 2020|
|173|[mppi.c](OpenMP/mppi.c)|C, OpenMP, 96 threads<br>gcc mppi.c -o mppi -O3 -ffast-math -fopenmp|Intel 2x Xeon Platinum 8175M|Jul 1, 2019|
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment