由于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