Skip to content
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

mpiexecjl should use a PowerShell on Windows. #545

Open
vchuravy opened this issue Mar 10, 2022 · 5 comments · May be fixed by #783
Open

mpiexecjl should use a PowerShell on Windows. #545

vchuravy opened this issue Mar 10, 2022 · 5 comments · May be fixed by #783
Milestone

Comments

@vchuravy
Copy link
Member

No description provided.

@vchuravy
Copy link
Member Author

@giordano do you have some time to look at this?

@vchuravy vchuravy added this to the 1.0 milestone Apr 15, 2022
@giordano
Copy link
Member

My problem is that I

  1. don't know much powershell
  2. don't have access to a Windows system for testing

🙂

@vchuravy
Copy link
Member Author

Ah yes I share those problems as well :)

@guilhermebodin
Copy link

I just realized that the mpiexecjl file written in my Windows was a bash script
image

Maybe it should give an error if someone tries to install it on Windows

@guilhermebodin
Copy link

guilhermebodin commented Aug 9, 2023

@simonbyrne @giordano
I wrote a MWE powershell example that works in my use case

# Copyright (C) 2023 Guilherme Bodin
# License is MIT "Expat"
#
# Commentary:
#
# Command line utility to call the `mpiexec` binary used by the `MPI.jl` version
# in the given Julia project. It has the same syntax as the `mpiexec` binary
# that would be called, with the additional `--project=...` flag to select a
# different Julia project.
#
# Examples of usage (the MPI flags available depend on the MPI implementation
# called):
#
#   $ mpiexecjl -n 40 julia mpi-script.jl
#   $ mpiexecjl --project=my_experiment -n 80 --oversubscribe julia mpi-script.jl

function usage {
    Write-Host "Usage: $([System.IO.Path]::GetFileNameWithoutExtension($MyInvocation.MyCommand.Name)) [--project=...] MPIEXEC_ARGUMENTS..."
    Write-Host "Call the mpiexec binary in the Julia environment specified by the --project option."
    Write-Host "If no project is specified, the MPI associated with the global Julia environment will be used."
    Write-Host "All other arguments are forwarded to mpiexec."
}

$julia_args = @()
$PROJECT_ARG = ""

$helpRequested = $false

foreach ($arg in $args) {
    if ($arg -match "^--project(=.*)?$") {
        $PROJECT_ARG = $arg
    }
    elseif ($arg -eq "-h" -or $arg -eq "--help") {
        $helpRequested = $true
        usage
        Write-Host "Below is the help of the current mpiexec."
        Write-Host
        $julia_args += $arg
    }
    else {
        $julia_args += $arg
    }
}

if (-not $args) {
    Write-Error "ERROR: no arguments specified."
    usage
    exit 1
}

if ($env:JULIA_BINDIR) {
    $JULIA_CMD = Join-Path $env:JULIA_BINDIR "julia"
} else {
    $JULIA_CMD = "julia"
}

$SCRIPT = @'
using MPI
ENV[\"JULIA_PROJECT\"] = dirname(Base.active_project())
mpiexec(exe -> run(`$exe $ARGS`))
'@

$PRECOMPILATION_SCRIPT = @'
println(\"precompiling current project before running MPI\")

import Pkg
Pkg.activate(dirname(Base.active_project()))
Pkg.instantiate()

println(\"precompilation finished\")
'@

& $JULIA_CMD $PROJECT_ARG -e $PRECOMPILATION_SCRIPT

if ($PROJECT_ARG) {
    & $JULIA_CMD $PROJECT_ARG --color=yes --startup-file=no --compile=min -O0 -e $SCRIPT -- $julia_args
} else {
    & $JULIA_CMD --color=yes --startup-file=no --compile=min -O0 -e $SCRIPT -- $julia_args
}

should I open a PR with this and edit the installation part to pick the correct script depending on the OS?

@guilhermebodin guilhermebodin linked a pull request Oct 16, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants