C ++并行std :: sort用于浮点值 [英] c++ parallel std::sort for floating values

查看:70
本文介绍了C ++并行std :: sort用于浮点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大文件,其中包含>百万个浮点值.我现在可以通过将文件读入vector来轻松地使用std::sort对它们进行排序,例如-

I've a large file consisting of > millions of floating point values. I can easily sort them using std::sort by reading file into vector for now, eg -

std::vector<float> v;
std::sort(v.begin(), v.end());

但是是否有任何版本的std::sort或类似的算法可以利用我系统上可用的多个内核?由于这是唯一需要花费大量时间设置的任务,因此我正在寻找具有1个以上核心CPU的性能改进.

but is there any version of std::sort or similar algorithm which takes advantage of multiple cores available on my system? Since this is the only task that takes much time setting up, I'm looking for perf improvements from having > 1 core cpu.

我可以在x64 linux服务器上使用任何最新版本的编译器,也可以使用-std=c++1z编译二进制文件.

I can use any latest releases of compilers on a x64 linux server and can compile the binary with -std=c++1z too.

推荐答案

您很幸运. 《 C ++并行技术扩展》添加了包括std::sort在内的许多标准算法的并行版本.它们在C ++ 17中可用. GCC支持此功能,您可以在此处上查看其页面. .看来他们正在利用OpenMP进行多线程处理.

You're in luck. The C++ Extensions for Parallelism Technical Specification added parallelized versions of the many of the standard algorithms including std::sort. They are available in C++17. GCC has support for this and you can see their page about it here. It looks as though they are utilizing OpenMP for multi-threading.

GCC先决条件编译器标志

GCC Prerequisite Compiler Flags

任何对并行功能的使用都需要附加的编译器和运行时支持,尤其是对OpenMP的支持.添加此支持并不困难:只需使用编译器标志-fopenmp编译您的应用程序.这将链接到libgomp(GNU卸载和多处理运行时库)中,该库的存在是必需的.

Any use of parallel functionality requires additional compiler and runtime support, in particular support for OpenMP. Adding this support is not difficult: just compile your application with the compiler flag -fopenmp. This will link in libgomp, the GNU Offloading and Multi Processing Runtime Library, whose presence is mandatory.

此外,支持原子操作的硬件和能够产生原子操作的编译器是必不可少的:GCC默认不支持某些常见硬件体系结构上的原子操作.激活原子操作可能需要在某些目标(例如sparc和x86)上使用显式的编译器标志,例如-march = i686,-march = native或-mcpu = v9.有关更多信息,请参见GCC手册.

In addition, hardware that supports atomic operations and a compiler capable of producing atomic operations is mandatory: GCC defaults to no support for atomic operations on some common hardware architectures. Activating atomic operations may require explicit compiler flags on some targets (like sparc and x86), such as -march=i686, -march=native or -mcpu=v9. See the GCC manual for more information.


我知道您说过您正在使用Linux,但我也想包括它似乎是MSVS,从2013 RTM版本开始,也支持并行技术规范.


I know you said you are using Linux but I also want to included that it appears MSVS, starting with version 2013 RTM, also has support for the Parallelism Technical Specification.

这篇关于C ++并行std :: sort用于浮点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