Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Tim_S_4
Beginner
167 Views

Parallelization of loops with if clause

Hello,

recently, I started to use the -avx feature and I am trying to transform my applications to simd.
So, I am running into some issues for parallelizing this loop:

#pragma omp simd
for (int j=0; j<nParticlesInUse; j++) {
  if (particles.id != INVALID) {

    double dx = particles.x - particles.x;
    double dy = particles.y - particles.y;
    double r2 = dx * dx + dy * dy;
    if( r2 > cutoff*cutoff ) {
      //return;
    } else {
      r2 = fmax( r2, min_r*min_r );
      double r = sqrt( r2 );
      double coef = ( 1 - cutoff / r ) / r2 / mass;
      particles.ax += coef * dx;
      particles.ay += coef * dy;

      if (particles.ax*particles.ax + particles.ay*particles.ay > 10000000) {
        particles.ax = 0; // here1
        particles.ay = 0; // here2
      }
    }
  }
}

I am getting an issue for the assignment in the if clause (here1 and here1):

      LOOP BEGIN at particle_simulation.cpp(1413,3)
         remark #15336: simd loop was not vectorized: conditional assignment to a scalar   [ test.cpp(1436,5) ]
         remark #13379: loop was not vectorized with "simd"
         remark #25015: Estimate of max trip count of loop=100
      LOOP END

I am using icc version 16.

In the Intel guide for vectorizing loops [1] I found this statement. However, I don't know how I can apply it to my situation:

The loop should consist primarily of straight-line code. There should be no jumps or branches such as switch statements, but masked assignments are allowed, including if-then-else constructs that can be interpreted as masked assignments.

Can somebody help me how to handle this if clause? Is there any best practice for these cases?
I am thankful for every pointer/help :)

Best regards

Tim

[1] https://software.intel.com/en-us/articles/requirements-for-vectorizable-loops

0 Kudos
6 Replies
Markus_W_Intel1
Employee
167 Views

Hello Tim,

Thank you for your question. From the issue you listed, it appears that the if clause was not vectorized with SIMD correctly. If you'll have a look at this SIMD article, you will see how to adjust your if clause.

Best Regards,

Markus

Tim_S_4
Beginner
167 Views

Hello Markus,

thank you for your feedback. I have read the article twice. Unfortunately,
I cannot find any pointer to my specific problem. You mentioned that the loop
was not vectorized correctly. Perhaps you can help me with these two questions:

a) What does the icc compiler means with scalar?

b) Can you describe the error message to me with some other words?
>> simd loop was not vectorized: conditional assignment to a scalar
   I don't understand this error message.

Best regards,

Tim

Markus_W_Intel1
Employee
167 Views

Tim,

Both questions have already been addressed in this diagnostic, so please take a look at it. This link as well as related articles in it answer both of your questions.

For additional knowledge, I have included this Auto-Vectorization tutorial which I believe might be of more assistance to you.

Best Regards,

Markus

TimP
Black Belt
167 Views

Among other issues, if you can use intel c++, std::max() is more amenable to optimization than fmax(). Unlike gcc which uses -ffast-math to discard the special requirements of fmax.
Tim_S_4
Beginner
167 Views

Hello Tim(P),

thank you very much for your pointer. I see that you are flying all around in this forum.
Perhaps you can help me with my parallelization issue. I read Markus's diagnostic article
and the "A Guide to Vectorization with Intel C++ Compilers". So, I believe that I got some
basic understanding about vectorization. Unfortunately, I am still not able to fix the loop.
Inserting lastprivate(particles.ax) in the pragma statement leads to
the error:

particle_simulation.cpp(1413): error: invalid entity for this variable list in omp clause
              #pragma omp simd lastprivate(particles.ax)

Do you know if the variable must have an arithmetic data type like int, float, double,... etc.?

Cheers!

Tim(S)

Tim_S_4
Beginner
167 Views

Okay, I could find the issue :) Problem solved :) thanks for all the pointers and help.

Best regards,

Tim
 

Reply