STEllAR-GROUP / hpx

The C++ Standard Library for Parallelism and Concurrency
https://hpx.stellar-group.org
Boost Software License 1.0
2.53k stars 430 forks source link

Compilation errors using -fopenmp #6552

Open Pansysk75 opened 1 week ago

Pansysk75 commented 1 week ago

HPX does not compile when using -fopenmp (or -fopenmp-simd) on Clang or GCC.

Clang: Can't use pragma in constexpr function

/work/pansysk75/hpx-test/hpx/libs/core/algorithms/include/hpx/parallel/unseq/reduce_helpers.hpp:134:13: error: statement not allowed in constexpr function
            HPX_VECTOR_REDUCTION(& : init)
            ^
/work/pansysk75/hpx-test/hpx/libs/core/config/include/hpx/config/auto_vectorization.hpp:61:38: note: expanded from macro 'HPX_VECTOR_REDUCTION'
#define HPX_VECTOR_REDUCTION(CLAUSE) HPX_PRAGMA(omp simd reduction(CLAUSE))
                                     ^
/work/pansysk75/hpx-test/hpx/libs/core/config/include/hpx/config/auto_vectorization.hpp:27:23: note: expanded from macro 'HPX_PRAGMA'
#define HPX_PRAGMA(x) _Pragma(#x)
                      ^

Clang/GCC: Loops in non-canonical form

/work/pansysk75/hpx-test/hpx/libs/core/algorithms/include/hpx/parallel/unseq/loop.hpp:269:21: error: initialization clause of OpenMP for loop is not in canonical form ('var = init' or 'T var = init')
                    for (/**/; count < num; (void) ++count, ++it, ++dest)
                    ^

/work/pansysk75/hpx-test/hpx/libs/core/algorithms/include/hpx/parallel/unseq/loop.hpp:229:78: error: expected ‘;’ before ‘)’ token
  229 |                     for (HPX_UNUSED(count); count < num; (void) ++count, ++it)
      |                                                                              ^

GCC: invalid increment expression

/work/pansysk75/hpx-test/hpx/libs/core/algorithms/include/hpx/parallel/util/loop.hpp:953:49: error: invalid increment expression
  953 |                     for (std::size_t i = 0; i < count;

@hkaiser Should we add feature tests for these, or just disable them for Clang/GCC? I suppose these were added with the Intel compiler in mind?

hkaiser commented 1 week ago

Should we add feature tests for these, or just disable them for Clang/GCC? I suppose these were added with the Intel compiler in mind?

They were created for gcc and clang :/ @Johan511 is this code part of your contributions?

I'd rather make the functions non-constexpr in this case and try to fix the other problems.

Johan511 commented 1 week ago

The PR

The first error seems pretty self explanatory second is because the variable is not initialized is loop body third is because of 2 increments being done in the loop body

Unfortunately, openmp simd reduction is rather strict about how it wants the loop body to be Working Example