2012年1月20日金曜日

Python でお気楽並列コンピューティング:MYMPIの使い方




example1.py
import numpy
from numpy import *
import mpi
from mpi import *
import sys
sys.argv = mpi.mpi_init(len(sys.argv),sys.argv)
print "after ",len(sys.argv),sys.argv
myid=mpi.mpi_comm_rank(mpi.MPI_COMM_WORLD)
numprocs=mpi.mpi_comm_size(mpi.MPI_COMM_WORLD)
print "Hello from ",myid
print "Numprocs is ", numprocs
print "python is not about snakes"
mpi.mpi_finalize()

mpirun --hostfile hosts -np 40 python example1.py

hosts ファイルの書き方

hoge@192.168.1.11 cpu=4 
hoge@192.168.1.12 cpu=4 
hoge@192.168.1.15 cpu=4
hoge@192.168.1.16 cpu=4 
hoge@192.168.1.17 cpu=4 
hoge@192.168.1.19 cpu=4 
hoge@192.168.1.20 cpu=4 
hoge@192.168.1.23 cpu=8 
hoge@192.168.1.24 cpu=16

とすること

server1@~/test_mympi> mpirun -host hoge@192.168.1.14 -np 3 python example1.py
Traceback (most recent call last): File "example1.py", line 2, in import numpy ImportError: No module named numpy Traceback (most recent call last): Traceback (most recent call last): File "example1.py", line 2, in import numpy ImportError: No module named numpy File "example1.py", line 2, in import numpy ImportError: No module named numpy

となぜかnumpyを認識していないノードはhostsファイルから除く。
後日なぜかを調査予定。


うまくいくと、以下のようになる


server1@~/test_mympi> mpirun --hostfile hosts -np 10 python example1.py
[puzzle15:26782] mca: base: component_find: unable to open osc pt2pt: file not found (ignored)
[puzzle11:27440] mca: base: component_find: unable to open osc pt2pt: file not found (ignored)
[puzzle15:26783] mca: base: component_find: unable to open osc pt2pt: file not found (ignored)
[puzzle12:23530] mca: base: component_find: unable to open osc pt2pt: file not found (ignored)
[puzzle11:27439] mca: base: component_find: unable to open osc pt2pt: file not found (ignored)
[puzzle11:27441] mca: base: component_find: unable to open osc pt2pt: file not found (ignored)
[puzzle11:27442] mca: base: component_find: unable to open osc pt2pt: file not found (ignored)
[puzzle12:23529] mca: base: component_find: unable to open osc pt2pt: file not found (ignored)
[puzzle12:23531] mca: base: component_find: unable to open osc pt2pt: file not found (ignored)
[puzzle12:23532] mca: base: component_find: unable to open osc pt2pt: file not found (ignored)
after  1 ('example1.py',)
Hello from  6
Numprocs is  10
python is not about snakes
after  1 ('example1.py',)
Hello from  8
after  1 ('example1.py',)
Hello from  2
Numprocs is  10
python is not about snakes
after  1 ('example1.py',)
Hello from  0
Numprocs is  10
python is not about snakes
after  1 ('example1.py',)
Hello from  3
Numprocs is  10
python is not about snakes
Numprocs is  10
python is not about snakes
after  1 ('example1.py',)
Hello from  9
Numprocs is  10
python is not about snakes
after  1 ('example1.py',)
Hello from  4
Numprocs is  10
python is not about snakes
after  1 ('example1.py',)
Hello from  5
Numprocs is  10
python is not about snakes
after  1 ('example1.py',)
Hello from  7
Numprocs is  10
python is not about snakes
after  1 ('example1.py',)
Hello from  1
Numprocs is  10
python is not about snakes

このエントリーをはてなブックマークに追加



0 件のコメント :

コメントを投稿