dash icon indicating copy to clipboard operation
dash copied to clipboard

constexpr function return is non-constant

Open devreal opened this issue 7 years ago • 8 comments

In my humble try to compile DASH with all compilers we support, I also tried to use the latest Cray CCE to compile the DASH part. While this has not been successful so far (some symbols are missing during linking), the following warnings could be relevant nevertheless:

CC-12251 crayc++: WARNING File = /zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-development/dash/include/dash/pattern/BlockPattern1D.h, Line = 724
  constexpr function return is non-constant
      return global(_team->myid(), std::array<IndexType, 1> {{ l_index }})[0];
             ^
          A template was detected during header processing.
            The instantiation of "std::array<IndexType, 2UL>
                      dash::BlockPattern<1, Arrangement,
                      IndexType>::initialize_local_range(dash::BlockPattern<1,
                      Arrangement, IndexType>::SizeType) const [with
                      Arrangement=(dash::MemArrange)1,
                      IndexType=dash::default_index_t]" at line 319
            The instantiation of "dash::BlockPattern<1, Arrangement,
                      IndexType>::BlockPattern(dash::BlockPattern<1,
                      Arrangement, IndexType>::SizeSpec_t,
                      dash::BlockPattern<1, Arrangement,
                      IndexType>::DistributionSpec_t, dash::Team &) [with
                      Arrangement=(dash::MemArrange)1,
                      IndexType=dash::default_index_t]" at line 769 of
                      "/zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-develop
                      ment/dash/include/dash/Array.h"
            The instantiation of "dash::Array<ElementType, IndexType,
                      PatternType>::Array(dash::Team &) [with
                      ElementType=node_t, IndexType=dash::default_index_t,
                      PatternType=dash::BlockPattern<1, (dash::MemArrange)1,
                      dash::default_index_t>]" at line 85 of
                      "/zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-develop
                      ment/dash/examples/app.01.mindeg/main.cpp"

