Організація багатопотокових обчислень в С++
Date
Journal Title
Journal ISSN
Volume Title
Publisher
Видавництво Львівської політехніки
Lviv Politechnic Publishing House
Lviv Politechnic Publishing House
Abstract
Впродовж багатьох років, збільшення обчислювальної потужності сучасних пристроїв досягається не через підвищення тактової частоти та пропускної здатності процесорів, а шляхом застосування гіперпотокових і багатоядерних архітектур. Ця проста зміна підходу до дизайну комплектуючих призвела до драматичних змін в організації обчислень і стала поворотним пунктом для розробників програмного забезпечення. Програмне забезпечення, яке має скористатися збільшенням обчислювальної потужності багатоядерних архітектур, повинно бути розроблена таким чином, щоб мати змогу одночасно виконувати кілька завдань. При висвітленні теми паралельних/одночасних обчислень науковці та фахівці в галузі ІТ користуються двома термінами: (1) «паралелізм» (англ. parallelism) та (2) «одночасне/узгоджене виконання» (англ. сoncurrency). Третім важливим терміном при розгляді паралельних/одночасних обчислень, є «багатопотоковість» (multithreading). У C++ двома найпоширенішими способами реалізації паралелізму є узгоджене виконання та власне паралелізм. Хоча їх можна використовувати і в інших мовах програмування, C++ виділяється своїми можливостями використання одночасних обчислень з нижчим, ніж середнє, залученням загальних ресурсів машини, а також здатністю виконувати складні інструкції. У стандарті C++11 була запропонована підтримка багатопотокових програм. Стандарт C++ визнавав існування багатопотоковості у мові та надавав компоненти для написання багатопотокових програм у бібліотеці . Це зробило можливим написання багатопотокових програм на C++, не покладаючись на специфічні для певної платформи розширення, та дало змогу створювати портативний багатопотоковий код із гарантованою поведінкою. Бібліотека надає широкі можливості для організації паралельних та узгоджених/одночасних обчислень, містить також модель пам’яті C++, умовні змінні, м’ютекси та ін. для синхронізації роботи потоків. У статті здійснено аналіз можливостей написання програм мовою C++ з використанням кількох потоків для паралельного та/або узгодженого виконання завдань, а також розгляд функцій мови C++ і засобів бібліотеки , які роблять це можливим.
For many years, the increase in computing power of modern devices is achieved not by increasing the clock frequency and bandwidth of CPUs, but by using hyper-threaded and multicore architectures. This simple change in approach to the CPU design led to dramatic changes in the organization of computing and became a turning point for software developers. Software that is going to take advantage of the increased computing power of multi-core architectures must be designed to be able to perform multiple tasks simultaneously. When covering the topic of parallel/simultaneous computing, scientists and IT professionals use two terms: (1) parallelism and (2) concurrency. A third important term when considering parallel/simultaneous computing is “multithreading”. In C++, the two most common ways to implement parallelism are concurrency and parallelism itself. Although they can be used in other programming languages, C++ stands out for its ability to use concurrent computations with lower-than-average utilization of general machine resources, as well as its ability to execute complex instructions. The C++11 standard introduced support for multi-threaded programs. The C++ standard recognized the existence of multithreading in the language and provided components for writing multithreaded programs in the library. This made it possible to write multithreaded programs in C++ without relying on platform-specific extensions and enabled the creation of portable multithreaded code with guaranteed behavior. The library provides extensive opportunities for organizing parallel and concurrent calculations, it also contains the C++ memory model, conditional variables, mutexes, etc. for thread synchronization. The article analyzes the possibilities of writing programs in the C++ using multiple threads for parallel and concurrent execution of tasks. It also considers the features of the C++ and the tools of the library that make parallelism and concurrency possible.
For many years, the increase in computing power of modern devices is achieved not by increasing the clock frequency and bandwidth of CPUs, but by using hyper-threaded and multicore architectures. This simple change in approach to the CPU design led to dramatic changes in the organization of computing and became a turning point for software developers. Software that is going to take advantage of the increased computing power of multi-core architectures must be designed to be able to perform multiple tasks simultaneously. When covering the topic of parallel/simultaneous computing, scientists and IT professionals use two terms: (1) parallelism and (2) concurrency. A third important term when considering parallel/simultaneous computing is “multithreading”. In C++, the two most common ways to implement parallelism are concurrency and parallelism itself. Although they can be used in other programming languages, C++ stands out for its ability to use concurrent computations with lower-than-average utilization of general machine resources, as well as its ability to execute complex instructions. The C++11 standard introduced support for multi-threaded programs. The C++ standard recognized the existence of multithreading in the language and provided components for writing multithreaded programs in the library. This made it possible to write multithreaded programs in C++ without relying on platform-specific extensions and enabled the creation of portable multithreaded code with guaranteed behavior. The library provides extensive opportunities for organizing parallel and concurrent calculations, it also contains the C++ memory model, conditional variables, mutexes, etc. for thread synchronization. The article analyzes the possibilities of writing programs in the C++ using multiple threads for parallel and concurrent execution of tasks. It also considers the features of the C++ and the tools of the library that make parallelism and concurrency possible.
Description
Citation
Андрушко А. Організація багатопотокових обчислень в С++ / Андрій Андрушко, Олександр Маркелов // Комп’ютерні системи проектування. Теорія і практика. — Львів : Видавництво Львівської політехніки, 2023. — Том 5. — № 1. — С. 19–27.