manodeep / Corrfunc

⚡️⚡️⚡️Blazing fast correlation functions on the CPU.
https://corrfunc.readthedocs.io
MIT License
167 stars 53 forks source link

Issues compiling with Intel ICX #326

Closed MatthieuSchaller closed 3 months ago

MatthieuSchaller commented 3 months ago

General information

Issue description

I am compiling with "Intel(R) oneAPI DPC++/C++ Compiler 2024.2.0 (2024.2.0.20240602)" and the compilation fails with C version errors:

 [login8a] Corrfunc > make CC=icx
mkdir -p lib
make -C theory
make[1]: Entering directory '/cosma8/data/dp004/jlvc76/Corrfunc/theory'
If you want to permanently set the default compiler to icx for all future compilations, please update the "CC" variable in "common.mk"

-------COMPILE SETTINGS------------
     MAKE        = ["make"]
     CC      = ["icx"]
     OPT         = ["-DPERIODIC -DENABLE_MIN_SEP_OPT  -DCOPY_PARTICLES  -DUSE_OMP"]
     CFLAGS      = ["-DVERSION=\"2.5.2\" -DUSE_UNICODE -std=c99 -m64 -g -Wsign-compare -Wall -Wextra -Wshadow -Wunused -fPIC -D_POSIX_SOURCE=200809L -D_GNU_SOURCE -D_DARWIN_C_SOURCE -O3 -funroll-loops -fno-strict-aliasing -Wformat=2 -Wpacked -Wnested-externs -Wpointer-arith -Wredundant-decls -Wfloat-equal -Wcast-qual -Wcast-align -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wstrict-prototypes -Wno-unused-local-typedefs"]
     CLINK       = ["-lrt  -lm"]
     PYTHON      = ["python"]
     GSL_CFLAGS  = [""]
     GSL_LINK    = [""]
     PYTHON_CFLAGS   = ["-isystem/cosma/local/Python/3.12.4/include/python3.12 -isystem /cosma/home/dphlss/jlvc76/.local/lib/python3.12/site-packages/numpy/_core/include"]
-------END OF COMPILE SETTINGS------------

make -C DD
make[2]: Entering directory '/cosma8/data/dp004/jlvc76/Corrfunc/theory/DD'
icx -DNDOUBLE_PREC -DVERSION=\"2.5.2\" -DUSE_UNICODE -std=c99 -m64 -g -Wsign-compare -Wall -Wextra -Wshadow -Wunused -fPIC -D_POSIX_SOURCE=200809L -D_GNU_SOURCE -D_DARWIN_C_SOURCE -O3 -funroll-loops -fno-strict-aliasing -Wformat=2 -Wpacked -Wnested-externs -Wpointer-arith -Wredundant-decls -Wfloat-equal -Wcast-qual -Wcast-align -Wmissing-declarations -Wmissing-prototypes -Wnested-externs -Wstrict-prototypes -Wno-unused-local-typedefs -I../../io -I../../utils  -c countpairs_impl_float.c -o countpairs_impl_float.o
icx: warning: -Wl,-rpath,/cosma/local/parallel-hdf5//intel_2024.2.0_ompi_5.0.3/1.14.4/lib: 'linker' input unused [-Wunused-command-line-argument]
icx: warning: -Wl,-rpath,/cosma/local/fftw//intel_2024.2.0_ompi_5.0.3/3.3.10/lib: 'linker' input unused [-Wunused-command-line-argument]
icx: warning: -Wl,-rpath,/cosma/local/ucx/1.13.0rc2/lib: 'linker' input unused [-Wunused-command-line-argument]
icx: warning: -Wl,-rpath,/cosma/local/gperftools/2.6.1/lib: 'linker' input unused [-Wunused-command-line-argument]
In file included from countpairs_impl_float.c:28:
In file included from ../../utils/gridlink_impl_float.h:26:
../../utils/cellarray_float.h:74:32: warning: redefinition of typedef 'cellarray_float' is a C11 feature [-Wtypedef-redefinition]
   74 | typedef struct cellarray_float cellarray_float;
      |                                ^
../../utils/cellarray_float.h:27:32: note: previous definition is here
   27 | typedef struct cellarray_float cellarray_float;
      |                                ^
../../utils/cellarray_float.h:75:8: error: redefinition of 'cellarray_float'
   75 | struct cellarray_float{
      |        ^
../../utils/cellarray_float.h:28:8: note: previous definition is here
   28 | struct cellarray_float{
      |        ^
1 warning and 1 error generated.
make[2]: *** [../../rules.mk:64: countpairs_impl_float.o] Error 1
make[2]: Leaving directory '/cosma8/data/dp004/jlvc76/Corrfunc/theory/DD'
make[1]: *** [Makefile:22: DD] Error 2
make[1]: Leaving directory '/cosma8/data/dp004/jlvc76/Corrfunc/theory'
make: *** [Makefile:9: theory] Error 2
lgarrison commented 3 months ago

Hmm, I suspect that the compiler isn't respecting #pragma once (which, admittedly, is non-standard). Interestingly, the Intel 2024.1 compiler that I have locally seems to compile Corrfunc fine. Might be worth trying to downgrade as a debugging step, if it's easy.

We're using #pragma once in 25 files. Maybe you could try changing the one in utils/cellarray_float.h.src to a traditional include guard to see if that changes anything? Then we can change the rest if it does.

manodeep commented 3 months ago

Thanks @MatthieuSchaller for reporting the issue.

Yeah this seems like a compiler issue rather than a code issue. If this is a double-include case (which seems likely), then Lehman's suggestion might be sufficient to fix the underlying issue.

If not a double-include situation, then one option to try could be to coalesce the typedef declaration with the definition that follows - something like

typedef struct 
{
....
} cellarray_DOUBLE;

Related: I don't understand the "linker" warnings (about the -Wl,-rpath ...) from the compiler - the linker should not be involved at all since this is a compile-only stage.

MatthieuSchaller commented 3 months ago

I'll try those. The llvm-based "oneAPI" is the new intel compiler replacing the regular icc pretty much everywhere. I wonder whether enforcing -std=c99 is possibly the issue here since the pragmas and the duplicate definitions are extensions to that standard.

MatthieuSchaller commented 3 months ago

Mmmh. Ok, identify the issue. It looks like somehow the auto-generated files (like cellarray_float.h and some in mocks) have received their content twice. That then trips up the compiler. I am not sure how that happened... Maybe trying different branches broke things?

Clearing all these files and starting from scratch worked smoothly. This can be closed.

lgarrison commented 3 months ago

Glad it's working! That explains why the line numbers were weird in the error message, I guess. (Did you try make -j at any point? I wonder if that could have caused something like this...)

MatthieuSchaller commented 3 months ago

I am definitely guilty of overusing make -j...

manodeep commented 3 months ago

Ahh yes - the Corrfunc Makefiles do not function in parallel. And yes make -j produces all kinds of fun compilation errors :)