nextsimhub / nextsimdg

neXtSIM_DG : next generation sea-ice model with DG
https://nextsim-dg.readthedocs.io/en/latest/?badge=latest
Apache License 2.0
10 stars 13 forks source link

Compiling on Intel compiler #594

Open einola opened 2 days ago

einola commented 2 days ago

@andreapiacentini is having problems compiling the code using the intel suite of compilers. Andrea reports

In the meantime, the simple sequence of commands

mkdir build
cd build
cmake -DBoost_INCLUDE_DIR=${BOOST_INC_DIR} -DEigen3_DIR=${EIGEN_DIR}/share/eigen3/cmake ..
make VERBOSE=1

miserably ended very soon (much sooner than what happened with Eric's old branch even if ConfigMap.hpp is unchanged) I definitely need a little push toward c++ and cmake misteries (both far more modern than I am)

In file included from /home/ext/cf/cglo/piacentinia/SASIP/nextsimdg/core/src/include/Configured.hpp(11),
                 from /home/ext/cf/cglo/piacentinia/SASIP/nextsimdg/core/src/Logged.cpp(9):
/home/ext/cf/cglo/piacentinia/SASIP/nextsimdg/core/src/include/ConfigMap.hpp(17): error: qualified name is not allowed
  typedef std::variant<double, unsigned, int, std::string> Fusi;
          ^

In file included from /home/ext/cf/cglo/piacentinia/SASIP/nextsimdg/core/src/include/Configured.hpp(11),
                 from /home/ext/cf/cglo/piacentinia/SASIP/nextsimdg/core/src/Logged.cpp(9):
/home/ext/cf/cglo/piacentinia/SASIP/nextsimdg/core/src/include/ConfigMap.hpp(17): error: expected a ";"
  typedef std::variant<double, unsigned, int, std::string> Fusi;
                      ^

In file included from /home/ext/cf/cglo/piacentinia/SASIP/nextsimdg/core/src/include/Configured.hpp(11),
                 from /home/ext/cf/cglo/piacentinia/SASIP/nextsimdg/core/src/Logged.cpp(9):
/home/ext/cf/cglo/piacentinia/SASIP/nextsimdg/core/src/include/ConfigMap.hpp(18): error: identifier "Fusi" is undefined
  typedef std::map<std::string, Fusi> ConfigMap;
                                ^

In file included from /opt/softs/gcc/9.2.0/include/c++/9.2.0/bits/ios_base.h(46),
                 from /opt/softs/gcc/9.2.0/include/c++/9.2.0/ios(42),
                 from /opt/softs/gcc/9.2.0/include/c++/9.2.0/ostream(38),
                 from /opt/softs/gcc/9.2.0/include/c++/9.2.0/iterator(64),
                 from /opt/softs/libraries/ICC_2018.5.274/boost-1.81.0/include/boost/iterator/iterator_traits.hpp(10),
                 from /opt/softs/libraries/ICC_2018.5.274/boost-1.81.0/include/boost/range/iterator_range_core.hpp(26),
                 from /opt/softs/libraries/ICC_2018.5.274/boost-1.81.0/include/boost/lexical_cast.hpp(30),
                 from /opt/softs/libraries/ICC_2018.5.274/boost-1.81.0/include/boost/program_options/value_semantic.hpp(14),
                 from /opt/softs/libraries/ICC_2018.5.274/boost-1.81.0/include/boost/program_options/options_description.hpp(13),
                 from /opt/softs/libraries/ICC_2018.5.274/boost-1.81.0/include/boost/program_options.hpp(15),
                 from /home/ext/cf/cglo/piacentinia/SASIP/nextsimdg/core/src/include/Configurator.hpp(13),
                 from /home/ext/cf/cglo/piacentinia/SASIP/nextsimdg/core/src/include/Configured.hpp(13),
                 from /home/ext/cf/cglo/piacentinia/SASIP/nextsimdg/core/src/Logged.cpp(9):
/opt/softs/gcc/9.2.0/include/c++/9.2.0/bits/stl_function.h(437): error: identifier "__builtin_is_constant_evaluated" is undefined
        if (__builtin_is_constant_evaluated())
einola commented 2 days ago

My own attempt at compiling develop with intel also fail.

[einola@login-2.FRAM ~/src/nextsimdg/intel]$ icpc --version
icpc (ICC) 2021.6.0 20220226
Copyright (C) 1985-2022 Intel Corporation.  All rights reserved.
[ 67%] Building CXX object CMakeFiles/nextsimlib.dir/physics/src/modules/OceanBoundaryModule/ConfiguredOcean.cpp.o
/cluster/home/einola/src/nextsimdg/dynamics/src/include/CGDynamicsKernel.hpp(38): error: the default constructor of "Nextsim::DynamicsKernel<6, 8>" cannot be referenced -- it is a deleted function
      {
      ^
          detected during:
            instantiation of "Nextsim::CGDynamicsKernel<DGadvection>::CGDynamicsKernel() [with DGadvection=6]" at line 37 of "/cluster/home/einola/src/nextsimdg/dynamics/src/include/FreeDriftDynamicsKernel.hpp"
            instantiation of "Nextsim::FreeDriftDynamicsKernel<DGadvection>::FreeDriftDynamicsKernel(const Nextsim::DynamicsParameters &) [with DGadvection=6]" at line 26 of "/cluster/home/einola/src/nextsimdg/core/src/modules/DynamicsModule/include/FreeDriftDynamics.hpp"

[ 68%] Building CXX object CMakeFiles/nextsimlib.dir/physics/src/modules/OceanBoundaryModule/FluxConfiguredOcean.cpp.o
[ 69%] Building CXX object CMakeFiles/nextsimlib.dir/physics/src/modules/OceanBoundaryModule/TOPAZOcean.cpp.o
[ 70%] Building CXX object CMakeFiles/nextsimlib.dir/physics/src/modules/OceanBoundaryModule/UniformOcean.cpp.o
[ 71%] Building CXX object CMakeFiles/nextsimlib.dir/physics/src/modules/OceanBoundaryModule/module.cpp.o
compilation aborted for /cluster/home/einola/src/nextsimdg/core/src/modules/DynamicsModule/module.cpp (code 2)
make[2]: *** [CMakeFiles/nextsimlib.dir/build.make:510: CMakeFiles/nextsimlib.dir/core/src/modules/DynamicsModule/module.cpp.o] Error 2
make[2]: *** Waiting for unfinished jobs....
/cluster/home/einola/src/nextsimdg/dynamics/src/include/CGDynamicsKernel.hpp(38): error: the default constructor of "Nextsim::DynamicsKernel<6, 8>" cannot be referenced -- it is a deleted function
      {
      ^
          detected during:
            instantiation of "Nextsim::CGDynamicsKernel<DGadvection>::CGDynamicsKernel() [with DGadvection=6]" at line 55 of "/cluster/home/einola/src/nextsimdg/dynamics/src/include/VPCGDynamicsKernel.hpp"
            instantiation of "Nextsim::VPCGDynamicsKernel<DGadvection>::VPCGDynamicsKernel(Nextsim::StressUpdateStep<DGadvection, 8> &, const Nextsim::DynamicsParameters &) [with DGadvection=6]" at line 25 of "/cluster/home/einola/src/nextsimdg/dynamics/src/include/MEVPDynamicsKernel.hpp"
            instantiation of "Nextsim::MEVPDynamicsKernel<DGadvection>::MEVPDynamicsKernel(const Nextsim::DynamicsParameters &) [with DGadvection=6]" at line 25 of "/cluster/home/einola/src/nextsimdg/core/src/modules/DynamicsModule/MEVPDynamics.cpp"

compilation aborted for /cluster/home/einola/src/nextsimdg/core/src/modules/DynamicsModule/MEVPDynamics.cpp (code 2)
make[2]: *** [CMakeFiles/nextsimlib.dir/build.make:496: CMakeFiles/nextsimlib.dir/core/src/modules/DynamicsModule/MEVPDynamics.cpp.o] Error 2
/cluster/home/einola/src/nextsimdg/dynamics/src/include/CGDynamicsKernel.hpp(38): error: the default constructor of "Nextsim::DynamicsKernel<6, 8>" cannot be referenced -- it is a deleted function
      {
      ^
          detected during:
            instantiation of "Nextsim::CGDynamicsKernel<DGadvection>::CGDynamicsKernel() [with DGadvection=6]" at line 60 of "/cluster/home/einola/src/nextsimdg/dynamics/src/include/BrittleCGDynamicsKernel.hpp"
            instantiation of "Nextsim::BrittleCGDynamicsKernel<DGadvection>::BrittleCGDynamicsKernel(Nextsim::StressUpdateStep<DGadvection, 8> &, const Nextsim::DynamicsParameters &) [with DGadvection=6]" at line 30 of "/cluster/home/einola/src/nextsimdg/dynamics/src/include/BBMDynamicsKernel.hpp"
            instantiation of "Nextsim::BBMDynamicsKernel<DGadvection>::BBMDynamicsKernel(const Nextsim::DynamicsParameters &) [with DGadvection=6]" at line 17 of "/cluster/home/einola/src/nextsimdg/core/src/modules/DynamicsModule/BBMDynamics.cpp"

compilation aborted for /cluster/home/einola/src/nextsimdg/core/src/modules/DynamicsModule/BBMDynamics.cpp (code 2)
make[2]: *** [CMakeFiles/nextsimlib.dir/build.make:482: CMakeFiles/nextsimlib.dir/core/src/modules/DynamicsModule/BBMDynamics.cpp.o] Error 2
make[1]: *** [CMakeFiles/Makefile2:279: CMakeFiles/nextsimlib.dir/all] Error 2
make: *** [Makefile:91: all] Error 2

However, simply changing DynamicsKernel() = default to DynamicsKernel() {} in DynamicsKernel.hpp lets the code compile (but with some warnings for CGModelArray_test.cpp).

diff --git a/dynamics/src/include/DynamicsKernel.hpp b/dynamics/src/include/DynamicsKernel.hpp
index 63ba93e4..36fe7dee 100644
--- a/dynamics/src/include/DynamicsKernel.hpp
+++ b/dynamics/src/include/DynamicsKernel.hpp
@@ -41,7 +41,7 @@ public:
     typedef std::pair<const std::string, const DGVector<DGadvection>&> DataMapping;
     typedef std::map<typename DataMapping::first_type, typename DataMapping::second_type> DataMap;

-    DynamicsKernel() = default;
+    DynamicsKernel() {};
     virtual ~DynamicsKernel() = default;
     virtual void initialise(const ModelArray& coords, bool isSpherical, const ModelArray& mask)
     {

@timspainNERSC: Shouldn't the two be equivalent, or is there a subtle difference?

timspainNERSC commented 2 days ago

@timspainNERSC: Shouldn't the two be equivalent, or is there a subtle difference? 😬🤷

I'll have a quick investigate, but as I understand it, the two should be equivalent.

timspainNERSC commented 2 days ago

They are so not equivalent. The default constructor = default will initialize everything with its default value (zeroes, default constructors). An empty constructor {} explicitly says: We initialize nothing! Nothing! Good day, sir!

I did manage to remove a warning in Eclipse by initializing all the fields in DynamicsKernel.

diff --git a/dynamics/src/include/DynamicsKernel.hpp b/dynamics/src/include/DynamicsKernel.hpp
index 63ba93e..2f68eef 100644
--- a/dynamics/src/include/DynamicsKernel.hpp
+++ b/dynamics/src/include/DynamicsKernel.hpp
@@ -168,7 +168,7 @@
     }

 protected:
-    Nextsim::DGTransport<DGadvection>* dgtransport;
+    Nextsim::DGTransport<DGadvection>* dgtransport = nullptr;

     DGVector<DGadvection> hice;
     DGVector<DGadvection> cice;
@@ -181,9 +181,9 @@

     size_t stepNumber = 0;

-    double deltaT;
+    double deltaT = 0.;

-    Nextsim::ParametricMesh* smesh;
+    Nextsim::ParametricMesh* smesh = nullptr;

     virtual void updateMomentum(const TimestepTime& tst) = 0;

Does that allow ICC to build DynamicsKernel? (With the = default constructor)

einola commented 2 days ago

Ah, good to know about = default!

But it still doesn't compile. It's strange because the compiler says, "You deleted the constructor, so I can't call it" if we use = default but not if we use an empty constructor. But both are valid constructors and not deleted, right?!

I did find something potentially relevant on stackoverflow. It's about a bug in Visual Studio 2015, which seems to have been fixed*, but the accepted answer lists conditions under which a default constructor is deleted. Unfortunately, I can't tell if any of these are true for us.

*I verified that the MWE on stackoverflow compiles with my setup.