more stuff
This commit is contained in:
11
uebung_03/exercise_02/exercise_02a.py
Normal file
11
uebung_03/exercise_02/exercise_02a.py
Normal 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}")
|
23
uebung_03/exercise_02/exercise_02b.py
Normal file
23
uebung_03/exercise_02/exercise_02b.py
Normal 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}")
|
Reference in New Issue
Block a user