CC-12251 crayc++: WARNING File = /zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-development/dash/include/dash/iterator/GlobIter.h, Line = 613
  constexpr function return is non-constant
      return self_t(
             ^
          A template was detected during header processing.
            The instantiation of "bool dash::Array<ElementType, IndexType,
                      PatternType>::allocate(const PatternType &) [with
                      ElementType=node_t, IndexType=dash::default_index_t,
                      PatternType=dash::BlockPattern<1, (dash::MemArrange)1,
                      dash::default_index_t>]" at line 1204 of
                      "/zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-develop
                      ment/dash/include/dash/Array.h"
            The instantiation of "bool dash::Array<ElementType, IndexType,
                      PatternType>::allocate(dash::Array<ElementType,
                      IndexType, PatternType>::size_type,
                      dash::DistributionSpec<1>, dash::Team &) [with
                      ElementType=node_t, IndexType=dash::default_index_t,
                      PatternType=dash::BlockPattern<1, (dash::MemArrange)1,
                      dash::default_index_t>]" at line 246 of
                      "/zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-develop
                      ment/dash/examples/app.01.mindeg/main.cpp"

CC-12251 crayc++: WARNING File = /zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-development/dash/include/dash/iterator/GlobIter.h, Line = 621
  constexpr function return is non-constant
      return self_t(
             ^
          Detected during instantiation of "dash::GlobIter<ElementType,
                    PatternType,
                    dash::GlobMem<std::remove_const<ElementType>::type,
                    dash::allocator::CollectiveAllocator<std::remove_const<Elem
                    entType>::type>>, dash::GlobPtr<ElementType, PatternType>,
                    dash::GlobRef<ElementType>> dash::min_element(const
                    dash::GlobIter<ElementType, PatternType,
                    dash::GlobMem<std::remove_const<ElementType>::type,
                    dash::allocator::CollectiveAllocator<std::remove_const<Elem
                    entType>::type>>, dash::GlobPtr<ElementType, PatternType>,
                    dash::GlobRef<ElementType>> &, const
                    dash::GlobIter<ElementType, PatternType,
                    dash::GlobMem<std::remove_const<ElementType>::type,
                    dash::allocator::CollectiveAllocator<std::remove_const<Elem
                    entType>::type>>, dash::GlobPtr<ElementType, PatternType>,
                    dash::GlobRef<ElementType>> &, Compare) [with
                    ElementType=node_t, PatternType=dash::BlockPattern<1,
                    (dash::MemArrange)1, dash::default_index_t>,
                    Compare=std::less<const node_t &>]" at line 331 of
                    "/zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-developme
                    nt/dash/examples/app.01.mindeg/main.cpp".

The Intel compiler has reported similar warnings.

devreal avatar Mar 10 '17 18:03 devreal

@devreal I fixed the code sections listed in the warnings you posted in PR #321. How did you obtain the constexpr warnings? I can't seem to generate them on my machines.

fuchsto avatar Mar 13 '17 18:03 fuchsto

I can't seem to produce them either with the Intel compiler (I was sure I saw them there). I threw the Cray compiler at your branch and it reported some more issues:

CC-12251 crayc++: WARNING File = /zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-development/dash/include/dash/pattern/BlockPattern1D.h, Line = 708
  constexpr function return is non-constant
      return global(_team->myid(), std::array<IndexType, 1> {{ l_index }})[0];
             ^
          A template was detected during header processing.
            The instantiation of "std::array<IndexType, 2UL>
                      dash::BlockPattern<1, Arrangement,
                      IndexType>::initialize_local_range(dash::BlockPattern<1,
                      Arrangement, IndexType>::SizeType) const [with
                      Arrangement=(dash::MemArrange)1, IndexType=long long]" at
                      line 319
            The instantiation of "dash::BlockPattern<1, Arrangement,
                      IndexType>::BlockPattern(dash::BlockPattern<1,
                      Arrangement, IndexType>::SizeSpec_t,
                      dash::BlockPattern<1, Arrangement,
                      IndexType>::DistributionSpec_t, dash::Team &) [with
                      Arrangement=(dash::MemArrange)1, IndexType=long long]" at
                      line 793 of
                      "/zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-develop
                      ment/dash/include/dash/Array.h"
            The instantiation of "dash::Array<ElementType, IndexType,
                      PatternType>::Array(dash::Array<ElementType, IndexType,
                      PatternType>::size_type, const dash::Array<ElementType,
                      IndexType, PatternType>::DistributionSpec_t &, dash::Team
                      &) [with ElementType=int, IndexType=long long,
                      PatternType=dash::BlockPattern<1, (dash::MemArrange)1,
                      long long>]" at line 810 of
                      "/zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-develop
                      ment/dash/include/dash/Array.h"
            The instantiation of "dash::Array<ElementType, IndexType,
                      PatternType>::Array(dash::Array<ElementType, IndexType,
                      PatternType>::size_type, dash::Team &) [with
                      ElementType=int, IndexType=long long,
                      PatternType=dash::BlockPattern<1, (dash::MemArrange)1,
                      long long>]" at line 53 of
                      "/zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-develop
                      ment/dash/examples/bench.02.memhog/main.cpp"
            The instantiation of "void test_array_alloc<T>(size_t) [with
                      T=int]" at line 19 of
                      "/zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-develop
                      ment/dash/examples/bench.02.memhog/main.cpp"

CC-12251 crayc++: WARNING File = /zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-development/dash/include/dash/pattern/BlockPattern1D.h, Line = 708
  constexpr function return is non-constant
      return global(_team->myid(), std::array<IndexType, 1> {{ l_index }})[0];
             ^
          A template was detected during header processing.
            The instantiation of "std::array<IndexType, 2UL>
                      dash::BlockPattern<1, Arrangement,
                      IndexType>::initialize_local_range(dash::BlockPattern<1,
                      Arrangement, IndexType>::SizeType) const [with
                      Arrangement=(dash::MemArrange)1,
                      IndexType=dash::default_index_t]" at line 319
            The instantiation of "dash::BlockPattern<1, Arrangement,
                      IndexType>::BlockPattern(dash::BlockPattern<1,
                      Arrangement, IndexType>::SizeSpec_t,
                      dash::BlockPattern<1, Arrangement,
                      IndexType>::DistributionSpec_t, dash::Team &) [with
                      Arrangement=(dash::MemArrange)1,
                      IndexType=dash::default_index_t]" at line 793 of
                      "/zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-develop
                      ment/dash/include/dash/Array.h"
            The instantiation of "dash::Array<ElementType, IndexType,
                      PatternType>::Array(dash::Array<ElementType, IndexType,
                      PatternType>::size_type, const dash::Array<ElementType,
                      IndexType, PatternType>::DistributionSpec_t &, dash::Team
                      &) [with ElementType=int,
                      IndexType=dash::default_index_t,
                      PatternType=dash::BlockPattern<1, (dash::MemArrange)1,
                      dash::default_index_t>]" at line 810 of
                      "/zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-develop
                      ment/dash/include/dash/Array.h"
            The instantiation of "dash::Array<ElementType, IndexType,
                      PatternType>::Array(dash::Array<ElementType, IndexType,
                      PatternType>::size_type, dash::Team &) [with
                      ElementType=int, IndexType=dash::default_index_t,
                      PatternType=dash::BlockPattern<1, (dash::MemArrange)1,
                      dash::default_index_t>]" at line 54 of
                      "/zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-develop
                      ment/dash/examples/bench.02.meminit/main.cpp"
            The instantiation of "bool init_array<T>(size_t) [with T=int]" at
                      line 32 of
                      "/zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-develop
                      ment/dash/examples/bench.02.meminit/main.cpp"
            The instantiation of "void perform_test<T>(size_t, size_t) [with
                      T=int]" at line 20 of
                      "/zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-develop
                      ment/dash/examples/bench.02.meminit/main.cpp"

