dftlibs / xcfun

XCFun: A library of exchange-correlation functionals with arbitrary-order derivatives
https://dftlibs.org/xcfun/
Mozilla Public License 2.0
57 stars 32 forks source link

Building with Intel Compilers (icpc / icc) not working #69

Closed chjacob-tubs closed 6 years ago

chjacob-tubs commented 6 years ago

I was trying to use Intel compilers (to check whether this breaks the Python bindings) but the code is not compiling. I tried to understand the problem, but did not succeed.

[ 1%] Building CXX object src/CMakeFiles/xcfun-objlib.dir/xcfun.cpp.o icpc: command line remark #10148: option '-vec-report0' not supported In file included from /home/christoph/sources/xcfun-mybranch/src/xcfun.cpp(15): /home/christoph/sources/xcfun-mybranch/src/xcint.hpp(70): error: expected an expression FOR_EACH(XC_MAX_ORDER, FP, ) ^

In file included from /home/christoph/sources/xcfun-mybranch/src/xcfun.cpp(15): /home/christoph/sources/xcfun-mybranch/src/xcint.hpp(70): error: expected a ">" FOR_EACH(XC_MAX_ORDER, FP, ) ^

In file included from /home/christoph/sources/xcfun-mybranch/src/xcfun.cpp(15): /home/christoph/sources/xcfun-mybranch/src/xcint.hpp(70): error: expected a ">" FOR_EACH(XC_MAX_ORDER, FP, ) ^

In file included from /home/christoph/sources/xcfun-mybranch/src/xcfun.cpp(15): /home/christoph/sources/xcfun-mybranch/src/xcint.hpp(70): error: expected an expression FOR_EACH(XC_MAX_ORDER, FP, ) ^

In file included from /home/christoph/sources/xcfun-mybranch/src/xcfun.cpp(15): /home/christoph/sources/xcfun-mybranch/src/xcint.hpp(70): error: expected a ">" FOR_EACH(XC_MAX_ORDER, FP, ) ^

In file included from /home/christoph/sources/xcfun-mybranch/src/xcfun.cpp(15): /home/christoph/sources/xcfun-mybranch/src/xcint.hpp(70): error: expected a ">" FOR_EACH(XC_MAX_ORDER, FP, ) ^

In file included from /home/christoph/sources/xcfun-mybranch/src/xcfun.cpp(15): /home/christoph/sources/xcfun-mybranch/src/xcint.hpp(70): error: expected an expression FOR_EACH(XC_MAX_ORDER, FP, ) ^

In file included from /home/christoph/sources/xcfun-mybranch/src/xcfun.cpp(15): /home/christoph/sources/xcfun-mybranch/src/xcint.hpp(70): error: expected a ">" FOR_EACH(XC_MAX_ORDER, FP, ) ^

In file included from /home/christoph/sources/xcfun-mybranch/src/xcfun.cpp(15): /home/christoph/sources/xcfun-mybranch/src/xcint.hpp(70): error: expected a ">" FOR_EACH(XC_MAX_ORDER, FP, ) ^

In file included from /home/christoph/sources/xcfun-mybranch/src/xcfun.cpp(15): /home/christoph/sources/xcfun-mybranch/src/xcint.hpp(70): error: expected an expression FOR_EACH(XC_MAX_ORDER, FP, ) ^

In file included from /home/christoph/sources/xcfun-mybranch/src/xcfun.cpp(15): /home/christoph/sources/xcfun-mybranch/src/xcint.hpp(70): error: expected a ">" FOR_EACH(XC_MAX_ORDER, FP, ) ^

In file included from /home/christoph/sources/xcfun-mybranch/src/xcfun.cpp(15): /home/christoph/sources/xcfun-mybranch/src/xcint.hpp(70): error: expected a ">" FOR_EACH(XC_MAX_ORDER, FP, ) ^

