0

I am trying to run a code snippet using openmp, but it gives compile error as there is no initialization in the for loop. The iterator class is defined here. I am not able to figure out how can I initialize inside the for loop.

I am not an expert in C++, so I would appreciate any help.

ntHashIterator itr(seq, h, k);
#pragma omp parallel for  
for(; itr != itr.end(); ++itr){ 
   std::cout << (*itr)[0] << std::endl; 
}
2
  • 1
    Try for (ntHashIterator itr = ntHashIterator(seq, h, k); itr != itr.end(); ++itr) Commented Jun 26, 2018 at 5:56
  • 1
    Thanks @acraig5075 !! I tried that, but it was giving invalid controlling predicate error. I think the answer below explains that. Commented Jun 26, 2018 at 15:02

1 Answer 1

2

OpenMP requires loops to be in so-called canonical loop form. Moreover, it can works with iterators, but they have to be of a random-access iterator type. Which doesn't seem to be your case, since your nHashIterator does not support + and += operators. See the OpenMP specifications for more details.

Anyway, it's hard to tell more, since you are not providing enough details such as a compiler and OpenMP version which it supports.

Sign up to request clarification or add additional context in comments.

2 Comments

That the canonical loop form also requires it < end() as loop condition even if it is a random access iterator.
Thanks Daniel !! I got the idea now. I am using gcc (GCC) 7.3.0.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.