more stuff

This commit is contained in:
2023-11-23 16:02:33 +01:00
parent 4b90be609e
commit 25d77e62e0
5 changed files with 108 additions and 3 deletions

View File

@ -0,0 +1,11 @@
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
if rank == 0:
data = "Hello, from process 0!"
comm.send(data, dest=1)
elif rank == 1:
received_data = comm.recv(source=0)
print(f"Process 1 received: {received_data}")

View File

@ -0,0 +1,23 @@
from mpi4py import MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()
send_data = f"Hello, from process {rank}!"
print(f"I am rank {rank}. I send to process {(rank+1)}")
print(f"I am rank {rank}. I receive from process {(rank-1)}")
if rank == size-1:
comm.send(send_data, dest=(0))
else:
comm.send(send_data, dest=(rank + 1))
recv_data = ""
if rank == 0:
recv_data= comm.recv(source=(size - 1))
else:
recv_data= comm.recv(source=(rank - 1))
print(f"I am rank {rank}. I have received: {recv_data}")