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
Vendored
BIN
View File
Binary file not shown.
Executable
+12
View File
@@ -0,0 +1,12 @@
import statistics
import time
def bench(func, *args, repeats=5, warmup=1):
"""Запускает func(*args) несколько раз и возвращает медиану и разброс, с."""
for _ in range(warmup): # прогрев: кэши, JIT, запуск пула
func(*args)
times = []
for _ in range(repeats):
start = time.perf_counter() # монотонный таймер высокого разрешения
func(*args)
times.append(time.perf_counter() - start)
return statistics.median(times), min(times), max(times)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Executable
+12
View File
@@ -0,0 +1,12 @@
import statistics
import time
def bench(func, *args, repeats=5, warmup=1):
"""Запускает func(*args) несколько раз и возвращает медиану и разброс, с."""
for _ in range(warmup): # прогрев: кэши, JIT, запуск пула
func(*args)
times = []
for _ in range(repeats):
start = time.perf_counter() # монотонный таймер высокого разрешения
func(*args)
times.append(time.perf_counter() - start)
return statistics.median(times), min(times), max(times)
Executable
+12
View File
@@ -0,0 +1,12 @@
import random
def count_hits(n_points, seed):
"""Сколько случайных точек из квадрата [0,1]x[0,1] попало в четверть круга."""
rng = random.Random(seed) # свой генератор у каждой порции
hits = 0
for _ in range(n_points):
x, y = rng.random(), rng.random()
if x * x + y * y <= 1.0:
hits += 1
return hits
def estimate_pi_serial(n_points):
return 4 * count_hits(n_points, seed=0) / n_points
+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
+14
View File
@@ -0,0 +1,14 @@
from concurrent.futures import ProcessPoolExecutor
from bench import bench
from mc import estimate_pi_serial
from mc_parallel import estimate_pi_parallel
N = 20_000_000
if __name__ == "__main__":
t1, _, _ = bench(estimate_pi_serial, N)
print(f"Последовательно: T(1) = {t1:.2f} с")
print(" p T(p), с S(p) E(p)")
for p in [1, 2, 4, 6, 8, 10]:
with ProcessPoolExecutor(max_workers=p) as pool:
tp, _, _ = bench(estimate_pi_parallel, N, pool, p)
s = t1 / tp
print(f"{p:2d} {tp:8.2f} {s:5.2f} {s / p:5.2f}")
+13
View File
@@ -0,0 +1,13 @@
from concurrent.futures import ProcessPoolExecutor
from bench import bench
from mc_parallel import estimate_pi_parallel
N_PER_WORKER = 5_000_000 # объём работы на одного исполнителя
if __name__ == "__main__":
print(" p N T(p), с E_weak")
for p in [1, 2, 4, 6, 8, 10]:
n = N_PER_WORKER * p # задача растёт вместе с числом процессов
with ProcessPoolExecutor(max_workers=p) as pool:
tp, _, _ = bench(estimate_pi_parallel, n, pool, p)
if p == 1:
t_base = tp
print(f"{p:2d} {n:10_d} {tp:7.2f} {t_base / tp:6.2f}")
Executable
+100
View File
@@ -0,0 +1,100 @@
## Практический пример по лекции 3: от гонки к корректному эксперименту
**Задача:** показать потерю обновлений, исправить её блокировкой, затем сравнить одинаковую CPU-нагрузку на стандартной и free-threaded сборках. Готовые файлы находятся в `материалы/lec3/`.
**Шаг 1. Воспроизводим гонку.**
Файл `race_demo.py` запускает четыре потока, каждый делает 2000 увеличений. В небезопасной версии `time.sleep(0)` повышает вероятность чередования, чтобы дефект проявлялся чаще.
```bash
python3.14 материалы/lec3/race_demo.py
```
**Контрольный запуск** (CPython 3.12.15, macOS, ARM64; число в первой строке меняется от запуска к запуску):
```text
Без Lock: 2041 из 8000
С Lock: 8000 из 8000
```
Потерянные 5959 обновлений — не «погрешность», а нарушение инварианта. В другом запуске число будет другим, а вариант с `Lock` обязан всегда давать 8000.
**Шаг 2. Проверяем исправление как гипотезу.**
Недостаточно увидеть один правильный результат. Запустите тест несколько раз на обеих сборках. Для каждого запуска зафиксируйте ожидаемое и фактическое значение. Утверждение `assert safe == expected` в файле проверяет инвариант автоматически.
Сформулируйте устно, почему критическая секция включает и чтение, и запись. Если вынести `old = self.value` за `with self.lock`, гонка останется, хотя в коде по-прежнему будет блокировка.
**Шаг 3. Запускаем одинаковую нагрузку на разных сборках.**
Функция `busy_sum` в `gil_demo.py` содержит только вычисления на чистом Python. Последовательная и поточная версии выполняют одинаковый объём работы и возвращают одинаковую сумму.
```python
def busy_sum(n):
total = 0
for i in range(n):
total += i * i
return total
def threaded(pool, n, workers):
return sum(pool.map(busy_sum, [n] * workers))
```
Прогрев выполняется до включения таймера, а пул создаётся вне измеряемой функции:
```python
def measure(function, *args):
function(*args)
start = time.perf_counter()
result = function(*args)
return result, time.perf_counter() - start
```
Выполните два запуска из папки `лекции/`:
```bash
python3.14 материалы/lec3/gil_demo.py
python3.14t материалы/lec3/gil_demo.py
```
Сначала проверьте строку `Результаты совпали: True`, затем анализируйте время. На стандартной сборке потоки не должны дать устойчивого ускорения чистого Python-цикла. На free-threaded сборке ускорение возможно, но его величину нельзя предсказать без замера: она зависит от нагрузки, оборудования и накладных расходов интерпретатора.
**Шаг 4. Связываем корректность и производительность.**
Увеличьте число workers до 1, 2, 4 и 8. Для каждого варианта вычислите `S(p) = T(1) / T(p)` по методике лекции 1. Отдельно отметьте, не изменился ли результат. Если ускорение появилось при неверном результате, это не ускорение решения задачи.
> **Попробуйте сами:** замените `ThreadPoolExecutor` на `ProcessPoolExecutor`. Какие части программы придётся изменить из-за сериализации и запуска процессов? Не меняйте вычислительную функцию.
## Типичные ошибки (≈5 мин)
| Симптом | Причина | Как исправить |
|---|---|---|
| Счётчик иногда меньше ожидаемого | Составное обновление не защищено | Включить весь цикл «чтение — изменение — запись» в критическую секцию |
| Блокировка есть, а гонка осталась | Часть обращений происходит вне `with lock` | Защищать один инвариант одним согласованным протоколом |
| Потоки не ускоряют чистый Python-цикл | Активен GIL | Проверить `sys._is_gil_enabled()`; выбрать процессы, подинтерпретаторы или free-threaded сборку |
| На free-threaded сборке GIL неожиданно активен | Расширение без поддержки free threading включило его при импорте | Проверить предупреждения и совместимость пакетов |
| Пул процессов падает или запускается рекурсивно | Нет защиты `__main__` либо функция не сериализуется | Запуск поместить под проверку; функцию вынести на верхний уровень модуля |
| Программа зависла при завершении очереди | Не отправлены признаки остановки или пропущен `task_done()` | Исправить протокол завершения; вызывать `task_done()` в `finally` |
| Два потока периодически ждут друг друга | Блокировки захватываются в разном порядке | Ввести единый порядок захвата и проверить циклы ожидания |
| TSan «не видит» гонку в Python-файле | Инструмент анализирует C/C++, а не Python-байткод | Для Python использовать инварианты и стресс-тесты; TSan применять к native-части |
**Задание** (≈60 минут). Проведите мини-исследование корректности и масштабируемости.
1. Запустите `race_demo.py` пять раз на стандартной сборке и пять раз на free-threaded сборке. Запишите фактический и ожидаемый результаты каждого прогона.
2. Исправьте небезопасный вариант через `Lock`, повторите эксперимент и сформулируйте инвариант, который теперь проверяется.
3. Выполните `gil_demo.py` для 1, 2, 4 и 8 workers на обеих сборках. Используйте не менее пяти повторов и медиану, фиксируйте окружение.
4. Постройте таблицу `T(p)`, `S(p)` и отметьте результат проверки корректности. Отдельно укажите, не включил ли сторонний пакет GIL.
5. Сделайте вывод: какая модель подходит для этой нагрузки и какие ограничения эксперимента не позволяют распространить вывод на все Python-программы.
Генерировать обвязку замеров и графиков с помощью ИИ-ассистента можно. Приложите декларацию: что сгенерировано, какие проверки выполнены и что исправлено.
**Считается выполненным, если:**
- приведены версии обеих сборок, ОС, процессор и результат проверки активности GIL;
- есть журнал всех прогонов счётчика и автоматическая проверка инварианта;
- таблица производительности построена по медианам не менее пяти повторов;
- результаты параллельной версии совпадают с последовательной;
- вывод разделяет наблюдения, интерпретацию и ограничения эксперимента.
Binary file not shown.
Binary file not shown.
+41
View File
@@ -0,0 +1,41 @@
"""Одна CPU-нагрузка последовательно и в ThreadPoolExecutor."""
import sys
import time
from concurrent.futures import ThreadPoolExecutor
def busy_sum(n):
"""Чистый Python: нагрузка на CPU без ожидания ввода-вывода."""
total = 0
for i in range(n):
total += i * i
return total
def serial(n, workers):
return sum(busy_sum(n) for _ in range(workers))
def threaded(pool, n, workers):
return sum(pool.map(busy_sum, [n] * workers))
def measure(function, *args):
function(*args) # прогрев: запуск workers и прогрев кэшей
start = time.perf_counter()
result = function(*args)
return result, time.perf_counter() - start
if __name__ == "__main__":
n, workers = 500_000, 4
gil = getattr(sys, "_is_gil_enabled", lambda: True)()
expected, serial_time = measure(serial, n, workers)
with ThreadPoolExecutor(max_workers=workers) as pool:
actual, thread_time = measure(threaded, pool, n, workers)
print(f"GIL включён: {gil}")
print(f"Последовательно: {serial_time:.4f} с")
print(f"Потоки: {thread_time:.4f} с")
print(f"Результаты совпали: {actual == expected}")
assert actual == expected
+42
View File
@@ -0,0 +1,42 @@
"""Демонстрация состояния гонки и исправления через Lock."""
import threading
import time
class Counter:
def __init__(self):
self.value = 0
self.lock = threading.Lock()
def add_unsafe(self, repeats):
for _ in range(repeats):
old = self.value # чтение старого значения
time.sleep(0) # увеличиваем шанс переключения потоков
self.value = old + 1 # запись может затерять чужое обновление
def add_safe(self, repeats):
for _ in range(repeats):
with self.lock: # весь цикл «чтение — изменение — запись»
self.value += 1
def run(method, n_threads=4, repeats=2_000):
counter = Counter()
threads = [
threading.Thread(target=method, args=(counter, repeats))
for _ in range(n_threads)
]
for thread in threads:
thread.start()
for thread in threads:
thread.join()
return counter.value, n_threads * repeats
if __name__ == "__main__":
unsafe, expected = run(Counter.add_unsafe)
safe, _ = run(Counter.add_safe)
print(f"Без Lock: {unsafe} из {expected}")
print(f"С Lock: {safe} из {expected}")
assert safe == expected
+11
View File
@@ -0,0 +1,11 @@
title,authors,year,citations,abstract,result_id,publication_info,pdf_links,url,total_results,search_time
Bounded model checking of concurrent programs,"I Rabinovitz, O Grumberg",2005,164,… In this paper we consider a concurrent program to be a program with several threads that … When verifying concurrent programs it is important to detect race conditions and deadlocks. …,VeO3gFqXt0MJ,"I Rabinovitz, O Grumberg - International Conference on Computer Aided …, 2005 - Springer",['https://www.academia.edu/download/43202005/TRANSYT_A_Tool_for_the_Verification_of_A20160229-25351-14feb9w.pdf#page=96'],https://link.springer.com/chapter/10.1007/11513988_9,unknown,unknown
Race condition and concurrency safety of multithreaded object-oriented programming in Java,HY Chen,2002,14,"… Java will result in system deadlock, which violates the requirement of software safety. As a contribution, an approach for detecting system deadlock in Java multithreaded programs with “…",JEo7KjfKRPYJ,"HY Chen - IEEE International Conference on Systems, Man and …, 2002 - ieeexplore.ieee.org",[],https://ieeexplore.ieee.org/abstract/document/1175574/,unknown,unknown
Efficient data race and deadlock prevention in concurrent object-oriented programs,P Nienaltowski,2004,10,"… concurrent programs will be proposed. In particular, we will focus on data race and deadlock … freedom – ideally, we would like to prove that our programs are globally deadlock free. …",4Cz0Zn2Ns0QJ,"P Nienaltowski - … SIGPLAN conference on Object-oriented programming …, 2004 - dl.acm.org",['https://dl.acm.org/doi/pdf/10.1145/1028664.1028695'],https://dl.acm.org/doi/abs/10.1145/1028664.1028695,unknown,unknown
"Flashlight: A dynamic detector of shared state, race conditions, and locking models in concurrent Java programs",SC Hale,2006,2,… model checking to find race conditions and deadlocks. The tool has … race conditions and deadlocks. The second mode generates reports about possible race conditions and deadlocks …,5OZSUEyNiGAJ,SC Hale - 2006 - scholar.afit.edu,['https://scholar.afit.edu/context/etd/article/4463/viewcontent/AFIT_GCS_ENG_06_08_Hale_S.pdf'],https://scholar.afit.edu/context/etd/article/4463/viewcontent/AFIT_GCS_ENG_06_08_Hale_S.pdf,unknown,unknown
A Petri Net-Based Tool for Detecting Deadlocks and Race Conditions in Concurrent Programs,"AL Goel, N Mansouri",1990,0,… deadlock errors and cases of race conditions on shared variables. We feel that its use in analyzing concurrent programs … of these programs with respect to such errors and anomalies. …,5EyNp0E3j54J,"AL Goel, N Mansouri - 1990 - surface.syr.edu",['https://surface.syr.edu/cgi/viewcontent.cgi?article=1087&context=eecs_techreports'],https://surface.syr.edu/cgi/viewcontent.cgi?article=1087&context=eecs_techreports,unknown,unknown
Ownership types for safe programming: Preventing data races and deadlocks,"C Boyapati, R Lee, M Rinard",2002,768,… : This paper presents a new static type system to prevent deadlocks in Java programs. Our system allows programmers to partition all the locks into a fixed number of lock levels and …,p01hrUHuGoUJ,"C Boyapati, R Lee, M Rinard - … on Object-oriented programming, systems …, 2002 - dl.acm.org",['https://dl.acm.org/doi/pdf/10.1145/582419.582440'],https://dl.acm.org/doi/abs/10.1145/582419.582440,unknown,unknown
A structured design methodology for concurrent programming,"A Bijlsma, C Huizing, R Kuiper, HJM Passier…",2017,8,"… to so-called race conditions: the correctness of the program’s … a deadlock could arise and how to take appropriate measures to prevent them. However, as opposed to the race-condition …",0RkhMrQCQAIJ,"A Bijlsma, C Huizing, R Kuiper, HJM Passier… - Proceedings of the 6th …, 2017 - dl.acm.org",['https://dl.acm.org/doi/pdf/10.1145/3162087.3162088'],https://dl.acm.org/doi/abs/10.1145/3162087.3162088,unknown,unknown
Static deadlock detection for the SHIM concurrent language,"N Vasudevan, SA Edwards",2008,24,"… can deadlock. Because of SHIM’s semantics, if the model does not deadlock, the program is guaranteed not to deadlock, … is not true: a program may not deadlock when we report it does. …",Lm-p22n-jmoJ,"N Vasudevan, SA Edwards - 2008 6th ACM/IEEE International …, 2008 - ieeexplore.ieee.org",['https://academiccommons.columbia.edu/doi/10.7916/D84F211C/download'],https://ieeexplore.ieee.org/abstract/document/4547686/,unknown,unknown
The application of supervisory control to deadlock avoidance in concurrent software,"Y Wang, T Kelly, M Kudlur, S Mahlke…",2008,30,… that usually remain latent on uniprocessors are more likely to manifest under real concurrency. This paper considers deadlocks involving mutual exclusion locks in concurrent programs. …,pAsCdNwRjLYJ,"Y Wang, T Kelly, M Kudlur, S Mahlke… - 2008 9th International …, 2008 - ieeexplore.ieee.org",['https://www.researchgate.net/profile/Stephane-Lafortune-3/publication/4364938_The_application_of_supervisory_control_to_deadlock_avoidance_in_concurrent_software/links/5623c58b08ae70315b5db040/The-application-of-supervisory-control-to-deadlock-avoidance-in-concurrent-software.pdf'],https://ieeexplore.ieee.org/abstract/document/4605961/,unknown,unknown
Static analysis for concurrent programs with applications to data race detection,"V Kahlon, S Sankaranarayanan, A Gupta",2013,19,"… The verification of multi-threaded programs for common types of bugs such as race conditions, deadlocks, memory safety errors, as well as user-defined functional properties has been …",KzN6HKEtfqwJ,"V Kahlon, S Sankaranarayanan, A Gupta - … Software Tools for Technology …, 2013 - Springer",[],https://link.springer.com/article/10.1007/s10009-013-0274-1,unknown,unknown
1 title authors year citations abstract result_id publication_info pdf_links url total_results search_time
2 Bounded model checking of concurrent programs I Rabinovitz, O Grumberg 2005 164 … In this paper we consider a concurrent program to be a program with several threads that … When verifying concurrent programs it is important to detect race conditions and deadlocks. … VeO3gFqXt0MJ I Rabinovitz, O Grumberg - International Conference on Computer Aided …, 2005 - Springer ['https://www.academia.edu/download/43202005/TRANSYT_A_Tool_for_the_Verification_of_A20160229-25351-14feb9w.pdf#page=96'] https://link.springer.com/chapter/10.1007/11513988_9 unknown unknown
3 Race condition and concurrency safety of multithreaded object-oriented programming in Java HY Chen 2002 14 … Java will result in system deadlock, which violates the requirement of software safety. As a contribution, an approach for detecting system deadlock in Java multithreaded programs with “… JEo7KjfKRPYJ HY Chen - IEEE International Conference on Systems, Man and …, 2002 - ieeexplore.ieee.org [] https://ieeexplore.ieee.org/abstract/document/1175574/ unknown unknown
4 Efficient data race and deadlock prevention in concurrent object-oriented programs P Nienaltowski 2004 10 … concurrent programs will be proposed. In particular, we will focus on data race and deadlock … freedom – ideally, we would like to prove that our programs are globally deadlock free. … 4Cz0Zn2Ns0QJ P Nienaltowski - … SIGPLAN conference on Object-oriented programming …, 2004 - dl.acm.org ['https://dl.acm.org/doi/pdf/10.1145/1028664.1028695'] https://dl.acm.org/doi/abs/10.1145/1028664.1028695 unknown unknown
5 Flashlight: A dynamic detector of shared state, race conditions, and locking models in concurrent Java programs SC Hale 2006 2 … model checking to find race conditions and deadlocks. The tool has … race conditions and deadlocks. The second mode generates reports about possible race conditions and deadlocks … 5OZSUEyNiGAJ SC Hale - 2006 - scholar.afit.edu ['https://scholar.afit.edu/context/etd/article/4463/viewcontent/AFIT_GCS_ENG_06_08_Hale_S.pdf'] https://scholar.afit.edu/context/etd/article/4463/viewcontent/AFIT_GCS_ENG_06_08_Hale_S.pdf unknown unknown
6 A Petri Net-Based Tool for Detecting Deadlocks and Race Conditions in Concurrent Programs AL Goel, N Mansouri 1990 0 … deadlock errors and cases of race conditions on shared variables. We feel that its use in analyzing concurrent programs … of these programs with respect to such errors and anomalies. … 5EyNp0E3j54J AL Goel, N Mansouri - 1990 - surface.syr.edu ['https://surface.syr.edu/cgi/viewcontent.cgi?article=1087&context=eecs_techreports'] https://surface.syr.edu/cgi/viewcontent.cgi?article=1087&context=eecs_techreports unknown unknown
7 Ownership types for safe programming: Preventing data races and deadlocks C Boyapati, R Lee, M Rinard 2002 768 … : This paper presents a new static type system to prevent deadlocks in Java programs. Our system allows programmers to partition all the locks into a fixed number of lock levels and … p01hrUHuGoUJ C Boyapati, R Lee, M Rinard - … on Object-oriented programming, systems …, 2002 - dl.acm.org ['https://dl.acm.org/doi/pdf/10.1145/582419.582440'] https://dl.acm.org/doi/abs/10.1145/582419.582440 unknown unknown
8 A structured design methodology for concurrent programming A Bijlsma, C Huizing, R Kuiper, HJM Passier… 2017 8 … to so-called race conditions: the correctness of the program’s … a deadlock could arise and how to take appropriate measures to prevent them. However, as opposed to the race-condition … 0RkhMrQCQAIJ A Bijlsma, C Huizing, R Kuiper, HJM Passier… - Proceedings of the 6th …, 2017 - dl.acm.org ['https://dl.acm.org/doi/pdf/10.1145/3162087.3162088'] https://dl.acm.org/doi/abs/10.1145/3162087.3162088 unknown unknown
9 Static deadlock detection for the SHIM concurrent language N Vasudevan, SA Edwards 2008 24 … can deadlock. Because of SHIM’s semantics, if the model does not deadlock, the program is guaranteed not to deadlock, … is not true: a program may not deadlock when we report it does. … Lm-p22n-jmoJ N Vasudevan, SA Edwards - 2008 6th ACM/IEEE International …, 2008 - ieeexplore.ieee.org ['https://academiccommons.columbia.edu/doi/10.7916/D84F211C/download'] https://ieeexplore.ieee.org/abstract/document/4547686/ unknown unknown
10 The application of supervisory control to deadlock avoidance in concurrent software Y Wang, T Kelly, M Kudlur, S Mahlke… 2008 30 … that usually remain latent on uniprocessors are more likely to manifest under real concurrency. This paper considers deadlocks involving mutual exclusion locks in concurrent programs. … pAsCdNwRjLYJ Y Wang, T Kelly, M Kudlur, S Mahlke… - 2008 9th International …, 2008 - ieeexplore.ieee.org ['https://www.researchgate.net/profile/Stephane-Lafortune-3/publication/4364938_The_application_of_supervisory_control_to_deadlock_avoidance_in_concurrent_software/links/5623c58b08ae70315b5db040/The-application-of-supervisory-control-to-deadlock-avoidance-in-concurrent-software.pdf'] https://ieeexplore.ieee.org/abstract/document/4605961/ unknown unknown
11 Static analysis for concurrent programs with applications to data race detection V Kahlon, S Sankaranarayanan, A Gupta 2013 19 … The verification of multi-threaded programs for common types of bugs such as race conditions, deadlocks, memory safety errors, as well as user-defined functional properties has been … KzN6HKEtfqwJ V Kahlon, S Sankaranarayanan, A Gupta - … Software Tools for Technology …, 2013 - Springer [] https://link.springer.com/article/10.1007/s10009-013-0274-1 unknown unknown
+11
View File
@@ -0,0 +1,11 @@
title,authors,year,citations,abstract,result_id,publication_info,pdf_links,url,total_results,search_time
Concurrency is hard: Java vs Python pitfalls you can't ignore,M Kommuru,2022,18,"… languages support concurrent … concurrency API, and Python through its simpler syntax which however comes with a very serious limitation in the form of the GIL (Global Interpreter Lock). …",Db6t3we__EkJ,"M Kommuru - … of Modern Research in Science & …, 2022 - worldcometresearchgroup.com",['https://worldcometresearchgroup.com/index.php/ijmrse/article/download/967/942'],https://worldcometresearchgroup.com/index.php/ijmrse/article/view/967,unknown,unknown
Python concurrency for high-load multicore processing,"A Zholdybay, A Askar",2025,2,… This article evaluates Python's concurrency methods for … Benchmarks showed that Python's Global Interpreter Lock (GIL) prevents … on choosing optimal concurrency strategies in Python. …,Ff2ifsFQ9k4J,"A Zholdybay, A Askar - Universum: технические науки, 2025 - cyberleninka.ru",[],https://cyberleninka.ru/article/n/python-concurrency-for-high-load-multicore-processing,unknown,unknown
"Reflections on the compatibility, performance, and scalability of parallel Python","R Meier, TR Gross",2019,28,"… vm) for Python. Instead, the predominant Python vms depend on a global interpreter lock, which … In a parallel vm, replicating Python’s concurrency semantics is challenging. Today, there …",7g0omS6ouoMJ,"R Meier, TR Gross - Proceedings of the 15th ACM SIGPLAN international …, 2019 - dl.acm.org",['https://dl.acm.org/doi/pdf/10.1145/3359619.3359747'],https://dl.acm.org/doi/abs/10.1145/3359619.3359747,unknown,unknown
Free-Threaded Python Interpreter Productivity Benefits Research for Data Science Domain,M Brodiuk,2026,0,… CPython’s Global Interpreter Lock is one of those design … Python concurrency research falls into three recognizable streams: proposals to remove or bypass the GIL at the interpreter …,H881ZnkZioIJ,M Brodiuk - 2026 - er.ucu.edu.ua,['https://er.ucu.edu.ua/bitstreams/c985eb0a-e0c4-4edc-b705-676b021ad2f0/download'],https://er.ucu.edu.ua/items/f75ff724-839b-4c8d-bb7a-b16780f9463b,unknown,unknown
FastFlow-Python: Parallel Building Blocks in Python Through FastFlow Integration,"M Della Bartola, J Massa, P Dazzi…",2025,0,"… to the Global Interpreter Lock (GIL) and the absence of structured concurrency abstractions. … arising from the Global Interpreter Lock (GIL), we opted for a pure Python implementation of …",X2a_FGy7-h4J,"M Della Bartola, J Massa, P Dazzi… - 2025 IEEE International …, 2025 - ieeexplore.ieee.org",[],https://ieeexplore.ieee.org/abstract/document/11196545/,unknown,unknown
Learning Concurrency in Python,E Forbes,2017,6,"… CPython threads are hamstrung by the limitations of the global interpreter lock (GIL), about which we'll go into more depth in the next chapter. While communication between threads …",Raj688bMq_EJ,E Forbes - 2017 - books.google.com,[],https://books.google.com/books?hl=en&lr=&id=hJZGDwAAQBAJ&oi=fnd&pg=PP1&dq=Python+global+interpreter+lock+concurrency&ots=DugwhvaQS4&sig=QSVqDIhYLtsyaGvAx8gjJIIrvic,unknown,unknown
Litmus Testing CPython Without the Global Interpreter Lock,A Siddiqui,2025,0,"… In Chapter 4, we survey the Python programming language’s support for concurrency, as well as the mechanisms CPython uses to facilitate concurrency in Python programs. We …",Rrxjkhi-eeUJ,A Siddiqui - 2025 - search.proquest.com,['https://indigo.uic.edu/articles/thesis/Litmus_Testing_CPython_Without_the_Global_Interpreter_Lock/29338727/1/files/55442684.pdf'],https://search.proquest.com/openview/ef0fc97470696af5bd33fa9c5eca9c25/1?pq-origsite=gscholar&cbl=18750&diss=y,unknown,unknown
Parallel virtual machines with RPython,"R Meier, A Rigo, TR Gross",2016,10,"… on a Global Interpreter Lock (GIL): PyPy serialises the execution of multi-threaded Python programs. … For Python, which supports concurrent threads, we thus need a way to implement its …",zQydFt84vFYJ,"R Meier, A Rigo, TR Gross - Proceedings of the 12th Symposium on …, 2016 - dl.acm.org",['https://dl.acm.org/doi/pdf/10.1145/2989225.2989233'],https://dl.acm.org/doi/abs/10.1145/2989225.2989233,unknown,unknown
Performance Comparison of Bagging Classifiers Between Multi-Core And Single-Core Processors Using Python Multiprocessing,"A Rawat, C Krishna, D Kumar",2024,2,"… Python, as a language, faces parallelism limitations due to the Global Interpreter Lock (GIL) … Consequently, relying solely on regular threads for concurrency would not fully harness the …",ktYc8LDvV_sJ,"A Rawat, C Krishna, D Kumar - 2024 2nd International …, 2024 - ieeexplore.ieee.org",[],https://ieeexplore.ieee.org/abstract/document/10867840/,unknown,unknown
CONCURDEP: Event-Guided Analysis of Dependency Invalidation in CPython Concurrency,"B Chen, H Westover, W Li",2026,0,"… Python Enhancement Proposal (PEP) 703 introduced a build with an optional Global Interpreter Lock (GIL), allowing Python … deferred reclamation, per-object locking, and critical-section …",c2J6pPFEhJEJ,"B Chen, H Westover, W Li - arXiv preprint arXiv:2609.28608, 2026 - arxiv.org",['https://arxiv.org/pdf/2609.28608'],https://arxiv.org/abs/2609.28608,unknown,unknown
1 title authors year citations abstract result_id publication_info pdf_links url total_results search_time
2 Concurrency is hard: Java vs Python pitfalls you can't ignore M Kommuru 2022 18 … languages support concurrent … concurrency API, and Python through its simpler syntax which however comes with a very serious limitation in the form of the GIL (Global Interpreter Lock). … Db6t3we__EkJ M Kommuru - … of Modern Research in Science & …, 2022 - worldcometresearchgroup.com ['https://worldcometresearchgroup.com/index.php/ijmrse/article/download/967/942'] https://worldcometresearchgroup.com/index.php/ijmrse/article/view/967 unknown unknown
3 Python concurrency for high-load multicore processing A Zholdybay, A Askar 2025 2 … This article evaluates Python's concurrency methods for … Benchmarks showed that Python's Global Interpreter Lock (GIL) prevents … on choosing optimal concurrency strategies in Python. … Ff2ifsFQ9k4J A Zholdybay, A Askar - Universum: технические науки, 2025 - cyberleninka.ru [] https://cyberleninka.ru/article/n/python-concurrency-for-high-load-multicore-processing unknown unknown
4 Reflections on the compatibility, performance, and scalability of parallel Python R Meier, TR Gross 2019 28 … vm) for Python. Instead, the predominant Python vms depend on a global interpreter lock, which … In a parallel vm, replicating Python’s concurrency semantics is challenging. Today, there … 7g0omS6ouoMJ R Meier, TR Gross - Proceedings of the 15th ACM SIGPLAN international …, 2019 - dl.acm.org ['https://dl.acm.org/doi/pdf/10.1145/3359619.3359747'] https://dl.acm.org/doi/abs/10.1145/3359619.3359747 unknown unknown
5 Free-Threaded Python Interpreter Productivity Benefits Research for Data Science Domain M Brodiuk 2026 0 … CPython’s Global Interpreter Lock is one of those design … Python concurrency research falls into three recognizable streams: proposals to remove or bypass the GIL at the interpreter … H881ZnkZioIJ M Brodiuk - 2026 - er.ucu.edu.ua ['https://er.ucu.edu.ua/bitstreams/c985eb0a-e0c4-4edc-b705-676b021ad2f0/download'] https://er.ucu.edu.ua/items/f75ff724-839b-4c8d-bb7a-b16780f9463b unknown unknown
6 FastFlow-Python: Parallel Building Blocks in Python Through FastFlow Integration M Della Bartola, J Massa, P Dazzi… 2025 0 … to the Global Interpreter Lock (GIL) and the absence of structured concurrency abstractions. … arising from the Global Interpreter Lock (GIL), we opted for a pure Python implementation of … X2a_FGy7-h4J M Della Bartola, J Massa, P Dazzi… - 2025 IEEE International …, 2025 - ieeexplore.ieee.org [] https://ieeexplore.ieee.org/abstract/document/11196545/ unknown unknown
7 Learning Concurrency in Python E Forbes 2017 6 … CPython threads are hamstrung by the limitations of the global interpreter lock (GIL), about which we'll go into more depth in the next chapter. While communication between threads … Raj688bMq_EJ E Forbes - 2017 - books.google.com [] https://books.google.com/books?hl=en&lr=&id=hJZGDwAAQBAJ&oi=fnd&pg=PP1&dq=Python+global+interpreter+lock+concurrency&ots=DugwhvaQS4&sig=QSVqDIhYLtsyaGvAx8gjJIIrvic unknown unknown
8 Litmus Testing CPython Without the Global Interpreter Lock A Siddiqui 2025 0 … In Chapter 4, we survey the Python programming language’s support for concurrency, as well as the mechanisms CPython uses to facilitate concurrency in Python programs. We … Rrxjkhi-eeUJ A Siddiqui - 2025 - search.proquest.com ['https://indigo.uic.edu/articles/thesis/Litmus_Testing_CPython_Without_the_Global_Interpreter_Lock/29338727/1/files/55442684.pdf'] https://search.proquest.com/openview/ef0fc97470696af5bd33fa9c5eca9c25/1?pq-origsite=gscholar&cbl=18750&diss=y unknown unknown
9 Parallel virtual machines with RPython R Meier, A Rigo, TR Gross 2016 10 … on a Global Interpreter Lock (GIL): PyPy serialises the execution of multi-threaded Python programs. … For Python, which supports concurrent threads, we thus need a way to implement its … zQydFt84vFYJ R Meier, A Rigo, TR Gross - Proceedings of the 12th Symposium on …, 2016 - dl.acm.org ['https://dl.acm.org/doi/pdf/10.1145/2989225.2989233'] https://dl.acm.org/doi/abs/10.1145/2989225.2989233 unknown unknown
10 Performance Comparison of Bagging Classifiers Between Multi-Core And Single-Core Processors Using Python Multiprocessing A Rawat, C Krishna, D Kumar 2024 2 … Python, as a language, faces parallelism limitations due to the Global Interpreter Lock (GIL) … Consequently, relying solely on regular threads for concurrency would not fully harness the … ktYc8LDvV_sJ A Rawat, C Krishna, D Kumar - 2024 2nd International …, 2024 - ieeexplore.ieee.org [] https://ieeexplore.ieee.org/abstract/document/10867840/ unknown unknown
11 CONCURDEP: Event-Guided Analysis of Dependency Invalidation in CPython Concurrency B Chen, H Westover, W Li 2026 0 … Python Enhancement Proposal (PEP) 703 introduced a build with an optional Global Interpreter Lock (GIL), allowing Python … deferred reclamation, per-object locking, and critical-section … c2J6pPFEhJEJ B Chen, H Westover, W Li - arXiv preprint arXiv:2609.28608, 2026 - arxiv.org ['https://arxiv.org/pdf/2609.28608'] https://arxiv.org/abs/2609.28608 unknown unknown
+6
View File
@@ -0,0 +1,6 @@
title,authors,year,citations,abstract,result_id,publication_info,pdf_links,url,total_results,search_time
Can large language models write parallel code?,"D Nichols, JH Davis, Z Xie, A Rajaram…",2024,113,"… of LLMs in generating parallel code, we propose the Parallel Code Generation Evaluation (ParEval) benchmark: … • We design the ParEval benchmark for evaluating the ability of LLMs to …",cyFMaN6u2s8J,"D Nichols, JH Davis, Z Xie, A Rajaram… - … -Performance Parallel …, 2024 - dl.acm.org",['https://dl.acm.org/doi/pdf/10.1145/3625549.3658689'],https://dl.acm.org/doi/abs/10.1145/3625549.3658689,unknown,unknown
Hpc-coder-v2: Studying code llms across low-resource parallel languages,"A Chaturvedi, D Nichols, S Singh…",2025,23,"… generation benchmark. We find that our fine-tuned model, HPC-Coder-v2, is the best performing opensource code LLM for parallel code generation and … models against the ParEval [2] …",kNk9g9iW5uEJ,"A Chaturvedi, D Nichols, S Singh… - ISC High Performance …, 2025 - ieeexplore.ieee.org",['https://ieeexplore.ieee.org/iel8/11008903/11008904/11017585.pdf'],https://ieeexplore.ieee.org/abstract/document/11017585/,unknown,unknown
Evaluating LLM Generated Task Codes,"S Yasna, SG De Gonzalo…",2026,0,"… [6], primarily examine the ability of LLMs to generate code in MPI, OpenMP, and other well-established parallel programming models. We extend the ParEval framework by adding a …",BEgH4fGrHdAJ,"S Yasna, SG De Gonzalo… - … Distributed Processing …, 2026 - ieeexplore.ieee.org",['https://mprobson.github.io/files/ParEval_AMT_HIPS_2026.pdf'],https://ieeexplore.ieee.org/abstract/document/11651914/,unknown,unknown
ParCoder: Harnessing Transformer Models for Parallel Code Generation with OpenMP and MPI,"L Chen, A Arijit, N Ahmed, N Hasabnis…",2026,0,"… , their efficacy in generating parallel code remains suboptimal, … LLM designed for parallel code generation, supporting both … and ParEval, to assess the effectiveness of the generated …",BNyA-Ut1O4gJ,"L Chen, A Arijit, N Ahmed, N Hasabnis… - … Processing …, 2026 - ieeexplore.ieee.org",['https://swapp.cs.iastate.edu/files/inline-files/ParCoder_Harnessing_Transformer_Models_for_Parallel_Code_Generation_with_OpenMP_and_MPI.pdf'],https://ieeexplore.ieee.org/abstract/document/11651888/,unknown,unknown
Paracoder: Parallel code generation with large language model,"X Huang, X Zhang, L Tao, R Mao, N Zhou…",2025,3,"… on 60 questions from the ParEval dataset [17], … generate OpenMP parallel code (parallel) improves the quality of the generated code compared to not enforcing parallel code generation (…",CWHkFx-PO98J,"X Huang, X Zhang, L Tao, R Mao, N Zhou… - … FastCode Programming …, 2025 - dl.acm.org",['https://dl.acm.org/doi/pdf/10.1145/3711708.3723442'],https://dl.acm.org/doi/abs/10.1145/3711708.3723442,unknown,unknown
1 title authors year citations abstract result_id publication_info pdf_links url total_results search_time
2 Can large language models write parallel code? D Nichols, JH Davis, Z Xie, A Rajaram… 2024 113 … of LLMs in generating parallel code, we propose the Parallel Code Generation Evaluation (ParEval) benchmark: … • We design the ParEval benchmark for evaluating the ability of LLMs to … cyFMaN6u2s8J D Nichols, JH Davis, Z Xie, A Rajaram… - … -Performance Parallel …, 2024 - dl.acm.org ['https://dl.acm.org/doi/pdf/10.1145/3625549.3658689'] https://dl.acm.org/doi/abs/10.1145/3625549.3658689 unknown unknown
3 Hpc-coder-v2: Studying code llms across low-resource parallel languages A Chaturvedi, D Nichols, S Singh… 2025 23 … generation benchmark. We find that our fine-tuned model, HPC-Coder-v2, is the best performing opensource code LLM for parallel code generation and … models against the ParEval [2] … kNk9g9iW5uEJ A Chaturvedi, D Nichols, S Singh… - ISC High Performance …, 2025 - ieeexplore.ieee.org ['https://ieeexplore.ieee.org/iel8/11008903/11008904/11017585.pdf'] https://ieeexplore.ieee.org/abstract/document/11017585/ unknown unknown
4 Evaluating LLM Generated Task Codes S Yasna, SG De Gonzalo… 2026 0 … [6], primarily examine the ability of LLMs to generate code in MPI, OpenMP, and other well-established parallel programming models. We extend the ParEval framework by adding a … BEgH4fGrHdAJ S Yasna, SG De Gonzalo… - … Distributed Processing …, 2026 - ieeexplore.ieee.org ['https://mprobson.github.io/files/ParEval_AMT_HIPS_2026.pdf'] https://ieeexplore.ieee.org/abstract/document/11651914/ unknown unknown
5 ParCoder: Harnessing Transformer Models for Parallel Code Generation with OpenMP and MPI L Chen, A Arijit, N Ahmed, N Hasabnis… 2026 0 … , their efficacy in generating parallel code remains suboptimal, … LLM designed for parallel code generation, supporting both … and ParEval, to assess the effectiveness of the generated … BNyA-Ut1O4gJ L Chen, A Arijit, N Ahmed, N Hasabnis… - … Processing …, 2026 - ieeexplore.ieee.org ['https://swapp.cs.iastate.edu/files/inline-files/ParCoder_Harnessing_Transformer_Models_for_Parallel_Code_Generation_with_OpenMP_and_MPI.pdf'] https://ieeexplore.ieee.org/abstract/document/11651888/ unknown unknown
6 Paracoder: Parallel code generation with large language model X Huang, X Zhang, L Tao, R Mao, N Zhou… 2025 3 … on 60 questions from the ParEval dataset [17], … generate OpenMP parallel code (parallel) improves the quality of the generated code compared to not enforcing parallel code generation (… CWHkFx-PO98J X Huang, X Zhang, L Tao, R Mao, N Zhou… - … FastCode Programming …, 2025 - dl.acm.org ['https://dl.acm.org/doi/pdf/10.1145/3711708.3723442'] https://dl.acm.org/doi/abs/10.1145/3711708.3723442 unknown unknown
Binary file not shown.
+114
View File
@@ -0,0 +1,114 @@
"""Практический пример к лекции 4: map/reduce и стенсил в Numba.
Запуск из папки «лекции»:
NUMBA_NUM_THREADS=1 python материалы/lec4/data_parallel_demo.py
NUMBA_NUM_THREADS=4 python материалы/lec4/data_parallel_demo.py
Переменную NUMBA_NUM_THREADS задавайте до импорта Numba.
"""
import os
import statistics
import sys
import time
import numpy as np
from numba import njit, prange
@njit
def step_serial(u):
"""Один шаг пятиточечного стенсила, последовательная версия."""
n, m = u.shape
v = u.copy()
for i in range(1, n - 1):
for j in range(1, m - 1):
v[i, j] = 0.25 * (
u[i - 1, j] + u[i + 1, j]
+ u[i, j - 1] + u[i, j + 1]
)
return v
@njit(parallel=True)
def step_parallel(u):
"""Тот же шаг: независимые строки распределяются между потоками."""
n, m = u.shape
v = u.copy()
for i in prange(1, n - 1):
for j in range(1, m - 1):
v[i, j] = 0.25 * (
u[i - 1, j] + u[i + 1, j]
+ u[i, j - 1] + u[i, j + 1]
)
return v
@njit
def sum_serial(a):
"""Последовательный эталон для редукции."""
total = 0.0
for i in range(a.size):
total += a[i]
return total
@njit(parallel=True)
def sum_parallel(a):
"""Скалярная редукция, распознаваемая Numba."""
total = 0.0
for i in prange(a.size):
total += a[i]
return total
def measure(function, *args, repeats=5):
"""Прогрев, затем медиана и размах пяти измерений."""
result = function(*args)
times = []
for _ in range(repeats):
start = time.perf_counter()
result = function(*args)
times.append(time.perf_counter() - start)
return result, statistics.median(times), min(times), max(times)
def main():
size = int(sys.argv[1]) if len(sys.argv) > 1 else 1024
rng = np.random.default_rng(2026)
u = rng.random((size, size), dtype=np.float64)
a = rng.random(size * size, dtype=np.float64)
reference, serial_time, serial_min, serial_max = measure(step_serial, u)
result, parallel_time, parallel_min, parallel_max = measure(
step_parallel, u
)
assert np.allclose(result, reference, rtol=1e-12, atol=1e-12)
assert np.array_equal(result[[0, -1], :], u[[0, -1], :])
assert np.array_equal(result[:, [0, -1]], u[:, [0, -1]])
sum_reference = sum_serial(a)
sum_result = sum_parallel(a)
assert np.isclose(sum_result, sum_reference, rtol=1e-12, atol=1e-12)
print(f"Python: {sys.version.split()[0]}")
print(f"NumPy: {np.__version__}")
print(f"NUMBA_NUM_THREADS: {os.environ.get('NUMBA_NUM_THREADS', 'не задано')}")
print(f"Сетка: {size} x {size}; повторов: 5")
print(
f"Стенсил serial: {serial_time:.6f} с "
f"(min {serial_min:.6f}, max {serial_max:.6f})"
)
print(
f"Стенсил parallel: {parallel_time:.6f} с "
f"(min {parallel_min:.6f}, max {parallel_max:.6f})"
)
print(f"Ускорение: {serial_time / parallel_time:.3f}x")
print(f"Редукция serial: {sum_reference:.12f}")
print(f"Редукция parallel: {sum_result:.12f}")
print("Корректность стенсила и границ: True")
if __name__ == "__main__":
main()