add lec1,lec2,lec3,lec4

This commit is contained in:
2026-11-14 10:09:26 +03:00
commit a64a74f1d5
23 changed files with 398 additions and 0 deletions
+10
View File
@@ -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