我有一段代码,我已经帕拉图,请看下面。代码在开始时运行得非常快,但是在特定的迭代之后它会变慢。
// something before this ...
// filename_list is quite long, 100k+ files
vector<string> some_string_list(filename_list.size(), " ");
int file_count = filename_list.size();
int counter = 0;
#pragma omp parallel for reduction(+:counter) schedule(auto)
for (int i = 0; i < file_count; i++)
{
string loop_filename = filename_list[i];
counter++;
// The filename is used to call a class member function and get some data, the file is used for reading
// This is the heavy part of code
some_string_list[i] = someclassinstance.getSomeString(loop_filename, param1, param2);
int temp = counter;
if(temp % 1000 == 0)
{
cout << "." << flush;
}
}
cout << endl;我尝试了不同的调度和块大小,但没有帮助。我很感谢你的建议。
谢谢!
发布于 2016-04-12 21:59:58
感谢你们所有的有用的评论。实际上,瓶颈在于HDD上的IO (读取)。初始速度的提高也是文件被缓存的结果。我复制了SSD驱动器上的数据,在这种情况下,并行化产生了巨大而明显的差异,IO不会成为一个大瓶颈。
https://stackoverflow.com/questions/36569394
复制相似问题