Created
December 5, 2019 01:37
-
-
Save bwedding/5597a7b8912f010b258f6570e7e75ae0 to your computer and use it in GitHub Desktop.
Parallel factorial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
#include <vector> | |
#include <execution> | |
#include <numeric> | |
long double Factorial(std::vector<int> & numbers) | |
{ | |
long double result = 1.0; | |
std::for_each( | |
std::execution::par_unseq, | |
numbers.begin(), | |
numbers.end(), | |
[&](auto&& item) | |
{ | |
result *= item; | |
}); | |
return result; | |
} | |
int main() | |
{ | |
long double result = 1.0; | |
std::vector<int> numbers(800); | |
std::iota(numbers.begin(), numbers.end(), 1); | |
std::cout << "800! is " << Factorial(numbers) << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment