How can I force Matlab system command to use a different mpiexec than its own?

2 次查看(过去 30 天)
I have to run another program from Matlab, which however has a parallel environment and thus uses the mpiexec. However, even though I installed Microsoft Open MPI, when I check which mpiexec will be used when running my program with the Matlab system command I get this:
[~,cmd] = system('where mpiexec')
cmd =
C:\Program Files\MATLAB\R2016b\bin\win64\mpiexec.exe
C:\Program Files\Microsoft MPI\Bin\mpiexec.exe
which means Matlab prioritizes its own mpiexec over Microsoft's. However I get errors with the one from Matlab, so I need the other one. I see when I check the path variable with getenv('PATH') there is no Matlab in the path variable, however using
[~,cmd] = system('echo %PATH%')
cmd =
C:\Program Files\MATLAB\R2016b\bin\win64;C:\Program Files\Microsoft MPI\Bin\;.....
clearly shows that Matlab adds itself to the path once it is opening the shell... So how can I force Matlab system command to not add itself or at least to use the other mpiexec?
Thanks!
  1 个评论
Andrea Michelotti
Andrea Michelotti 2021-9-27
Hi,
I had the same issue and I tried many cmd lines trying to execute mpiexec in the right way.
At the end, I just copied mpiexec.exe from Microsoft MPI folder into my MATLAB one and it worked fine.

请先登录,再进行评论。

回答(1 个)

Marcel Beining
Marcel Beining 2017-10-27
Well, I found some workaround myself (searching for the mpi software on the path and temporarily putting it in front of Matlab, see below), but if there is a more elegant solution than this, please report it to me, thanks!
[~,pth] = system('echo %PATH%');
pth = strsplit(pth,';');
mpisoftw = cellfun(@(x) ~isempty(strfind(x,'mpi'))|~isempty(strfind(x,'MPI')),pth);
[~,cmd] = system(sprintf('set PATH=%s;%%PATH%%& where mpiexec',pth{find(mpisoftw,1,'first')}))
cmd =
C:\Program Files\Microsoft MPI\Bin\mpiexec.exe
C:\Program Files\MATLAB\R2016b\bin\win64\mpiexec.exe

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by