OpenMP 处理许多文件
我编写了一个程序,它与 openMP 对文件中的数据并行计算,
让我们说:
./foobar input.txt
我正在修改我的程序,这样,它将对许多文件执行相同的计算:
./foobar input1.txt input2.txt input3.txt
我的问题是:
以下两者之间哪个更有效: 准备好每个文件(大小可以达到数百兆字节)并对每个文件进行并行计算,
for (i = O; i < numberOfFile; i++)
calculationOn(filename[i]); // the calculation program run in parallel
或者让每个线程并行读取自己的文件并对其进行处理?
#pragma omp parallel for private(i)
for(i = 0; i < numberOfFile; i++)
calculationOn(filename[i]);
感谢您的回复!
I've write a program which compute a calculation in parallel with openMP on data from on a file,
let says :
./foobar input.txt
I'm on the way to modify my program such a way that, It's will do the same calculation but upon many files :
./foobar input1.txt input2.txt input3.txt
My question is :
what is suppose to be the more efficient between :
ready each file (which can reach hundred MegaByte in size) and do a calculation in parallel on each of them,
for (i = O; i < numberOfFile; i++)
calculationOn(filename[i]); // the calculation program run in parallel
or let each thread read in parallel it own file and work on it ?
#pragma omp parallel for private(i)
for(i = 0; i < numberOfFile; i++)
calculationOn(filename[i]);
thanks for any reply !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有很多文件,并且每个文件的输出独立于所有其他文件,那么您根本不需要 OpenMP。只需使用 GNU Parallel 之类的工具在多个处理器上并行运行整个程序即可获得线性加速。在这些情况下,对参数进行 OpenMP 循环可能非常浪费;就程序员的时间而言,就是这样。
If you have very many files and the output per file is independent of all the other files, then you don't need OpenMP at all. Just run entire the program in parallel on multiple processors with a tool like GNU Parallel to get linear speedup. An OpenMP loop over the arguments is likely quite wasteful in these cases; in terms of programmer time, that is.