Running MPI4Py Programs
To run MPI programs, the OpenMPI parallel environment and Python must be loaded with the command
module load openmpi python
The mpi4py library is also installed in the locally installed Python, which we check with the following program. Prepare the basic test program hello.py with any editor for the test
## -*- coding: utf-8 -*-
from mpi4py import MPI
comm = MPI.COMM_WORLD
print "Zdravo! Jaz sem proces %d od skupaj %d procesov" % (comm.rank, comm.size)
comm.Barrier() # Počakajmo vse, da pridejo do to, potem pa nadaljujemo
After installation, programs are run with the command
sbatch --partition=rome --ntasks=4 --ntasks-per-core=1 --output=error.log --wrap="mpirun python hello.py"
The result is read from the file error.log, which we read on the prelog control node. For interactive work on a single node or on half a node, the following commands can also be used
srun --partition=rome --nodes=1 --ntasks=48 --ntasks-per-core=1 python hello.py
srun --partition=rome --nodes=1 --ntasks=24 --ntasks-per-core=1 python hello.py
Poganjanje programov MPI4Py
Za poganjanje MPI programov je potrebno namestiti paralelno okolje OpenMPI in Python z ukazom
module load openmpi python
Knjižnica mpi4py je v lokalno nameščeni pyton tudi nameščena, kar preverimo z naslednjim programom. Osnovni testni program hello.py s poljubni urejevalnikom pripravimo za test
## -*- coding: utf-8 -*-
from mpi4py import MPI
comm = MPI.COMM_WORLD
print "Zdravo! Jaz sem proces %d od skupaj %d procesov" % (comm.rank, comm.size)
comm.Barrier() # Počakajmo vse, da pridejo do to, potem pa nadaljujemo
Po namestitvi poganjamo programe z ukazom
sbatch --partition=rome --ntasks=4 --ntasks-per-core=1 --output=error.log --wrap="mpirun python hello.py"
Rezultat si preberemo v datoteki error.log ki, jo beremo na nadzornem vozlišču prelog. Za interaktivno delo na enem samem vozlišču ali pa na polovici vozlišča pa lahko uporabimo tudi ukaza
srun --partition=rome --nodes=1 --ntasks=48 --ntasks-per-core=1 python hello.py
srun --partition=rome --nodes=1 --ntasks=24 --ntasks-per-core=1 python hello.py