cc_staff
153
edits
m (Adding some Python (mpi4py) material) |
m (More Python (mpi4py) examples) |
||
Line 257: | Line 257: | ||
|lang="python" | |lang="python" | ||
|contents= | |contents= | ||
from mpi4py import MPI | |||
print('Hello, world!') | |||
}} | }} | ||
</tab> | </tab> | ||
Line 692: | Line 692: | ||
end program phello2 | end program phello2 | ||
}} | }} | ||
</tab> | |||
<tab name="Python (mpi4py)"> | |||
{{File | |||
|name=phello2.py | |||
|lang="python" | |||
|contents= | |||
from mpi4py import MPI | |||
comm = MPI.COMM_WORLD | |||
rank = comm.Get_rank() | |||
size = comm.Get_size() | |||
outbuf = "Hello, world! from process %d of %d" % (rank, size) | |||
sendto = (rank + 1) % size; | |||
recvfrom = (rank + size - 1) % size; | |||
comm.send(outbuf, dest=sendto, tag=0) | |||
inbuf = comm.recv(source=recvfrom, tag=0) | |||
print('[P_%d] process %d said: "%s"]' % (rank, recvfrom, inbuf)) | |||
</tab> | </tab> | ||
</tabs> | </tabs> | ||
Line 956: | Line 977: | ||
end program phello3 | end program phello3 | ||
}} | |||
</tab> | |||
<tab name="Python (mpi4py)"> | |||
{{File | |||
|name=phello3.py | |||
|lang="python" | |||
|contents= | |||
from mpi4py import MPI | |||
comm = MPI.COMM_WORLD | |||
rank = comm.Get_rank() | |||
size = comm.Get_size() | |||
outbuf = "Hello, world! from process %d of %d" % (rank, size) | |||
sendto = (rank + 1) % size; | |||
recvfrom = ((rank + size) - 1) % size; | |||
if rank % 2 == 0: | |||
comm.send(outbuf, dest=sendto, tag=0) | |||
inbuf = comm.recv(source=recvfrom, tag=0) | |||
else: | |||
inbuf = comm.recv(source=recvfrom, tag=0) | |||
comm.send(outbuf, dest=sendto, tag=0) | |||
print('[P_%d] process %d said: "%s"]' % (rank, recvfrom, inbuf)) | |||
}} | }} | ||
</tab> | </tab> |