cloud_3_3/run.py
PawelDopierala 57ef9aa4eb add files
2024-11-26 16:53:02 +01:00

31 lines
1.1 KiB
Python

import subprocess
from concurrent.futures import ThreadPoolExecutor
MODULO = 999999937
# Funkcja do wywołania ./computeC
def run_computeC(a, b, sigma):
result = subprocess.run(["./computeC", str(a), str(b), str(sigma)],
capture_output=True, text=True)
if result.returncode != 0:
raise RuntimeError(f"Error running computeC: {result.stderr}")
return int(result.stdout.strip()) % MODULO
# Główna funkcja
def parallel_calculate_C_sigma(a_start, b_end, sigma, num_chunks):
chunk_size = (b_end - a_start + 1) // num_chunks
ranges = [(a_start + i * chunk_size, min(a_start + (i + 1) * chunk_size - 1, b_end))
for i in range(num_chunks)]
with ThreadPoolExecutor() as executor:
futures = [executor.submit(run_computeC, a, b, sigma) for a, b in ranges]
results = [f.result() for f in futures]
return sum(results) % MODULO
# Parametry
a_start, b_end, sigma = 1, 10000, 42
num_chunks = 32 # Liczba podziałów równoległych
result = parallel_calculate_C_sigma(a_start, b_end, sigma, num_chunks)
print(f"C_sigma({a_start}, {b_end}) = {result}")