CC-12251 crayc++: WARNING File = /zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-development/dash/include/dash/pattern/BlockPattern1D.h, Line = 708
  constexpr function return is non-constant
      return global(_team->myid(), std::array<IndexType, 1> {{ l_index }})[0];
             ^
          A template was detected during header processing.
            The instantiation of "std::array<IndexType, 2UL>
                      dash::BlockPattern<1, Arrangement,
                      IndexType>::initialize_local_range(dash::BlockPattern<1,
                      Arrangement, IndexType>::SizeType) const [with
                      Arrangement=(dash::MemArrange)1,
                      IndexType=dash::default_index_t]" at line 319
            The instantiation of "dash::BlockPattern<1, Arrangement,
                      IndexType>::BlockPattern(dash::BlockPattern<1,
                      Arrangement, IndexType>::SizeSpec_t,
                      dash::BlockPattern<1, Arrangement,
                      IndexType>::DistributionSpec_t, dash::Team &) [with
                      Arrangement=(dash::MemArrange)1,
                      IndexType=dash::default_index_t]" at line 769 of
                      "/zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-develop
                      ment/dash/include/dash/Array.h"
            The instantiation of "dash::Array<ElementType, IndexType,
                      PatternType>::Array(dash::Team &) [with
                      ElementType=node_t, IndexType=dash::default_index_t,
                      PatternType=dash::BlockPattern<1, (dash::MemArrange)1,
                      dash::default_index_t>]" at line 85 of
                      "/zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-develop
                      ment/dash/examples/app.01.mindeg/main.cpp"

CC-12251 crayc++: WARNING File = /zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-development/dash/include/dash/pattern/CSRPattern.h, Line = 751
  constexpr function return is non-constant
      return global(_team->myid(), std::array<IndexType, 1> {{ l_index }})[0];
             ^
          A template was detected during header processing.
            The instantiation of "void dash::CSRPattern<1, Arrangement,
                      IndexType>::initialize_local_range() [with
                      Arrangement=(dash::MemArrange)1, IndexType=int]" at line
                      378
            The instantiation of "dash::CSRPattern<1, Arrangement,
                      IndexType>::CSRPattern(const
                      std::vector<dash::CSRPattern<1, Arrangement,
                      IndexType>::size_type, std::allocator<dash::CSRPattern<1,
                      Arrangement, IndexType>::size_type>> &, dash::Team &)
                      [with Arrangement=(dash::MemArrange)1, IndexType=int]" at
                      line 133 of
                      "/zhome/academic/HLRS/hlrs/hpcjschu/src/dash/dash-develop
                      ment/dash/examples/bench.01.igups/main.cpp"

devreal avatar Mar 14 '17 10:03 devreal

These warnings are caused by Team.myid() which is not constexpr and probably never will. The value of _team->myid() could be stored in a member, but pattern constructors would then not be constexpr any more. I will try some workarounds, but it's not a bug, just a missed opportunity for compile-time optimization.

fuchsto avatar Mar 16 '17 09:03 fuchsto

The value of _team->myid() could be stored in a member, but pattern constructors would then not be constexpr any more.

Most (all?) pattern constructor are not constexpr anyway afaics. The value of team->myid() could be cached upon team creation so that should allow constexpr there as well.

devreal avatar Mar 16 '17 09:03 devreal

@devreal ... so ... what you are saying is that team ids are not cached at team creation? Why?

fuchsto avatar Mar 18 '17 06:03 fuchsto

Well, the team-relative unit ID is not cached from the start but queried on first request and then cached. The reason is that the unit ID in dash::Team::All() cannot be initialized in the constructor so this initialization is deferred. This is what makes dash::Team::myid() non-constexpr. A workaround could be to set the unit ID for dash::Team::All() during initialization in dash::Init(). The same holds true for dash::Team::size().

devreal avatar Mar 19 '17 18:03 devreal

I started implementing this but I'm stuck with the check for dash::is_initialized() in dash::Team::myid(). My understanding is that this check was required in case an application called dash::myid() before dash::Init() has been called. IMO, calling any DASH functionality (dash::myid() in this case) in a uninitialized DASH environment (before dash::Init() or after dash::Finalize()) is UB so the return value of dash::myid() is either -1 or the global unit ID that remained from the previous initialization.

devreal avatar Mar 19 '17 20:03 devreal

OK, so I think I slightly misunderstood the meaning of constexpr. The C++11 standard (https://github.com/cplusplus/draft/blob/master/papers/N3376.pdf) says in 7.1.5:

For a constexpr function, if no function argument values exist such that the function invocation sub- stitution would produce a constant expression (5.19), the program is ill-formed; no diagnostic required.

My understanding is that any constexpr member function accessing a member variable in a class that has no constexpr constructor is ill-formed (not only a missed chance for optimization). The constructors of dash::Team cannot be made constexpr since there is no constexpr c'tor for std::list.

We may need to revise our usage of constexpr, e.g., BlockPattern has no constexpr c'tor but constexpr member functions accessing member variables (local_at for example).

Or am I missing something here?

devreal avatar Mar 19 '17 22:03 devreal