Skip to content

Commit fb5e9ba

Browse files
committed
Check for wi4mpi specific compiler flags. Demo script sets compiler flags more carefully and warns about invalid python.
1 parent 49c9404 commit fb5e9ba

File tree

2 files changed

+77
-6
lines changed

2 files changed

+77
-6
lines changed

e4s_cl/cf/wi4mpi/install.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,16 @@ def install_wi4mpi(install_dir: Path) -> Optional[Path]:
214214
source_dir.as_posix(),
215215
]
216216

217+
# Apply custom CFLAGS/CXXFLAGS if provided via environment variables
218+
wi4mpi_cflags = os.environ.get('E4S_CL_WI4MPI_CFLAGS')
219+
wi4mpi_cxxflags = os.environ.get('E4S_CL_WI4MPI_CXXFLAGS')
220+
if wi4mpi_cflags:
221+
configure_cmd.append(f"-DCMAKE_C_FLAGS={wi4mpi_cflags}")
222+
LOGGER.debug("Using custom Wi4MPI CFLAGS: %s", wi4mpi_cflags)
223+
if wi4mpi_cxxflags:
224+
configure_cmd.append(f"-DCMAKE_CXX_FLAGS={wi4mpi_cxxflags}")
225+
LOGGER.debug("Using custom Wi4MPI CXXFLAGS: %s", wi4mpi_cxxflags)
226+
217227
build_cmd = [
218228
cmake_executable,
219229
"--build",

scripts/demo.sh

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,25 @@ if [[ "${E4S_CL_ONLY_CHECK:-0}" == "1" ]]; then
245245

246246
log "Checking Python..."
247247
if check_cmd python3; then
248-
log " Found: $(command -v python3) ($(python3 --version))"
248+
PYTHON_VERSION=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")' 2>/dev/null || echo "unknown")
249+
log " Found: $(command -v python3) (Python ${PYTHON_VERSION})"
250+
251+
# Check version (need 3.7+)
252+
if python3 -c "import sys; sys.exit(0 if sys.version_info >= (3, 7) else 1)" 2>/dev/null; then
253+
log " Version check: OK (>= 3.7)"
254+
else
255+
log " ERROR: Python ${PYTHON_VERSION} is too old (need 3.7+)"
256+
MISSING=1
257+
fi
258+
259+
# Check for ctypes support (required by e4s-cl)
260+
if python3 -c "import ctypes" 2>/dev/null; then
261+
log " ctypes support: OK"
262+
else
263+
log " ERROR: Python missing ctypes module (compiled without libffi)"
264+
log " Try: module unload python, or use a Python built with libffi-dev"
265+
MISSING=1
266+
fi
249267
else
250268
log " MISSING: python3"
251269
MISSING=1
@@ -431,6 +449,7 @@ fi
431449

432450
# Host MPI detection
433451
HOST_MPICC="${E4S_CL_HOST_MPI:-$(command -v mpicc || true)}"
452+
HOST_MPICXX="${E4S_CL_HOST_MPICXX:-$(command -v mpicxx || command -v mpic++ || true)}"
434453
HOST_MPIRUN="${E4S_CL_HOST_MPIRUN:-$(command -v mpirun || command -v mpiexec || true)}"
435454
[[ -n "${HOST_MPICC}" ]] || fail "Host MPI compiler not found (mpicc)"
436455
[[ -n "${HOST_MPIRUN}" ]] || fail "Host MPI launcher not found (mpirun or mpiexec)"
@@ -490,6 +509,34 @@ elif [[ -n "${HOST_MPI_FAMILY}" && -n "${CONTAINER_MPI_FAMILY}" && "${HOST_MPI_F
490509
fi
491510

492511
log "Step 1: Setting up e4s-cl. Using a local virtual environment and editable install to ensure the latest code is used."
512+
513+
# Verify Python has required features before creating venv
514+
if ! python3 -c "import ctypes" 2>/dev/null; then
515+
log "ERROR: Python installation at $(command -v python3) is missing the ctypes module"
516+
log "ERROR: This is typically caused by Python being compiled without libffi support"
517+
log "ERROR: "
518+
log "ERROR: To fix this issue:"
519+
log "ERROR: 1. If you loaded a Python module: module unload python"
520+
log "ERROR: 2. Use system Python (usually /usr/bin/python3)"
521+
log "ERROR: 3. Or load a different Python module that has ctypes support"
522+
log "ERROR: 4. Verify with: python3 -c 'import ctypes; print(\"OK\")'"
523+
fail "Python missing required ctypes module (needs libffi)"
524+
fi
525+
526+
PYTHON_VERSION=$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')
527+
if python3 -c "import sys; sys.exit(0 if sys.version_info >= (3, 7) else 1)"; then
528+
log "Python version check passed: ${PYTHON_VERSION}"
529+
else
530+
log "ERROR: Python ${PYTHON_VERSION} is too old (e4s-cl requires Python 3.7+)"
531+
log "ERROR: Current Python: $(command -v python3)"
532+
log "ERROR: "
533+
log "ERROR: To fix this issue:"
534+
log "ERROR: 1. Load a newer Python module: module load python/3.9 (or similar)"
535+
log "ERROR: 2. Or use a newer system Python if available"
536+
log "ERROR: 3. Ensure the Python has ctypes: python3 -c 'import ctypes'"
537+
fail "Python version ${PYTHON_VERSION} is too old (need 3.7+)"
538+
fi
539+
493540
if [[ ! -x "${REPO_ROOT}/.venv/bin/python" ]]; then
494541
python3 -m venv "${REPO_ROOT}/.venv"
495542
fi
@@ -502,10 +549,11 @@ E4S_CL_BIN="${REPO_ROOT}/.venv/bin/e4s-cl"
502549
if [[ "${NEEDS_TRANSLATION}" == "1" ]]; then
503550
log "Wi4MPI translation required; e4s-cl will install Wi4MPI during launch if missing"
504551
if [[ -n "${E4S_CL_WI4MPI_CFLAGS}" ]]; then
505-
log "CONFIG: injecting Wi4MPI build flags to ensure compatibility (e.g., GCC 14)"
506-
log "CONFIG: CFLAGS/CXXFLAGS=${E4S_CL_WI4MPI_CFLAGS}"
507-
export CFLAGS="${E4S_CL_WI4MPI_CFLAGS} ${CFLAGS:-}"
508-
export CXXFLAGS="${E4S_CL_WI4MPI_CFLAGS} ${CXXFLAGS:-}"
552+
log "CONFIG: Wi4MPI build flags set (for e4s-cl internal use): ${E4S_CL_WI4MPI_CFLAGS}"
553+
log "CONFIG: These flags will be used by e4s-cl when building Wi4MPI, not for OSU benchmarks"
554+
# Export as E4S_CL_WI4MPI_* variables that e4s-cl can use when building Wi4MPI
555+
export E4S_CL_WI4MPI_CFLAGS="${E4S_CL_WI4MPI_CFLAGS}"
556+
export E4S_CL_WI4MPI_CXXFLAGS="${E4S_CL_WI4MPI_CFLAGS}"
509557
fi
510558
fi
511559

@@ -609,8 +657,19 @@ if [[ "${REBUILD_HOST_OSU}" == "1" ]]; then
609657
rm -rf "${OSU_HOST_PREFIX}"
610658
mkdir -p "${OSU_HOST_PREFIX}"
611659
(
660+
# Clear CFLAGS/CXXFLAGS to avoid injecting incompatible compiler flags
661+
# (e.g., GCC-specific flags when using NVIDIA HPC or other compilers)
662+
unset CFLAGS
663+
unset CXXFLAGS
612664
cd "${OSU_SRC_DIR}"
613-
./configure CC="${HOST_MPICC}" --prefix="${OSU_HOST_PREFIX}"
665+
# Configure with both CC and CXX set to MPI wrappers to avoid linker issues
666+
if [[ -n "${HOST_MPICXX}" ]]; then
667+
./configure CC="${HOST_MPICC}" CXX="${HOST_MPICXX}" --prefix="${OSU_HOST_PREFIX}"
668+
else
669+
# If no MPI C++ wrapper found, unset CXX to prevent using raw compiler for linking
670+
unset CXX
671+
./configure CC="${HOST_MPICC}" --prefix="${OSU_HOST_PREFIX}"
672+
fi
614673
make -j
615674
make install
616675
)
@@ -689,6 +748,8 @@ if [[ "${REBUILD_CONT_OSU}" == "1" ]]; then
689748
mkdir -p "${OSU_CONT_PREFIX}"
690749
${CONTAINER_CMD} exec -B "${E4S_CL_WORKDIR}:/work" -B "${E4S_CL_CACHE_DIR}:/cache" "${E4S_CL_IMAGE}" bash -lc "\
691750
set -euo pipefail; \
751+
unset CFLAGS; \
752+
unset CXXFLAGS; \
692753
cd /work; \
693754
rm -rf osu-container-build && mkdir osu-container-build; \
694755
tar -xzf /cache/osu.tar.gz -C osu-container-build --strip-components=1; \

0 commit comments

Comments
 (0)