__gnu_parallel::sort()对空间是否有要求 博客分类: c++
程序员文章站
2024-03-19 10:59:34
...
目的:在使用__gnu_parallel::sort()时,发现改方法对空间好像有要求,所以测试__gnu_parallel::sort()的空间
需求。
方法: 在4G内存的机器上运行一个大的数据,然后调用__gnu_parallel::sort()排序,看是否能正常运行。
结果:该方法确实需要两倍的排序空间
#include <iostream> #include <vector> #include <stdio.h> #include<stdlib.h> #include<string> ///STL parallel sort Library #include <parallel/algorithm> using uint32 = unsigned int; using uint64 = unsigned long long int; using uint8 = unsigned char; int main() { uint32 s_len = 3*1014*1024*1024; uint8 * buf = new uint8[s_len]; std::cout << "s_len = " << s_len / 1024 / 1024 / 1024 << "G.\n"; for(uint32 i = 0; i < s_len; ++i){ buf[i] = rand()%256; } std::cout << "buffer is ready.\n"; std::cout << "start to sort.\n"; __gnu_parallel::sort(buf,buf+s_len,std::less<uint8>()); std::cout << "sort closed.\n"; std::cout << "close.\n"; return 0; }