From 5c1a08daf65027b98e8810cb307203ef0ec6e558 Mon Sep 17 00:00:00 2001 From: kosipov Date: Sat, 17 Oct 2026 08:47:37 +0200 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20lec1/mc=5Fparallel.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lec1/mc_parallel.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 lec1/mc_parallel.py diff --git a/lec1/mc_parallel.py b/lec1/mc_parallel.py new file mode 100644 index 0000000..c7255fd --- /dev/null +++ b/lec1/mc_parallel.py @@ -0,0 +1,10 @@ +from concurrent.futures import ProcessPoolExecutor +from mc import count_hits +def estimate_pi_parallel(n_points, pool, n_workers): + """Делит работу на n_workers порций и считает их в пуле процессов.""" + chunk = n_points // n_workers + sizes = [chunk] * n_workers + sizes[-1] += n_points - chunk * n_workers # остаток — последней порции + seeds = range(1, n_workers + 1) # разные зёрна у порций + hits = sum(pool.map(count_hits, sizes, seeds)) + return 4 * hits / n_points