Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/155.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ STXXL在使用非常快速的SSD时表现不佳_C++_Solid State Drive_Stxxl - Fatal编程技术网

C++ STXXL在使用非常快速的SSD时表现不佳

C++ STXXL在使用非常快速的SSD时表现不佳,c++,solid-state-drive,stxxl,C++,Solid State Drive,Stxxl,我目前正在编写一个工具,它使用STXXL查找硬盘上的一个大文件和内存中的向量之间的相似性。我在下面为Windows写了一个例子来说明我的意思。引用的文件大约38GB大,是用上述工具创建的 在普通HDD和SATA SSD上,它的性能相当不错,但在M.2或更快的SSD上,它最多只使用了bandwith的三分之一,尽管它可以获得更多 VS2017探查器表明 const_reference const_element(const blocked_index_type& offset) const

我目前正在编写一个工具,它使用STXXL查找硬盘上的一个大文件和内存中的向量之间的相似性。我在下面为Windows写了一个例子来说明我的意思。引用的文件大约38GB大,是用上述工具创建的

在普通HDD和SATA SSD上,它的性能相当不错,但在M.2或更快的SSD上,它最多只使用了bandwith的三分之一,尽管它可以获得更多

VS2017探查器表明

const_reference const_element(const blocked_index_type& offset) const
STXXL的函数,该函数间接调用

似乎是最慢的部分。有没有人知道它为什么表现不佳以及需要改变什么

先谢谢你

编辑:新代码的性能表:

Threads  CPU%   SSD MB/s   Time in s
8        72     450        265
6        64     560        286
4        52     720        329
2        29     790        600
1        17     900        1051
代码:

#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
typedef stxxl::向量_生成器::结果contentVecType;
int main(){
自动启动=标准::时钟::高分辨率时钟::现在();
常量字符串&sLibFile=“I:/DA/merged\u s\u 80\u h”;
常量int32_t&inumofethreads=1,inumofecs=24;
const int32_t&iDiv=inumofecs/iNumOfThreads;
omp_集合_num_线程(inumof线程);
ifstream fLibInfo(sLibFile+“_info.txt”);
uint64_t iSizeOfLib=0;
fLibInfo>>伊西佐夫利;
stxxl::wincall_文件*stxxlLibFile=新的stxxl::wincall_文件(sLibFile,stxxl::file::RDONLY);
const contentVecType**vLib=new const contentVecType*[iNumOfThreads];
对于(int32_t i=0;icbegin(),vLib[i]->cend(),vDummy.begin(),[](常量元组&a,常量元组&b){return get(a)CPU使用率如何?100%或更少?因为我有一个7700k,它是50%,但将相应的变量更改为8只会将它从SSD.TBH推到70%和450MB/s。使用所有这些
新的
表达式,我希望引用的局部性不好。在开始研究STXXL实现之前,我会修复它们。@rustyx我添加了一个表d做了一个公平的比较。另一个版本为每个线程添加了一个向量,现在它是一个常量。@mAlter在更新的版本中,只包含了对new的必要调用。
#include <inttypes.h>
#include <vector>
#include <random>
#include <ctime>
#include <limits>
#include <algorithm>
#include <tuple>
#include <chrono>

#include <stxxl/vector>
#include <stxxl/bits/io/wincall_file.h>

#include <omp.h>

using namespace std;

typedef stxxl::VECTOR_GENERATOR<tuple<uint32_t, uint32_t>, 16U, 16U, 4096 * 8, stxxl::RC>::result contentVecType;

int main() {
    auto start = std::chrono::high_resolution_clock::now();
    const string& sLibFile = "I:/DA/merged_s_80_h";
    const int32_t& iNumOfThreads = 1, iNumOfVecs = 24;
    const int32_t& iDiv = iNumOfVecs / iNumOfThreads;
    omp_set_num_threads(iNumOfThreads);

    ifstream fLibInfo(sLibFile + "_info.txt");
    uint64_t iSizeOfLib = 0;
    fLibInfo >> iSizeOfLib;

    stxxl::wincall_file* stxxlLibFile = new stxxl::wincall_file(sLibFile, stxxl::file::RDONLY);
    const contentVecType** vLib = new const contentVecType*[iNumOfThreads];
    for (int32_t i = 0; i < iNumOfThreads; ++i) {
        vLib[i] = new const contentVecType(stxxlLibFile, iSizeOfLib);
    }

    mt19937_64 rng(time(0));
    uniform_int_distribution<uint32_t> unii(1, numeric_limits<uint32_t>::max());
    vector<tuple<uint32_t,uint32_t>> vInput[24];
    for (int32_t i = 0; i < iNumOfVecs; ++i) {
        for (int32_t j = 0; j < 100000; ++j) {
            vInput[i].push_back(make_tuple(unii(rng),0));
        }
    }

    #pragma omp parallel for
    for (int32_t i = 0; i < iNumOfVecs; ++i) {
        sort(vInput[i].begin(), vInput[i].end());
    }

    #pragma omp parallel for
    for (int32_t i = 0; i < iNumOfThreads; ++i) {
        for (int32_t j = i* iDiv; j < (i+1)*iDiv; ++j) {
            vector<tuple<uint32_t, uint32_t>> vDummy(vInput[j].size());
            set_intersection(vInput[j].cbegin(), vInput[j].cend(), vLib[i]->cbegin(), vLib[i]->cend(), vDummy.begin(), [](const tuple<uint32_t, uint32_t>& a, const tuple<uint32_t, uint32_t>& b) { return get<0>(a) < get<0>(b); });
        }
    }


    for (int32_t i = 0; i < iNumOfThreads; ++i) {
        delete vLib[i];
    }
    delete[] vLib;
    delete stxxlLibFile;

    auto end = std::chrono::high_resolution_clock::now();
    cout << "Time: " << chrono::duration_cast<std::chrono::seconds>(end - start).count() << endl;
    return 0;
}