grackle-project / grackle

The Grackle chemistry and cooling library for astrophysical simulations and models.
Other
26 stars 50 forks source link

grackle doesn't compile with gcc > 11 #247

Closed EricTittley closed 3 weeks ago

EricTittley commented 3 weeks ago

calc_temp_cloudy_g.F compiles with gfortran 11.5, but fails with 13.3 or higher.

Compiler error:

/usr/lib/gcc/x86_64-linux-gnu/13/finclude/omp_lib.h:324:75:

  324 |         function omp_aligned_calloc (alignment, nmemb, size, allocator)   &
      |                                                                           1
Error: Unexpected junk after function declaration at (1)

and much more.

The errors are all in omp_lib.h

CLI used to reproduce the error:

gfortran-13 -c -fno-second-underscore -ffixed-line-length-132 -O3 -g -flto -fopenmp -DLINUX -DH5_USE_16_API -I./../include -I./autogen calc_temp_cloudy_g.F -fPIC -o .libs/calc_temp_cloudy_g.o

EricTittley commented 3 weeks ago

I think the problem is that -ffixed-line-length-132 is set for all fortran compilations in grackle so is used when compiling this bit of code, but is or has become incompatible with omp_lib.h

EricTittley commented 3 weeks ago

Ya, new code has been added to omp_lib.h that uses wrapping at the 72 character limit.

diff /usr/lib/gcc/x86_64-linux-gnu/13/finclude/omp_lib.h /usr/lib/gcc/x86_64-linux-gnu/11/finclude/omp_lib.h
(SNIP)
<       interface
<         function omp_aligned_calloc (alignment, nmemb, size, allocator)   &
<      &      bind(c)
<           use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t
<           use, intrinsic :: omp_lib_kinds
<           type(c_ptr) :: omp_aligned_calloc
<           integer(c_size_t), value :: alignment, nmemb, size
<           integer(omp_allocator_handle_kind), value :: allocator
<         end function omp_aligned_calloc
<       end interface
<       interface
<         function omp_aligned_calloc (alignment, nmemb, size, allocator)   &
<      &      bind(c)
<           use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t
<           use, intrinsic :: omp_lib_kinds
<           type(c_ptr) :: omp_aligned_calloc
<           integer(c_size_t), value :: alignment, nmemb, size
<           integer(omp_allocator_handle_kind), value :: allocator
<         end function omp_aligned_calloc
<       end interface
(SNIP)
EricTittley commented 3 weeks ago

Deleting the compiler agrument -ffixed-line-length-132 from the Make.mach.* fixes the issue. So not a bug with grackle but a bug with the example Make.mach.*

mabruzzo commented 3 weeks ago

@EricTittley I know you closed this, but I wanted to briefly follow up. I've been working to make Grackle compilation/installation a more frictionless experience (ideally compilation/installation should "just work" without any requiring any manual, tweaks).

Unfortunately the classic Make-based system is a little fragile and it would be non-trivial to achieve this experience. Did you by any chance try compiling Grackle with its new CMake build-system? (I'm curious to know if you encountered similar problems)

mabruzzo commented 3 weeks ago

Oh wait, I see your follow up message expanding on the source of the issues with openmp. Yeah, this would definitely fail with CMake too.

I'm actually working on porting internal Fortran routines to C++ so this issue should soon resolve itself (coincidentally, I started with the high-level routines that actually include the omp_lib.h header so I expect this will cease being a problem in the near-ish future)