Compilation failure: "const" assignment in LoopControl/src/loopcontrol.cc

Issue #2548 wontfix
Bernard Kelly created an issue

Fresh download & first compilation of the latest ETK release. Compilation fails during LoopControl because a dynamic variable is used to set a const constexpr parameter “lc_random_range”. Here’s the error message:

COMPILING Carpet/LoopControl/src/loopcontrol.cc /gpfs/scratch/bjk0015/codes/Cactus_ET_2021_05/arrangements/Carpet/LoopControl/src/loopcontrol.cc(70): error: function call must have a constant value in a constant expression lc_random.max() - lc_random.min() + 1; ^

/gpfs/scratch/bjk0015/codes/Cactus_ET_2021_05/arrangements/Carpet/LoopControl/src/loopcontrol.cc(70): error: function call must have a constant value in a constant expression lc_random.max() - lc_random.min() + 1;

… though it’s useful to see the full assignment, which begins the line before (line 69):

minstd_rand::result_type const constexpr lc_random_range = lc_random.max() - lc_random.min() + 1;

Fix: take out the “const” and “constexpr” descriptors from the lc_random_range declaration. git diff is attached.

Further notes:

The compilation is on the WVU machine Spruce Knob, using the Intel 17.0.1 compiler. I’m using the following configuration options:

CC=icc

CFLAGS=-Ofast -qopenmp -xHost  -align -std=gnu99

CPP=cpp

CPPFLAGS=-DMPICH_IGNORE_CXX_SEEK

CPP_DEBUG_FLAGS=-DCARPET_DEBUG

CPP_OPENMP_FLAGS=-fopenmp

CROSS_COMPILE=yes

CXX=icpc

CXXFLAGS=-Ofast -qopenmp -xHost  -align -std=gnu++11

CXX_DEBUG_FLAGS=-O0

CXX_NO_OPTIMISE_FLAGS=-O0

CXX_OPENMP_FLAGS=-fopenmp

CXX_OPTIMISE_FLAGS=-Ofast

CXX_PROFILE_FLAGS=-pg

C_DEBUG_FLAGS=-O0

C_LINE_DIRECTIVES=yes

C_NO_OPTIMISE_FLAGS=-O0

C_OPENMP_FLAGS=-fopenmp

C_OPTIMISE_FLAGS=-Ofast

C_PROFILE_FLAGS=-pg

Comments (8)

  1. Roland Haas

    Hmm, these may be causes by a change in C++ where constexpr and const are not longer implying each other, though why it would only happen for you with Intel17 I am not sure. Could be the same library mismatch as in #2457 but I kind of doubt it.
    I took a look at the reference for the function call (min) in question: https://en.cppreference.com/w/cpp/numeric/random/linear_congruential_engine/min and it is declared as

    static constexpr result_type min();
    

    so the compiler error seems odd. The only thing I can think of is that either the C++ standard library used (incorrectly) does not declare it as constexpr, or that the compiler gets confused b/c I am calling a static class function via an object.

    I will try and see if minstd_rand::minx() works instead, assuming I can find a cluster where I can reproduce the issue.

  2. Roland Haas

    I can compile fine with Intel 17 on Blue Waters if I use a modern enough C++ library. However if I force it to use gcc 4.3 by using --gxx-name then I get the same error that you see:

    COMPILING Carpet/LoopControl/src/loopcontrol.cc
    /mnt/a/u/staff/rhaas/ET_Next/arrangements/Carpet/LoopControl/src/loopcontrol.cc(70): error: function call must have a constant value in a constant expression
          lc_random.max() - lc_random.min() + 1;
                    ^
    
    /mnt/a/u/staff/rhaas/ET_Next/arrangements/Carpet/LoopControl/src/loopcontrol.cc(70): error: function call must have a constant value in a constant expression
          lc_random.max() - lc_random.min() + 1;
                                      ^
    
    compilation aborted for /mnt/a/u/staff/rhaas/ET_Next/configs/sim-intel/build/LoopControl/loopcontrol.cc (code 2)
    

    so both this and #2547 are due to a too old stdc++ library. Trying to work around this by using minstd_rand::max() does not work and gives:

    COMPILING Carpet/LoopControl/src/loopcontrol.cc
    /mnt/a/u/staff/rhaas/ET_Next/arrangements/Carpet/LoopControl/src/loopcontrol.cc(70): error: a nonstatic member reference must be relative to a specific object
          minstd_rand::max() - minstd_rand::min() + 1;
          ^
    
    /mnt/a/u/staff/rhaas/ET_Next/arrangements/Carpet/LoopControl/src/loopcontrol.cc(70): error: a nonstatic member reference must be relative to a specific object
          minstd_rand::max() - minstd_rand::min() + 1;
                               ^
    
    compilation aborted for /mnt/a/u/staff/rhaas/ET_Next/configs/sim-intel/build/LoopControl/loopcontrol.cc (code 2)
    

    indicating that the library does not declare the function correctly as a static class function and indeed digging into the header files on BlueWaters shows it to be defined as:

          result_type
          max() const
          { return __m - 1; }
    

    A workaround would be to remove constexpr from this line of code but given that thorn Vectors also fails with due to the same old C++ library, I am not sure if the workaround would help a lot (would only help in situations where LoopControl but not Vectors is used).

  3. Roland Haas

    i am closing this since this happens due to the the compiler used (gcc 4.8 does not support C++11 but only the technical report pre-standard version).

  4. Log in to comment