Microsoft Dev Blogs

OpenMP improvements in Visual Studio C/C++ compiler: loop collapse

thumbnail
  • OpenMP loop collapse has been implemented in the Visual Studio C/C++ compiler.
  • Loop collapse allows for the combining of nested loops into a single giant loop to be split and executed on multiple threads.
  • The loop space must be rectangular for the implementation of the clause in OpenMP Standard 3.1.
  • The compiler generates code and calls runtime functions to calculate the number of iterations and obtain the original induction variables' values.
  • In OpenMP Standard 5.2, the lower and upper bounds of inner loops can depend on the induction variables of outer loops.
  • The compiler generates additional checks for non-rectangular loop nests and the runtime calculates the bounds of the chunks to execute.
  • The current implementation is generic and should work for any combination of loop bounds and increments allowed by the standard, with performance comparable to LLVM.
  • The feature is available in Visual Studio 2022 version 17.8 or newer and feedback is encouraged.