import json
import socket
import threading
import time
from typing import List, Tuple
# ... imports locais ...
def worker(idx: int, host: str, port: int, A_chunk: Matrix):
"""Função executada por cada thread para comunicar com um servidor"""
payload = {"A_chunk": A_chunk, "B": B}
try:
# Envia dados e aguarda resposta
response = send_json_and_receive(host, port, payload)
resultados_parciais[idx] = response["C_chunk"]
except Exception as e:
print(f"Erro no servidor {idx}: {e}")
# Loop principal de distribuição
threads = []
for idx, ((host, port), subA) in enumerate(zip(SERVERS, submatrizes_A)):
t = threading.Thread(target=worker, args=(idx, host, port, subA))
t.start()
threads.append(t)
# Aguarda conclusão
for t in threads:
t.join()