Skip to content

ENH: Give Error message when no conda env is present #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion tests/pot3d/validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@ set -ex

POT3D_HOME=$PWD
TEST="validation"
MPIEXEC=${CONDA_PREFIX}/bin/mpiexec

cp ${POT3D_HOME}/testsuite/${TEST}/input/* ${POT3D_HOME}/testsuite/${TEST}/run/
cd ${POT3D_HOME}/testsuite/${TEST}/run

# Check if conda is active
if [[ -z "$CONDA_PREFIX" ]]; then
echo -e "${RED}Error: No Conda environment is active. Please activate a conda env with MPI installed.${NC}"
exit 1
fi
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the user has global installation of MPI implementation?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition might cause false negative.


# Try locating mpiexec
if [[ -x "${CONDA_PREFIX}/bin/mpiexec" ]]; then
MPIEXEC="${CONDA_PREFIX}/bin/mpiexec"
elif command -v mpiexec &> /dev/null; then
MPIEXEC=$(command -v mpiexec)
else
echo -e "${RED}Error: mpiexec not found. Please install MPI (OpenMPI or MPICH) via Conda or system package manager.${NC}"
exit 1
fi

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking for existence of ${CONDA_PREFIX}/bin/mpiexec doesn't detect MPI compilers, include paths, or libraries. We are only checking for runtime control here.

The correct approach probably will be to eventually use cmake build system for us. We've an open issue for this: #19

The current approach isn't the best one though.

Copy link
Collaborator

@gxyd gxyd May 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked pFUnit repository, the way they check the existence of MPI is using cmake's find_package using:

find_package (MPI QUIET COMPONENTS Fortran)

  if (MPI_Fortran_FOUND)
    message (STATUS "MPI enabled")
    if (ENABLE_MPI_F08)
      if (NOT MPI_Fortran_HAVE_F08_MODULE)
        message (FATAL_ERROR "MPI F08 module requested but not available")
      else()
        message (STATUS "MPI F08 module enabled")
      endif()
    endif()
  else ()
    message (STATUS "MPI not found; building without MPI")
  endif()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh YEs i Didn't see that CMAKE issue Thanks for mentioning it.
We can avoid this approach if not needed.

# detect MPI implementation
MPI_VERSION=$($MPIEXEC --version 2>&1)
if echo "$MPI_VERSION" | grep -q "Open MPI"; then
Expand Down
16 changes: 15 additions & 1 deletion tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,21 @@ while [[ $# -gt 0 ]]; do
esac
done

MPIEXEC=${CONDA_PREFIX}/bin/mpiexec
# Check if conda is active
if [[ -z "$CONDA_PREFIX" ]]; then
echo -e "${RED}Error: No Conda environment is active. Please activate a conda env with MPI installed.${NC}"
exit 1
fi

# Try locating mpiexec
if [[ -x "${CONDA_PREFIX}/bin/mpiexec" ]]; then
MPIEXEC="${CONDA_PREFIX}/bin/mpiexec"
elif command -v mpiexec &> /dev/null; then
MPIEXEC=$(command -v mpiexec)
else
echo -e "${RED}Error: mpiexec not found. Please install MPI (OpenMPI or MPICH) via Conda or system package manager.${NC}"
exit 1
fi

# detect MPI implementation
MPI_VERSION=$($MPIEXEC --version 2>&1)
Expand Down