openmp - while loop for text file reading and using a pipeline

后端 未结 3 1167
遥遥无期
遥遥无期 2020-12-15 15:02

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.

I have this bit of cod

3条回答
  •  温柔的废话
    2020-12-15 15:24

    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
    }
    

    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.

提交回复
热议问题