OpenMP的 - while循环文本文件阅读和使用管道 [英] openmp - while loop for text file reading and using a pipeline

查看:880
本文介绍了OpenMP的 - while循环文本文件阅读和使用管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现,OpenMP的不支持while循环(或至少不喜欢他们太多)。
而且不喜欢'!='操作。

I discovered that openmp doesn't support while loops( or at least doesn't like them too much). And also doesn't like the ' != ' operator.

我有code这一点。

int count = 1;
#pragma omp parallel for
    while ( fgets(buff, BUFF_SIZE, f) != NULL )
    {
        len = strlen(buff);
        int sequence_counter = segment_read(buff,len,count);
        if (sequence_counter == 1)
        {
            count_of_reads++;
            printf("\n Total No. of reads: %d \n",count_of_reads);
        }
    count++;
    }

任何线索,如何管理呢?我读的地方(在计算器另一个帖子附带),我可以使用管道。那是什么 ?以及如何实现的呢?

Any clues as to how to manage this ? I read somewhere ( another post on stackoverflow included) that I can use a pipeline. What is that ? and how to implement it ?

推荐答案

一个实行平行而在OpenMP是使用whil​​e循环,创建任务的方式。这里是一个普遍的草图:

One way to implement "parallel while" in OpenMP is to use a while loop that create tasks. Here is a general sketch:

void foo() {
    while( Foo* f = get_next_thing() ) {
#pragma omp task firstprivate(f)
        bar(f);
    }
#pragma omp taskwait
}

有关遍历与fgets的具体情况,注意与fgets具有固有顺序语义(它获取的下一个行),这样就需要在启动任务之前被调用。这也将是重要的,每个任务自身通过与fgets返回的数据副本进行操作,这样就与fgets的调用不会覆盖由previous任务正在操作的缓冲区。

For the specific case of looping over fgets, note that fgets has inherently sequential semantics (it gets the "next" line), so it would need to be called before launching the task. It would also be important for each task to operate on its own copy of the data returned by fgets, so that a call to fgets does not overwrite the buffer being operated on by a previous task.

这篇关于OpenMP的 - while循环文本文件阅读和使用管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