C++ 17 Parallel Sum

Jul 21, 2017 at 1:21am
Following web site has small program to parallel sum elements of Vector:

<
http://en.cppreference.com/w/cpp/experimental/reduce
>

<

#include <iostream>
#include <chrono>
#include <vector>
#include <numeric>
// #include <experimental/execution_policy>
// #include <experimental/numeric>
#include <experimental/execution_policy>
#include <experimental/numeric>

int main()
{
std::vector<double> v(10'000'007, 0.5);

{
auto t1 = std::chrono::high_resolution_clock::now();
double result = std::accumulate(v.begin(), v.end(), 0.0);
auto t2 = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> ms = t2 - t1;
std::cout << std::fixed << "std::accumulate result " << result
<< " took " << ms.count() << " ms\n";
}

{
auto t1 = std::chrono::high_resolution_clock::now();
double result = std::experimental::parallel::reduce(
std::experimental::parallel::par,
v.begin(), v.end());
auto t2 = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> ms = t2 - t1;
std::cout << "parallel::reduce result "
<< result << " took " << ms.count() << " ms\n";
}
}

>

Above program output will be:

<
std::accumulate result 5000003.50000 took 12.7365 ms
parallel::reduce result 5000003.50000 took 5.06423 ms
>

I compiled this program using Microsoft Visual C++ 2017 Professional.

Compiler is giving following errors:

cannot open source file "experimental/execution_policy"

cannot open source file "experimental/numeric"

Any information to resolve these compilation errors please?






Jul 21, 2017 at 2:30am
That program uses the Parallelism TS (Technical specification), which was a sort of a beta branch of the C++ standard, which had since been merged into C++17.

You can wait for when C++17 is implemented by your compiler, at which point this program will work, except you'd have to rewrite it as was done on http://en.cppreference.com/w/cpp/algorithm/reduce#Example

Or you can find one of the half a dozen implementations of the Parallelism TS, and read its documentation on how exactly to plug it in. As I recall, HPX had the best implementation.
Jul 21, 2017 at 7:36am
Cubbi,
Thank you very much.
Microsoft VC++ 2017 has not implemented parallelism? Correct?
When may be Microsoft planning to release next C++ version (2018?) and will they include parallel C++features in 2018?

I have gcc.exe and g++.exe. Both are of version 8.0.0 and can be run from DOS prompt.
Looks like g++ 8.0.0 has not yet implemented parallel C++? correct?

Is there a later gcc/g++ version that implements parallel C++ please?
If yes, which version of gcc/g++? And is there an easy way to install the gcc/g++ with parallel C++?

Thanks







Jul 21, 2017 at 7:40am
Cubbi,
Is HPX freely downloadable and usable software?
Is there a tutorial website, with HPX installation and running steps please?
Jul 21, 2017 at 8:00am
I have downloaded and extracted hpx_1.0.0. I did not see any HPX installation and usage instructions in the HPX folder.

May I know any information about HPX installation and usage please?
Last edited on Jul 21, 2017 at 8:02am
Jul 21, 2017 at 11:42am
Is there a webpage tutorial or instructions for plugging HPX into Visual C++ Studio 2017 Professional please?
Jul 21, 2017 at 11:43am
HPX is integrated into VcPkg. See: http://stellar-group.org/2017/05/using-hpx-on-windows/
Jul 21, 2017 at 1:16pm
Microsoft VC++ 2017 has not implemented parallelism? Correct?

Microsoft's take on that technical specification was http://parallelstl.codeplex.com/

Looks like g++ 8.0.0 has not yet implemented parallel C++? correct?

GCC's take on parallelism was https://gcc.gnu.org/onlinedocs/libstdc++/manual/parallel_mode.html - that approach is older than the technical specification and is not compatible with it

Note I am using past tense. It doesn't matter who implemented Parallelism TS. Those features (after a number of modifications) were all merged into C++17, next compiler to support that revision of the standard will have std::reduce (not std::experimental::parallel::reduce)
Last edited on Jul 21, 2017 at 1:31pm
Jul 21, 2017 at 2:20pm
If you need to stick to visual studio, you can thread your own easily, and divide up the work then sum the results of that. Split it 4 ways maybe, for typical desktop cpus.

You might also see if cuda is an option for it, this sort of thing would do really well on a graphics card.

If the data changes slowly, you might be able to keep a running total in a real example. That is, say you get an initial chunk of 10k and add 10 here and 10 there, just adjust the running total by the 10 changes ...


Aug 13, 2017 at 3:00pm
Is there a freely downloadable latest compiler such as g++ that compiles on Microsoft Windows 10 computer, all C++17 features that includes Parallelism TS (Technical specification) features please?

If yes, how to download and install (any website link please)?
Last edited on Aug 13, 2017 at 3:02pm
Aug 13, 2017 at 5:23pm
> Is there a freely downloadable latest compiler such as g++ with all C++17 features

No.

Though the GNU compiler does make a spurious claim by defining __cplusplus as 201703L
For example, GCC 8.0 (snapshot): https://godbolt.org/g/F2mrna
(Uncomment the #include of the C++17 header to call the bluff)
Topic archived. No new replies allowed.