libCEED icon indicating copy to clipboard operation
libCEED copied to clipboard

Compiling libceed in a conda environment with gcc from conda

Open stefanozampini opened this issue 3 years ago • 4 comments

I was trying to compile libceed in a conda environment from PETSc (--download-libceed --download-libceed-commit=origin/main) and got a linking error

/home/zampins/miniforge/envs/ecrcml-cuda/bin/../lib/gcc/x86_64-conda-linux-gnu/9.4.0/../../../../x86_64-conda-linux-gnu/bin/ld: build/backends/opt/ceed-opt-operator.o: warning: relocation against CEED_VECTOR_ACTIVE in read-only section .text
/home/zampins/miniforge/envs/ecrcml-cuda/bin/../lib/gcc/x86_64-conda-linux-gnu/9.4.0/../../../../x86_64-conda-linux-gnu/bin/ld: build/interface/ceed-fortran.o: relocation R_X86_64_PC32 against symbol stdout@@GLIBC_2.2.5 can not be used when making a shared object; recompile with -fPIC
/home/zampins/miniforge/envs/ecrcml-cuda/bin/../lib/gcc/x86_64-conda-linux-gnu/9.4.0/../../../../x86_64-conda-linux-gnu/bin/ld: final link failed: bad value

this is because ${CC} --version expands to

(ecrcml-cuda) zampins@vulture:~/miniforge/Devel/petsc/arch-jed/externalpackages/git.libceed$ $CC --version
x86_64-conda-linux-gnu-cc (GCC) 9.4.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

My hack is to make CC_VENDOR editable from make command line

diff --git a/Makefile b/Makefile
index 44591efa..31123323 100644
--- a/Makefile
+++ b/Makefile
@@ -93,8 +93,8 @@ endif
 AFLAGS = -fsanitize=address #-fsanitize=undefined -fno-omit-frame-pointer
 
 # Note: Intel oneAPI C/C++ compiler is now icx/icpx
-CC_VENDOR := $(subst oneAPI,icc,$(firstword $(filter gcc clang icc oneAPI XL,$(subst -, ,$(shell $(CC) --version)))))
-FC_VENDOR := $(if $(FC),$(firstword $(filter GNU ifort XL,$(shell $(FC) --version 2>&1 || $(FC) -qversion))))
+CC_VENDOR ?= $(subst oneAPI,icc,$(firstword $(filter gcc clang icc oneAPI XL,$(subst -, ,$(shell $(CC) --version)))))
+FC_VENDOR ?= $(if $(FC),$(firstword $(filter GNU ifort XL,$(shell $(FC) --version 2>&1 || $(FC) -qversion))))
 
 # Default extra flags by vendor
 MARCHFLAG.gcc           := -march=native

Also, since conda (sigh) uses environment variables for CFLAGS and the like, I also had to modify those from the makefile

@@ -129,8 +129,8 @@ OMP_SIMD_FLAG := $(OMP_SIMD_FLAG.$(CC_VENDOR))
 OMP_SIMD_FLAG := $(if $(call cc_check_flag,$(OMP_SIMD_FLAG)),$(OMP_SIMD_FLAG))
 
 OPT    ?= -O -g $(MARCHFLAG) $(OPT.$(CC_VENDOR)) $(OMP_SIMD_FLAG)
-CFLAGS ?= $(OPT) $(CFLAGS.$(CC_VENDOR))
-CXXFLAGS ?= $(OPT) $(CXXFLAGS.$(CC_VENDOR))
+override CFLAGS += $(OPT) $(CFLAGS.$(CC_VENDOR))
+override CXXFLAGS += $(OPT) $(CXXFLAGS.$(CC_VENDOR))
 LIBCXX ?= -lstdc++
 NVCCFLAGS ?= -ccbin $(CXX) -Xcompiler "$(OPT)" -Xcompiler -fPIC
 ifneq ($(CUDA_ARCH),)

How are you planning to support this case?

stefanozampini avatar Mar 17 '22 14:03 stefanozampini

Hmm, would this address your use case? https://gitlab.com/petsc/petsc/-/merge_requests/4986

jedbrown avatar Mar 17 '22 14:03 jedbrown

Yes, modulo the fact that you may want to keep vendor optimization on from libceed and add them to he flags, or not?

stefanozampini avatar Mar 17 '22 15:03 stefanozampini

I think when PETSc is building libCEED, we shouldn't force in our own set of optimizations. Yes, libCEED (and especially qfunctions) benefit from aggressive optimization flags, but it's too confusing for us to add our own without the user asking.

jedbrown avatar Mar 18 '22 18:03 jedbrown

Is this resolved through the PETSc MR or is there still something libCEED needs to do?

jedbrown avatar Sep 06 '22 02:09 jedbrown

Closing, but re-open if needed

jeremylt avatar Apr 27 '23 17:04 jeremylt