You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
990 B
44 lines
990 B
7 months ago
|
import time
|
||
|
from mpi4py import MPI
|
||
|
import threading
|
||
|
|
||
|
|
||
|
def plan_delivery(message, recipient, tag, time=1):
|
||
|
thread = threading.Thread(target=deliver, args=(message, recipient, tag, time,))
|
||
|
thread.start()
|
||
|
|
||
|
|
||
|
def deliver(message, recipient, tag, sleep=1):
|
||
|
time.sleep(sleep)
|
||
|
conn.isend(message, recipient, tag)
|
||
|
|
||
|
|
||
|
conn = MPI.COMM_WORLD
|
||
|
|
||
|
rank = conn.Get_rank()
|
||
|
print(f"Is root : {rank == 0}")
|
||
|
|
||
|
size = conn.Get_size()
|
||
|
print(f"COMM_WORLD size is {size}")
|
||
|
|
||
|
if rank == 0:
|
||
|
plan_delivery("Houston, we have a Problem!", rank, 1)
|
||
|
|
||
|
message = conn.irecv(source=0, tag=1)
|
||
|
message = message.wait()
|
||
|
|
||
|
print(f"Message received: {message}")
|
||
|
|
||
|
# Bcast kann direkt in Variablen einschreiben
|
||
|
text = "Groundcontrol to Major Tom"
|
||
|
response = conn.bcast(text, 0)
|
||
|
print(f"Response received: {response}")
|
||
|
|
||
|
if rank == 0:
|
||
|
X = list(range(1, 5))
|
||
|
else:
|
||
|
X = None
|
||
|
|
||
|
# Gather schreibt in ein array, hier mit allen bei den clients registrierten X
|
||
|
gathered_data = conn.gather(X, root=0)
|
||
|
print(gathered_data)
|