I want to use the new parallel facilities of C 17 but my computer don't.
This works :
finalOutline.push_back(std::accumulate(intermediateCoefs.begin(), intermediateCoefs.end(),origin,[](sf::Vector2f prev, sf::Vector2f current) {
return sf::Vector2f(current.x prev.x, current.y prev.y);
}));
But this does not work :
finalOutline.push_back(std::accumulate(std::execution::seq, intermediateCoefs.begin(), intermediateCoefs.end(),origin,[](sf::Vector2f prev, sf::Vector2f current) {
return sf::Vector2f(current.x prev.x, current.y prev.y);
}));
Here the error message :
/home/mbs/Bureau/cplusplusWorkspace/sauvegardeGit/compresse-moi-ces-cercles/src/Model.cpp: In member function ‘void Model::computeFinalOutline(int)’:
/home/mbs/Bureau/cplusplusWorkspace/sauvegardeGit/compresse-moi-ces-cercles/src/Model.cpp:246:47: error: no matching function for call to ‘accumulate(const __pstl::execution::v1::sequenced_policy&, std::vector<sf::Vector2<float> >::iterator, std::vector<sf::Vector2<float> >::iterator, sf::Vector2f&, Model::computeFinalOutline(int)::<lambda(sf::Vector2f, sf::Vector2f)>)’
246 | finalOutline.push_back(std::accumulate(std::execution::seq, intermediateCoefs.begin(), intermediateCoefs.end(),origin,[](sf::Vector2f prev, sf::Vector2f current) {
| ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
247 | return sf::Vector2f(current.x prev.x, current.y prev.y);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
248 | }));
| ~~
I do include what it is needed (i guess):
#include <numeric>
#include <execution>
I always display the version of __cplusplus when I execute my programm and its value is : 202002
Here my CMAKE file (but i don't think it's usefull) :
cmake_minimum_required(VERSION 3.22) # way overkill
project(Taratari)
set (CMAKE_CXX_STANDARD 20)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS_DEBUG_INIT "-g -Wall -Wextra -pedantic -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c 2a")
include_directories(
$(PROJECT_SOURCE_DIR)/include
$(PROJECT_SOURCE_DIR)/src
)
file(GLOB all_SRCS
"${PROJECT_SOURCE_DIR}/include/*.h"
"${PROJECT_SOURCE_DIR}/src/*.cpp"
)
add_compile_options(
-mavx
)
#sfml
find_package(SFML REQUIRED system graphics network audio window) #too much flag no ?
add_executable(exe ${all_SRCS})
target_link_libraries(exe PRIVATE sfml-audio sfml-graphics sfml-network sfml-system sfml-window)
And to be really sure, here is gcc -v :
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.1.0-1ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c ,go,brig,d,fortran,objc,obj-c ,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --disable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-2V7zgg/gcc-11-11.1.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-2V7zgg/gcc-11-11.1.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.1.0 (Ubuntu 11.1.0-1ubuntu1~20.04)
So, I do not understand what is happening. Do I need a compilation flag ? (But the doc do not mention it).
Thank you for your help and have a nice day :-)
CodePudding user response:
std::accumulate
is meant to apply the binary operation in-order, so it doesn't make any sense to use an execution policy. It doesn't have any overload accepting one (see https://en.cppreference.com/w/cpp/algorithm/accumulate).
If you want to allow out-of-order evaluation with some execution policy, replace std::accumulate
by std::reduce
. std::reduce
may assume commutativity and associativity of the operation to reorder it into any permutation and apply it in any grouping of the elements.