Parallel Technical Standard

Any C++ compiler on Windows 10 that can compile a C++ 17 program that uses Parallel Technical Standard features please?

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

Best regards
std::reduce http://en.cppreference.com/w/cpp/algorithm/reduce

Visual Studio 2017 version 15.5

Several Standard Library features have been added, deprecated or removed in accordance with the C++17 standard. For more information see C++ conformance improvements in Visual Studio.

New experimental features

Experimental support for the following parallel algorithms:
all_of
any_of
for_each
for_each_n
none_of
reduce
replace
replace_if
sort

The signatures for the following parallel algorithms are added but not parallelized at this time; profiling showed no benefit in parallelizing algorithms that only move or permute elements:
copy
copy_n
fill
fill_n
move
reverse
reverse_copy
rotate
rotate_copy
swap_ranges

https://docs.microsoft.com/en-us/cpp/what-s-new-for-visual-cpp-in-visual-studio
Last edited on
Hello JLBorges:
Many thanks for giving link:
std::reduce http://en.cppreference.com/w/cpp/algorithm/reduce

I have Microsoft Visual Studio Professional 2017 Version 15.5.1 (I have downloaded & installed yesterday from microsoft.com.

Example program at this link is also not compiling and giving following build error:

Error C4996 '_Experimental_parallel_algorithms': warning STL4019: Parallel algorithms support is experimental in this release of Visual C++.
This warning will be removed when parallel algorithms support is completed in a future update.

Any suggestion for compiling this program without errors please?

Best regards,

#include <iostream>
#include <chrono>
#include <vector>
#include <numeric>
#include <execution>

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::reduce(std::execution::par, v.begin(), v.end());
auto t2 = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> ms = t2 - t1;
std::cout << "std::reduce result "
<< result << " took " << ms.count() << " ms\n";
}
}
> Error C4996 '_Experimental_parallel_algorithms':
> warning STL4019: Parallel algorithms support is experimental in this release of Visual C++.

This is just a warning being treated as an error.
The -sdl compiler option causes certain warnings to be treated as errors.
See: https://msdn.microsoft.com/en-us/library/jj161081.aspx

This feature can be disabled by specifying the option -sdl-
In the IDE, project properties -> Configuration Properties -> C/C++ -> General -> SDL checks: set to No.

Doing this would also disable some run-time checks which may be useful:
When /sdl is enabled, the compiler generates code to perform these checks at run time:

Enables the strict mode of /GS run-time buffer overrun detection, equivalent to compiling with #pragma strict_gs_check(push, on).

Performs limited pointer sanitization. In expressions that do not involve dereferences and in types that have no user-defined destructor, pointer references are set to a non-valid address after a call to delete. This helps to prevent the reuse of stale pointer references.

Performs class member initialization. Automatically initializes all class members to zero on object instantiation (before the constructor runs). This helps prevent the use of uninitialized data associated with class members that the constructor does not explicitly initialize.


The other option (which does not turn off all sdl checks) is to specify
#pragma warning(disable: 4996) right at the beginning.
Last edited on
Hello JLBorges:
Thank you very much for the very helpful information.

I have built (i.e. compiled) the program without errors.
1>------ Rebuild All started: Project: parallel_sum, Configuration: Debug Win32 ------
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

However, I am not able run (or debug) the program. It is saying:
Unable to start program C:\...\parallel_sum\Debug\parallel_sum.exe
The system cannot find the file specified.

I do not know which folder path exe file has been created? With previous versions of visual studio, it used to create exe file in Debug sub-folder of the project/solution folder. With 15.5.1 version it did not create the exe file in the Debug sub folder.

Another issue with Visual Studio C++ 2017 professional version 15.5.1 is:
Microsoft has introduced "Project Templates" concept with version 15.5.1 and Visual Studio is asking me to download and install Visual C++ template every time I close Visual Studio and restart Visual Studio.

Any information/help in resolving these two issues with Visual Studio C++ 15.5.1 version please?

Is Code Blocks C++ compiler has latest Visual C++ 17 Parallel Tech Standard & File System features implemented?

Again many thanks for your help and information.
Best regards,
Thank you JLBorges:
I ran the parallel_sum.exe and got output results.
std::accumulate result 5000003.500000 took 243.117927 ms
std::reduce result 5000003.500000 took 11.410495 ms

Looks like I got both issues that I have stated in my previous reply are resolved.
Many thanks again for your excellent help/information.
Best regards
A third (better) option to turn off this warning:
#define _SILENCE_PARALLEL_ALGORITHMS_EXPERIMENTAL_WARNING

The rationale for this warning is given in this blog post:
Including <execution> now emits “warning STL4019: Parallel algorithms support is experimental in this release of Visual C++. Object files and static libraries that include <execution> may need to be rebuilt to link with a future update of Visual C++, and programs using <execution> may not run on Windows XP. This warning will be removed when parallel algorithms support is completed in a future update. You can define _SILENCE_PARALLEL_ALGORITHMS_EXPERIMENTAL_WARNING to acknowledge that you have received this warning.”
https://blogs.msdn.microsoft.com/vcblog/2017/12/19/c17-progress-in-vs-2017-15-5-and-15-6/
JLBorges,
Thank you very much for the very useful information.
Best regards,

Following non-parallel code (modified from C++ 17 STL Cookbook by Jacek Galowicz, Packt Press compiles, runs and gives the following output:


50% of the numbers are odd.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <vector>
#include <random>
#include <algorithm>

using namespace std;

static bool odd(int n) { return n % 2; }

int main()
{
	vector<int> d(500);

	mt19937 gen;
	uniform_int_distribution<int> dis(0, 100000);

	auto rand_num([=]() mutable { return dis(gen); });
	generate(begin(d), end(d), rand_num);
	sort(begin(d), end(d));
	reverse(begin(d), end(d));
	auto odds(count_if(begin(d), end(d), odd));

	cout << (100.0 * odds / d.size()) << "% of the numbers are odd.\n";
}


Above code compiles and runs, but NOT the below shown code from Jacek Calowicz book titled C++ 17 STL Cookbook, Packt press.

Following parallel version of code giving compile errors:
generate: E0304 no instance of function template "std::generate" matches argument list
count_if: E0304 no instance of function template "std::count_if" matches argument list



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#pragma warning(disable: 4996)

#include <iostream>
#include <vector>
#include <random>
#include <algorithm>
// #include <execution_policy>
#include <execution>

using namespace std;	

static bool odd(int n) { return n % 2; }

int main()
{
    vector<int> d (500);

    mt19937 gen;
    uniform_int_distribution<int> dis(0, 100000);

    auto rand_num ([=] () mutable { return dis(gen); });
    generate(execution::par, begin(d), end(d), rand_num);
    sort(execution::par, begin(d), end(d));
    reverse(execution::par, begin(d), end(d));
	auto odds(count_if(execution::par, begin(d), end(d), odd));

    cout << (100.0 * odds / d.size()) << "% of the numbers are odd.\n";
}


Any ideas/help to fix the above compile errors with generate and count_if using Microsoft Visual C++ Professional 2017 Version 15.5.1 please?




Last edited on
As of the current release, the parallel algorithms:supported are the ones listed in the blog linked to in this post:
http://www.cplusplus.com/forum/general/226814/#msg1033903

Hopefully, support for more parallel algirithms would be available in the next release (which is imminent).

Version 15.6 preview 2: https://www.visualstudio.com/en-us/news/releasenotes/vs2017-Preview-relnotes
Thanks for the information about MS VC++ 15.6.
Topic archived. No new replies allowed.