Skip to main content

Posts

Showing posts with the label threading

Leveraging CUDA for General Parallel Processing Application

  Photo by SevenStorm JUHASZIMRUS by pexel Differences Between CPU-based Multi-threading and Multi-processing CPU-based Multi-threading : - Concept: Uses multiple threads within a single process. - Shared Memory: Threads share the same memory space. - I/O Bound Tasks: Effective for tasks that spend a lot of time waiting for I/O operations. - Global Interpreter Lock (GIL): In Python, the GIL can be a limiting factor for CPU-bound tasks since it allows only one thread to execute Python bytecode at a time. CPU-based Multi-processing : - Concept: Uses multiple processes, each with its own memory space. - Separate Memory: Processes do not share memory, leading to more isolation. - CPU Bound Tasks: Effective for tasks that require significant CPU computation since each process can run on a different CPU core. - No GIL: Each process has its own Python interpreter and memory space, so the GIL is not an issue. CUDA with PyTorch : - Concept: Utilizes the GPU for parallel computation. - Massi...

The new feature in Python 3.13 allowing CPython to run without the Global Interpreter Lock

Understanding Free-threaded CPython and Parallel Execution The new feature in Python 3.13, allowing CPython to run without the Global Interpreter Lock (GIL), is significant for improving parallelism in Python programs. Here’s a detailed explanation along with a code example to illustrate how it works and the benefits it brings: Key Points 1. Disabling the GIL : CPython can be built with the `--disable-gil` option, allowing threads to run in parallel across multiple CPU cores. 2. Parallel Execution : This enables full utilization of multi-core processors, leading to potential performance improvements for multi-threaded programs. 3. Experimental Feature : This is still experimental and may have bugs and performance trade-offs in single-threaded contexts. 4. Optional GIL : The GIL can still be enabled or disabled at runtime using the `PYTHON_GIL` environment variable or the `-X gil` command-line option. 5. C-API Extensions : Extensions need to be adapted to work without the GIL. Demo Code...