Home > Blockchain >  MPI on Windows: how to detect available library and processor count
MPI on Windows: how to detect available library and processor count

Time:10-07

I would like to automate detection of an MPI library under Windows 10/11 via a script. So far the only options would be MPICH2 or MS-MPI, so I'd like to:

  • Find an available installation (search for mpiexec.exe or spmd.exe)

For this, I'm currently running

# where mpiexec
C:\Program Files\Microsoft MPI\Bin\mpiexec.exe

and I can search for "Microsoft MPI" or "MPICH2" in the path string, but that's certainly not a general approach.

  • Detect the available number of CPUs on the local machine.

Is the following command general?

mpiexec -n *

Thanks of any help

CodePudding user response:

I can search for "Microsoft MPI" or "MPICH2" in the path string, but that's certainly not a general approach.

There is no general approach on Windows (as opposed on Linux and MacOS). Programs can be installed everywhere though they are generally in:

  • C:\Program Files
  • C:\Program Files (x86)
  • C:\Users\YOUR_USER\AppData\...

An alternative solution is to search for a MPI program in the PATH. This solution require to modify the PATH in the system properties. There are Linux related tools to search programs in it like locate. Such tools can be executed from Windows using a Linux-friendly console (eg. Git-Bash, Cmder, etc.). Batch shell script are very limited and clearly not user-friendly. Powershell may have some similar feature (though it requires a Powershell console).

This is a mess since tools like CMake (which barely supports MPI) spend a lot of effort and runtime to search for many frequent locations so to search libraries with no guarantee.


Detect the available number of CPUs on the local machine.

In Powershell, you can use the following code:

$processor = Get-ComputerInfo -Property CsProcessors
$CPU_COUNT = $processor.CsProcessors.NumberOfCores

assuming you want to extract the number of core, or otherwise:

$processor = Get-ComputerInfo -Property CsProcessors
$CPU_COUNT = $processor.CsProcessors.NumberOfLogicalProcessors

assuming you want to extract the number of logical cores (ie. hyper-threads).

Whether you should use one or the other is dependent of your target application and the target machine. I advise to use the number of core.

An alternative solution is to use the hw-loc tool also available on Linux and portable on many platforms. It is also a great tool to understand, profile and control the platform configuration (especially on NUMA systems).


Note that using MPI on Windows is very uncommon these days. A lot of high-performance tools/libraries supports mainly Linux (and not Windows) since 100% of the top 500 supercomputers (meant to run MPI programs) operate on Linux.

  • Related