Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double calcPiCpp11(const int numThreads, const long numSteps)
- {
- double step = 1.0 / (double)numSteps;
- double x, pi;
- double* sums = new double[numThreads];
- for (int i = 0; i < numThreads; ++i)
- {
- sums[i] = 0.0f;
- }
- const int threadNumSteps = numSteps / numThreads;
- std::vector<std::thread> threads;
- for (int i = 0; i < numThreads; ++i)
- {
- int iStart = threadNumSteps * i + 1;
- threads.push_back(std::thread(calcPI, sums, step, threadNumSteps, iStart, i));
- }
- for (auto& thread : threads)
- {
- thread.join();
- }
- pi = step * std::accumulate(sums, sums + numThreads, 0.0);
- delete[] sums;
- return pi;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement