代码之家  ›  专栏  ›  技术社区  ›  Tjcool

如何在最短时间内处理大文件(c++,openmp,输入文件:FASTQ/FASTA)

  •  0
  • Tjcool  · 技术社区  · 6 年前

    由于RAM(8gb)有限,我们试图将这个大的输入文件分块处理,将x个字符串放入一个向量中,并使用多个线程进行处理。此过程重复进行,直到输入文件中的所有字符串都得到完全处理。但这种方法非常缓慢。 我们甚至通过改变数组的大小(1000000个字符串)来测试代码,但这比1000个大小的数组需要更多的时间 如何在时间方面进行优化?

    示例代码:

    #include <zlib.h>
    #include <stdio.h>
    #include "kseq.h"
    #include <string>
    #include <vector>
    #include <iostream>
    #include <omp.h>
    int main()
    {
        gzFile fp;
        kseq_t *seq;
        int l;
        int it;
        int read_count=0;
        fp = gzopen("dm.fastq", "r");
        seq = kseq_init(fp);
        vector <string> array;       
     while ((l = kseq_read(seq)) >= 0) 
        {
                if (read_count <= 999) 
            {
                    array.push_back(seq->seq.s);
                    read_count++;
            }
                if (read_count == 1000) 
            {
            #pragma omp parallel for num_threads(12) schedule(static) private(it) shared(array)
                    for (it = 0; it < array.size(); ++it) 
                {
                    string line = array[it];
                                int size_s = line.size();
                                char _buf[size_s + 1];
                                strcpy(_buf, line.c_str());
                }
            array.clear();    
            read_count=0;
            }
        }
        #pragma omp parallel for num_threads(12) schedule(static) private(it) shared(array)
            for (it = 0; it < array.size(); ++it) 
                {
                                string line = array[it];
                                int size_s = line.size();
                                char _buf[size_s + 1];
                                strcpy(_buf, line.c_str());
                }
        
        kseq_destroy(seq);gzclose(fp);return 0;
    }//main close
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Galimov Albert    6 年前

    首先,您应该知道,仅仅从一个标准的旋转硬盘读取(不处理)100Gb文件大约需要17分钟。

    strcpy(_buf 一个)。这个 对于

    最后,大部分(比如90%)的CPU是在库中消耗的( kseq\u读取 )以及 gzopen公司