Two error messages in the code while parallelizing a loop

Asked By 10 points N/A Posted on -
qa-featured

 

Hi all,

In a class member function, I try to parallelize a loop, but I find two error messages in the code:

class myclass  
{  
public:  

int _k;  

void f(int nb_examples, int nb_try)  
{  
      int i;  
      int ks[nb_try];  
      // assignment to elements in ks  
      omp_set_num_threads(_nb_threads);  
    #pragma omp parallel shared(ks) private(i, _k) // error: ‘myclass::_k’ is not a variable in clause ‘private’  
      {  
    #pragma omp for schedule(dynamic) nowait  
        for(i=0; i < nb_try; i ++){  
          _k = ks[i];  
          if (_k > nb_examples)  break;// error: break statement used with OpenMP for loop  
          // operations on _k  
        }  
      }  
}  
}

I need to solve these errors. Please help me.

Thanks in advance.

SHARE
Answered By 0 points N/A #149232

Two error messages in the code while parallelizing a loop

qa-featured

Hello Kurt,

When parallelizing loops for multicore platforms, the following conditions must be met, otherwise you it will result into an error like the one you are getting right now.  The following 3 requirements must be fulfilled for the compiler to be able to parallelize a loop:

  • You will need to check and make sure that the number of iterations is known before entry into a loop. That will enable the work to be divided in advance. If the loop is a while loop for instance, it cannot be made parallel.
  • Ensure that there are no jumps into or out of the loop.
  • The loop iterations have to be independent – the cross-iteration dependencies should not be there.

Hope this helps.

Regards,

Carl

Login/Register to Answer

Related Questions