提交 41dfa2c7 authored 作者: Matthew Rocklin's avatar Matthew Rocklin

more complex roundtrip example

上级 cb167f3b
...@@ -5,32 +5,34 @@ ...@@ -5,32 +5,34 @@
from mpi4py import MPI from mpi4py import MPI
comm = MPI.COMM_WORLD comm = MPI.COMM_WORLD
import theano import theano
from theano.tensor.io import send, recv from theano.tensor.io import send, recv, mpi_cmp
from theano.gof.graph import sort_schedule_fn
import numpy as np import numpy as np
from sys import stdout from sys import stdout
rank = comm.Get_rank() rank = comm.Get_rank()
size = comm.Get_size() size = comm.Get_size()
shape = (2, 2) shape = (2, 2)
dtype = 'float32' dtype = 'float32'
mode = theano.Mode(optimizer=None, linker='py') scheduler = sort_schedule_fn(mpi_cmp)
mode = theano.Mode(optimizer=None,
linker=theano.OpWiseCLinker(schedule=scheduler))
if rank == 0: if rank == 0:
x = theano.tensor.matrix('x', dtype=dtype) x = theano.tensor.matrix('x', dtype=dtype)
# y = x + x y = x + x
# send_request = send(y, 1, 11) send_request = send(y, 1, 11)
send_request = send(x, 1, 11) # send_request = send(x, 1, 11)
z = recv(shape, dtype, 1, 12) z = recv(shape, dtype, 1, 12)
f = theano.function([x], [send_request, z], mode=mode) f = theano.function([x], [send_request, z], mode=mode)
xx = np.random.rand(*shape).astype(dtype) xx = np.random.rand(*shape).astype(dtype)
# expected = (xx + 1) * 2 expected = (xx + 1) * 2
expected = xx * 2 # expected = xx * 2
_, zz = f(xx) _, zz = f(xx)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论