compilation aborted for /home/christoph/sources/xcfun-mybranch/src/xcfun.cpp (code 2) src/CMakeFiles/xcfun-objlib.dir/build.make:84: recipe for target 'src/CMakeFiles/xcfun-objlib.dir/xcfun.cpp.o' failed make[2]: [src/CMakeFiles/xcfun-objlib.dir/xcfun.cpp.o] Error 2 CMakeFiles/Makefile2:1060: recipe for target 'src/CMakeFiles/xcfun-objlib.dir/all' failed make[1]: [src/CMakeFiles/xcfun-objlib.dir/all] Error 2 Makefile:138: recipe for target 'all' failed make: *** [all] Error 2

robertodr commented 6 years ago

Which version of icpc are you using? I suspect it's not C++11 compliant. And it that's the case it means we need to put a CMake check (though I thought it was automatic, so it's a bit puzzling)

chjacob-tubs commented 6 years ago

The newest one I tried / have available is 2017.4.

robertodr commented 6 years ago

Disturbing, I will try to reproduce ASAP.

robertodr commented 6 years ago

I managed to compile without problems (apart from a warning on a deprecated flag) I think your Intel compilers are using header from a pre-C++11 standard library provided by an ancient GCC. What does icpc -v say for you? I get:

icpc version 17.0.4 (gcc version 6.4.0 compatibility)
chjacob-tubs commented 6 years ago

It does indeed say icpc version 17.0.4 (gcc version 5.0.0 compatibility)

I will try to fix my installation then ...

robertodr commented 6 years ago

No, your installation looks fine to me. GCC 4.8 is already enough for C++11 (you'd need 4.9 if you needed C++11 regexes) I'll see if our cluster has an Intel installed against GCC 5 and re-test.

robertodr commented 6 years ago

I managed to compile all the way down to this Intel compiler:

icpc -v
icpc version 12.1.2 (gcc version 4.6.0 compatibility)

which surprised me quite a bit, given your current predicament with something that looks perfectly fine. Can your icpc compile the following?

#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>

int main()
{
    std::vector<int> c = {1, 2, 3, 4, 5, 6, 7};
    int x = 5;
    c.erase(std::remove_if(c.begin(), c.end(), [x](int n) { return n < x; }), c.end());

    std::cout << "c: ";
    std::for_each(c.begin(), c.end(), [](int i){ std::cout << i << ' '; });
    std::cout << '\n';

    // the type of a closure cannot be named, but can be inferred with auto
    // since C++14, lambda could own default arguments
    auto func1 = [](int i = 6) { return i + 4; };
    std::cout << "func1: " << func1() << '\n';

    // like all callable objects, closures can be captured in std::function
    // (this may incur unnecessary overhead)
    std::function<int(int)> func2 = [](int i) { return i + 4; };
    std::cout << "func2: " << func2(6) << '\n';
}
chjacob-tubs commented 6 years ago

Yes it can, if I use the -std=c++11 option.

Which is not used when compiling XcFun. If I use --extra-cxx-flags='-std=c++11' XcFun compiles.

chjacob-tubs commented 6 years ago

I now installed CMake 3.11 instead of CMake 3.5 on our cluster and that solves the problem. So somehow CMake 3.5 does not tell icpc correctly that it has to use C++11.

robertodr commented 6 years ago

Indeed! CMake 3.6 is needed to pick up C++11 from Intel: https://cmake.org/cmake/help/v3.6/release/3.6.html#other Sorry for your troubles, but at least now we know that a properly set up Intel 12.1.2 works. @bast should I add -std=c++11 to the flags, or should I bump up CMake requirements? I think the former is most desirable, otherwise the same thing here reported will happen with PGI, which seems to be supported by XCFun.

bast commented 6 years ago

I agree that we should here add the flag.

robertodr commented 6 years ago

@chjacob-tubs can you check that #71 fixes your problems? If yes, close this issue. Thanks!

chjacob-tubs commented 6 years ago

Yes, works. Thankss a lot!