In [13]:
%matplotlib inline
import matplotlib.pyplot as plt
In [14]:
import ipyparallel as ipp
import numpy as np
c = ipp.Client(profile='mpi')
print(c.ids)
view = c[:]
view.activate()
In [15]:
%%px --block
from mpi4py import MPI
import numpy as np
rank = MPI.COMM_WORLD.Get_rank()
No_processes = MPI.COMM_WORLD.Get_size()
nx = 28*No_processes
X_local = np.empty(nx//No_processes,dtype=np.float64)
if rank == 0:
X = np.linspace(0,10.0,nx)
else:
X = None
MPI.COMM_WORLD.Scatter(X, X_local)
f_local = np.sin(X_local)
In [16]:
X = view['X'][np.argsort(view['rank'])[0]]
In [ ]:
In [17]:
X_from_local = np.hstack([view['X_local'][i] for i in np.argsort(view['rank'])])
f_from_local = np.hstack([view['f_local'][i] for i in np.argsort(view['rank'])])
In [18]:
np.all( X_from_local == X)
Out[18]:
In [19]:
plt.plot(X_from_local,f_from_local)
Out[19]:
In [20]:
plt.clf()
for id,(x,f,rank) in enumerate(zip(view['X_local'],view['f_local'],view['rank'] )):
plt.plot(x,f)
plt.text( np.average(x),np.average(f),"%d (id:%d)"%(rank,id))
In [21]:
view['rank']
Out[21]:
In [7]:
%%px --block
from mpi4py import MPI
import numpy as np
rank = MPI.COMM_WORLD.Get_rank()
No_processes = MPI.COMM_WORLD.Get_size()
nx,ny = 16,3
X_local = np.empty((nx//No_processes,ny),dtype=np.int)
if rank == 0:
X = np.random.randint(60,size=(nx,ny))
else:
X = None
MPI.COMM_WORLD.Scatter(X, X_local)
In [24]:
np.argsort(view['rank'])
Out[24]:
In [8]:
X = view['X'][np.argsort(view['rank'])[0]]
X
Out[8]:
In [9]:
X_from_local = np.vstack([view['X_local'][i] for i in np.argsort(view['rank'])])
X_from_local
Out[9]:
In [10]:
np.all(X_from_local == X)
Out[10]:
In [11]:
In [40]:
%%px --block
from mpi4py import MPI
import numpy as np
rank = MPI.COMM_WORLD.Get_rank()
No_processes = MPI.COMM_WORLD.Get_size()
nx,ny = 3,16
X_local = np.empty((nx,ny//No_processes),dtype=np.int,order='F')
if rank == 0:
X = np.asfortranarray( np.random.randint(60,size=(nx,ny)) )
else:
X = None
MPI.COMM_WORLD.Scatter(X, X_local)
In [41]:
X = view['X'][np.argsort(view['rank'])[0]]
X
Out[41]:
In [42]:
view['X_local'][2]
Out[42]:
In [ ]:
In [45]:
X_from_local = np.hstack([view['X_local'][i] for i in np.argsort(view['rank'])])
X_from_local
Out[45]:
In [46]:
np.all(X_from_local == X)
Out[46]:
In [31]:
X_local = np.random.randint(55,size=(6,4))
X_local
Out[31]:
In [32]:
L_bulk = (1,slice(None))
L_ghost = (0,slice(None))
R_bulk = (-2, slice(None))
R_ghost = (-1, slice(None))
In [38]:
X_local[R_ghost]
Out[38]:
In [39]:
X_local[R_bulk]
Out[39]:
In [40]:
X_local[L_ghost]
Out[40]:
In [ ]: