In [1]:
import numpy as np
In [2]:
import ipyparallel as ipp
c = ipp.Client(profile='mpi')
print(c.ids)
view = c[:]
view.activate()
Parallel eigenvalues:
import numpy as np
%time np.max(np.real(np.linalg.eigvals(np.random.randn(400,400))))
A task: find a biggest entry in a random matrix:
In [8]:
%time np.max(np.random.randn(5000,5000))
Out[8]:
In [3]:
%%px --block
from mpi4py import MPI
import time
import numpy as np
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()
t = MPI.Wtime()
print("result =",np.max(np.random.randn(5000,5000//4)))
t = MPI.Wtime() - t
print(rank,":: execution time:",t)
In [11]:
%%px --block
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
data = None
if rank == 0:
data = {'a': 7, 'b': 3.14}
comm.send(data, dest=1)
elif rank == 1:
data = comm.recv(source=0)
print("OK, rank= ",rank,"dane: ",data)
In [6]:
%%px --block
import numpy as np
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
a = np.zeros((2,2))
if rank == 0:
a[:] = 2
comm.send(a, dest=1)
elif rank == 1:
a = comm.recv(source=0)
print ("OK,",rank,np.sum(a))
In [6]:
%%px --block
import numpy as np
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
a = np.zeros((2,2))
if rank == 0:
a[:] = 2
comm.send(a[0,:], dest=1)
elif rank == 1:
a[0,:] = comm.recv(source=0)
print("OK,",rank,np.sum(a))
In [7]:
view['rank']
Out[7]:
In [11]:
view['a'][5]
Out[11]:
In [15]:
np.argsort(view['rank'])
Out[15]:
In [16]:
view['a'][np.argsort(view['rank'])[1]]
Out[16]:
In [9]:
print(view['a'][view['rank'][0]])
print(view['a'][view['rank'][1]])
In [10]:
%%px --block
import numpy as np
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
a = np.zeros((2,2))
if rank == 0:
a[:] = 2
comm.send(a[:,0], dest=1)
elif rank == 1:
a[:,0] = comm.recv(source=0)
print ("OK,",rank,np.sum(a))
In [11]:
print(view['a'][view['rank'][0]])
print(view['a'][view['rank'][1]])
In [12]:
%%px --block
import numpy as np
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
a = np.zeros((2,2))
if rank == 0:
a[:] = 2
comm.Send(a[0,:], dest=1)
elif rank == 1:
comm.Recv(a[0,:], source=0)
print ("OK,",rank,np.sum(a))
In [13]:
%%px --block
import numpy as np
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
a = np.zeros((2,2))
if rank == 0:
a[:] = 2
comm.Send(a[:,0], dest=1)
elif rank == 1:
comm.Recv(a[:,0], source=0)
print ("OK,",rank,np.sum(a))
In [14]:
a = np.zeros((2,2))
a.flags
Out[14]:
In [15]:
a[:,0].flags
Out[15]:
In [16]:
a[0,:].flags
Out[16]:
In [17]:
%%px --block
import numpy as np
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
a = np.zeros((2,2))
if rank == 0:
a[:] = 2
buf = a[:,0].copy()
comm.Send(buf, dest=1)
elif rank == 1:
buf = np.empty(2)
comm.Recv(buf, source=0)
a[:,0] = buf
print ("OK,",np.sum(a))
In [1]:
import ipyparallel as ipp
c = ipp.Client(profile='mpi')
print(c.ids)
view = c[:]
view.activate()
In [5]:
%%px --block --target :3
print("OK")
In [6]:
%%px --block
print("OK")
In [9]:
%%px --block
import numpy as np
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
a = np.zeros((2,2))
if rank == 0:
import os
print(os.getcwd())
In [ ]: