Using while loops instead of for loops may inhibit vectorization.
Vectorization works by performing certain mathematical operations over vectors instead of over each of their individual elements one by one. Modern hardware has special units to perform these kinds of operations in a very efficient way. Vector operations are obvious for instance when adding two 3-dimensional points. However, vectorization is not restricted to vector mathematical operations: many times loops performing computations over a set of data elements can also be vectorized. Such loops need to fulfill some requirements though, one of them being that the number of iterations needs to be known before entering the loop so that the compiler can chunk the data into vectors. Normally, compilers can successfully count the number of iterations of most for loops; however, they tend to struggle for other types such as while loops. This is especially true for older compilers. Thus, the use of for loops is encouraged.
Rewrite the loop so that its number of iterations can be counted.
Get started with Parallelware Analyzer today
Boost the performance of your code