简体   繁体   English

OpenMP从磁盘顺序读取和并行处理

[英]OpenMP sequential reading from disc and parallel processing

There is my question: 我的问题是:

I have many files (more than 1000) of the same size (several Mb). 我有许多大小相同(几个Mb)的文件(超过1000个)。 I have to read them and extract some information. 我必须阅读它们并提取一些信息。 This step of the information extraction requires some time, so I can use (at least I hope so) this time to read another file. 信息提取的这一步骤需要一些时间,因此我可以(至少希望如此)这段时间来读取另一个文件。 What I try to do is: 我想做的是:

#pragma omp parallel for
for (int i=0; i<FilesCount; i++)
{
    myData Data;

    #pragma omp critical
    {
        Data.ReadDataFromFile (FileNames[i]);
    }

    //Operate with the Data and extract some information
}

It doesn't work as I expect. 它不符合我的预期。 I also tried to use: 我也尝试使用:

#pragma omp ordered

and the result is the same - only one thread is used. 结果是相同的-仅使用了一个线程。 Other OpenMP stuff works fine. 其他OpenMP东西也可以正常工作。 Maybe the problem is that I use fstream for the reading? 也许问题是我使用fstream进行阅读?

What is the problem with it and how to do that correctly? 它有什么问题以及如何正确执行?

Everything in a block marked with 标记为“

#pragma omp critical

will be executed by one thread at a time only. 一次只能由一个线程执行。 All other threads have to wait until the current thread leaves that block. 所有其他线程都必须等待,直到当前线程离开该块为止。

Section about 'critical' in an OpenMP tutorial OpenMP教程中有关“关键”的部分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM