之前遇到的问题在这儿mpi编程 comm.Get_rank()全为0而comm.Get_size()全为1应该怎么办?_wennyLee的博客-CSDN博客
后来,我尝试了在pycharm的terminal中运行程序
mpiexec -n 4 test.py
但是又出现了新的问题↓
然后为了解决”不是有效的 Win32 应用程序“这个问题,发现了解决方案:
需要将test.py文件打包为exe文件,然后再使用命令行来执行程序。
step1 安装pyinstaller包
好像python3.6是自带了的
step2 将.py文件打包为exe文件
1、通过cmd进入到.py文件所在的文件夹下
2、”pyinstaller -F test.py“ (此处以test.py文件为例)
3、然后会在当前文件夹下出现一个dist文件夹
step3 运行test.exe文件
1、进入到dist文件夹下,打开cmd。
2、输入”mpiexec -n 4 test.exe“即可。
总结:如果MPI完成了配置的话,估计就只是进程没法启动起来,那就换个思路,打包为exe后再运行代码吧。
example:
from mpi4py import MPI
comm = MPI.COMM_WORLD
print("Rank:", comm.Get_rank(), "Size:", comm.Get_size())
print("hello world from process ", comm.Get_rank(),"of", comm.Get_size())
输出:
在pycharm中(支持远程调试及运行)运行MPI的代码:
代码来源于:使用pycharm专业版(支持远程调试及运行)如何运行mpi的代码呢???(mpi4py的代码)_51CTO博客_pycharm运行调试配置
我的代码运行如下:
import os
python_path = "D:/conda3/python"
python_file = "D:/work/coded_matrix/Polynomial-Code-master/EC2-code/ISS_encode.py"
total_process = "-n {}".format(17)
command_str = 'mpiexec {0} {1} {2} '.format(total_process, python_path, python_file)
print(command_str)
os.system(command_str)
运行截图:
酱紫就不用每次从终端先打包,再运行啦~