我是 Slurm 和 mpi4py 的新用户,所以我想测试我在这里找到的一些代码: https: //researchcomputing.princeton.edu/mpi4py
我的Python代码test.py
如下:
from mpi4py import MPI
import sys
def print_hello(rank, size, name):
msg = "Hello World! I am process {0} of {1} on {2}.\n"
sys.stdout.write(msg.format(rank, size, name))
if __name__ == "__main__":
size = MPI.COMM_WORLD.Get_size()
rank = MPI.COMM_WORLD.Get_rank()
name = MPI.Get_processor_name()
print_hello(rank, size, name)
我的 bash 脚本是:
#!/bin/bash
#SBATCH --job-name=mpi4py-test
#SBATCH --nodes=1
#SBATCH --ntasks=3
#SBATCH --cpus-per-task=1
srun python test.py
运行时sbatch run.sh我期望得到类似的东西:
Hello World! I am process 0 of 3 on node1.
Hello World! I am process 1 of 3 on node1.
Hello World! I am process 2 of 3 on node1.
但是我得到:
Hello World! I am process 0 of 1 on node1.
Hello World! I am process 0 of 1 on node1.
Hello World! I am process 0 of 1 on node1.
如果我改变的srun python test.py话srun mpiexec -n 3 python test.py我会得到:
Hello World! I am process 0 of 3 on node1.
Hello World! I am process 2 of 3 on node1.
Hello World! I am process 1 of 3 on node1.
Hello World! I am process 1 of 3 on node1.
Hello World! I am process 0 of 3 on node1.
Hello World! I am process 2 of 3 on node1.
Hello World! I am process 0 of 3 on node1.
Hello World! I am process 1 of 3 on node1.
Hello World! I am process 2 of 3 on node1.
该进程执行了 3 次,但我只想执行一次。提前致谢。
POPMUISE
相关分类