Skip to content

Commit

Permalink
WIP: Refactor Windows DLL path handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dalcinl committed Oct 19, 2023
1 parent 6de1d61 commit 2078b72
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .cibw/merge-wheels.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ def wheel_tagline(tags: list[str]) -> str:
fh.write("# Register MPI ABI variants\n")
for variant in variant_registry:
fh.write(f"_mpiabi._register({variant!r})\n")
mpi_pth = root_dir / "mpi.pth"
if mpi_pth.exists():
fh.write("_mpiabi._bootstrap_windows()\n")
mpi_pth.unlink()

output_dir.mkdir(parents=True, exist_ok=True)
wheel_pack.pack(root_dir, output_dir, None)
Expand Down
38 changes: 38 additions & 0 deletions .cibw/mpi4py_mpiabi.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,41 @@ def find_spec(cls, fullname, path, target=None):
def _install_finder():
if _Finder not in sys.meta_path:
sys.meta_path.append(_Finder)


def _bootstrap_windows():
dllpath = []

def add(root, *subdir, dll=""):
path = os.path.join(root, *subdir)
dll = os.path.join(path, dll)
if os.path.exists(dll):
dllpath.append(path)

I_MPI_ROOT = os.environ.get("I_MPI_ROOT")
if I_MPI_ROOT:
library_kind = (
os.environ.get("I_MPI_LIBRARY_KIND") or
os.environ.get("library_kind") or
"release"
)
ofi_internal = os.environ.get("I_MPI_OFI_LIBRARY_INTERNAL")
if ofi_internal not in ("0", "no", "off", "disable"):
add(I_MPI_ROOT, "libfabric", "bin", dll="libfabric.dll")
add(I_MPI_ROOT, "bin", "libfabric", dll="libfabric.dll")
add(I_MPI_ROOT, "bin", library_kind, dll="impi.dll")
add(I_MPI_ROOT, "bin", dll="impi.dll")

MSMPI_BIN = os.environ.get("MSMPI_BIN")
if I_MPI_ROOT:
add(MSMPI_BIN, dll="msmpi.dll")

if hasattr(os, "add_dll_directory"):
for entry in dllpath:
os.add_dll_directory(entry)
else:
ospath = os.environ["PATH"].split(os.path.pathsep)
for entry in dllpath:
if entry not in ospath:
ospath.append(entry)
os.environ["PATH"] = os.path.pathsep.join(ospath)
18 changes: 9 additions & 9 deletions .github/workflows/cd-wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -334,16 +334,16 @@ jobs:
*NT*-impi_rt)
I_MPI_ROOT=$(cygpath -w "$CONDA_PREFIX/Library")
echo "I_MPI_ROOT=$I_MPI_ROOT" >> $GITHUB_ENV
echo "$I_MPI_ROOT\\bin" >> $GITHUB_PATH
echo "$I_MPI_ROOT\\bin\\libfabric" >> $GITHUB_PATH
#echo "$I_MPI_ROOT\\bin" >> $GITHUB_PATH
#echo "$I_MPI_ROOT\\bin\\libfabric" >> $GITHUB_PATH
;;
*NT*-msmpi)
MSMPI_ROOT=$(cygpath -w "$CONDA_PREFIX/Library")
echo "MSMPI_BIN=$MSMPI_ROOT\\bin" >> $GITHUB_ENV
echo "MSMPI_INC=$MSMPI_ROOT\\include" >> $GITHUB_ENV
echo "MSMPI_LIB64=$MSMPI_ROOT\\lib" >> $GITHUB_ENV
echo "$MSMPI_BIN" >> $GITHUB_PATH
;;
#echo "MSMPI_INC=$MSMPI_ROOT\\include" >> $GITHUB_ENV
#echo "MSMPI_LIB64=$MSMPI_ROOT\\lib" >> $GITHUB_ENV
#echo "$MSMPI_BIN" >> $GITHUB_PATH
#;;
esac
- run: python -m pip install mpi4py --no-index --find-links=dist
Expand Down Expand Up @@ -413,7 +413,7 @@ jobs:
mpiexec: ${{steps.user.outputs.mpiexec }}
env:
PYTHONUSERBASE: ${{ runner.temp }}/user
I_MPI_FABRICS: shm
#I_MPI_FABRICS: shm

- if: ${{ matrix.mpi == 'impi' }}
id: venv
Expand Down Expand Up @@ -442,8 +442,8 @@ jobs:
with:
python: ${{ steps.venv.outputs.python }}
mpiexec: ${{steps.venv.outputs.mpiexec }}
env:
I_MPI_FABRICS: shm
#env:
# I_MPI_FABRICS: shm

- uses: mpi4py/setup-mpi@v1
with:
Expand Down

0 comments on commit 2078b72

Please sign in to comment.