1. 6

OpenMP consists of a set of compiler #pragmas that control how the program works. The pragmas are designed so that even if the compiler does not support them, the program will still yield correct behavior, but without any parallelism.


  2. 3

    I’m automatically skeptical of anything that claims to make multithreading easy.

    1. 2

      Note that OpenMP also works for C. However, in C, you need to set explicitly the loop variable as private, because C does not allow declaring it in the loop body:

      int n;
      #pragma omp for private(n)
      for(n=0; n<10; ++n) printf(" %d", n);

      wat. The article was first written in 2007. Since C99, you have been able to declare variables in the for-loop preamble. The following works great for me, even when compiled with -std=c99:

      #include <stdio.h>
      #include <stdlib.h>
      main (void) {
          #pragma omp parallel for
          for ( int i = 0; i < 50; ++ i ) {
              puts(i % 2 == 0 ? "Hello" : "World");
          return EXIT_SUCCESS;
      1. 2

        It works fine with GCC, but MSVC does not support declaring the loop variable inside the for of parallel for in C. If you try to compile the above code as C, you get “error C3015: initialization in OpenMP ‘for’ statement has improper form”, whereas it compiles fine as C++.

        On a side note, MSVC does not allow the loop variable to be unsigned either (which I believe might be due to only supporting OpenMP 2.0, but still can be annoying (think size_t)).

        1. 4

          MSVC is not a C compiler.

          It is very explicitly a C++ compiler that just added enough C99 compatibility for the C++ compiler to stay correct.

          It is unreasonable to include it in the category of C compilers.

          1. 3

            While that is true, it does seem somewhat random that it does support declaring variables in C for loops, except when they happen to be OpenMP loops.