# Evaluation of the efficiency of implementation of asynchronous computing algorithms using coroutines and threads in С++

## DOI:

https://doi.org/10.34185/1562-9945-3-146-2023-06## Keywords:

coprogram, coroutine, asynchronous programming, multithreading, parallel computing, algorithm, speed## Abstract

Modern multi-core systems are most effective when used in large server centers and for cloud computing. However, despite the known complexity of software implemen-tation, parallel computing on multiprocessors is increasingly used in computer model-ling. Advanced mechanisms of synchronous and multithreaded programming are in-creasingly used to improve the productivity of numerical studies, reducing the time of computer models implementation. One such mechanism is coroutines, a convenient tool for managing asynchronous operations introduced in the C++20 standard. A special feature of coroutines is the ability to suspend a function at a certain stage, saving its state, and after some time resume its execution from the previous stop. The aim of this research is to improve the performance of computer modelling by using coroutines and data threads. As a result of the work, a test algorithm for multiplying a matrix by a vector and its modified asynchronous version using the coroutine mechanism and splitting into two data threads was developed, which allowed to achieve 1.94 times increase in the com-puting speed when the matrix dimension is 15000 (2.25×106 elements). It has been found that at a small matrix dimension, the developed asynchronous algorithm using coroutines and splitting into two threads is less efficient than the single thread algo-rithm. This is due to the fact that the compiler needs some time to create threads and start execution simultaneously. With a large dimensionality, the performance of the asynchronous algorithm increases significantly. With a matrix dimension of more than 1200, the use of an asynchronous algorithm divided into two threads is guaranteed to be more efficient than a single-threaded. The data obtained are consistent with the results of similar studies of the problem of increasing the efficiency of computer modelling using alternative software and hard-ware. The new method of solving the problems of asynchronous programming provides a more efficient and simple mechanism for managing asynchronous operations.

## References

Andrist B. C++ High Performance: Master the art of optimizing the functioning of your C++ code / B. Andrist, V. Sehr, B.Garney. – 2nd Edition: textbook. – 2020. – 540 p.

Conway Melvin E. Design of a separable transition-diagram compiler/ Melvin E. Conway // Communications of the ACM. – 1963. – Vol. 6. – № 1. – P.396 – 408.

Knuth Donald E. Fundamental algorithms, The art of computer programming / Donald E. Knuth. – Publisher: Addison-Wesley, 1968. – Vol.1.– 634 p.

Zhulkovskyi O.O. Evaluating the effectiveness of the implementation of computa-tional algorithms using the OреnMP standard for parallelizing programs / O. O. Zhulkovskyi, I. I. Zhulkovska, V. V. Shevchenko // Informatics and Mathematical Methods in Simulation. – 2021. – Vol.11. – №4. – P. 268 – 277.

DOI: 10.15276/imms.v11.no4.268

Zhulkovskyi O. O. Evaluation of the efficiency of the implementation of parallel computational algorithms using the library in C++ / O.O.Zhulkovskyi, I. I. Zhulkovska, V. V. Shevchenko, H. Ya. Vokhmianin // Computer Systems and In-formation Technologies. – 2022. – № 3. – P. 49–55. DOI: 10.31891/csit-2022-3-6

Fertig A. Programming with C++20: Concepts, Coroutines, Ranges, and more/ A. Fertig, F. Panter. – Textbook. – 2021. – 333 p.

Browning J. Burton. C++20 Recipes: A Problem-Solution Approach / J.Burton Browning, B. Sutherland. – 2nd Edition: textbook. – 2020. – 657 p.

Williams A. C++ Concurrency in Action: Practical Multithreading/ A.Williams. – Textbook. – 2012. – 528 p.

Mastering Posch M. C++ Multithreading: Write robust, concurrent, and parallel applications / Posch M. Mastering. – Textbook. – 2017. – 246 p.

Zhulkovskii O. A. Information-Modeling Forecasting System for Thermal Mode of Top Converter Lance / O.A. Zhulkovskii, S.P. Panteikov, I.I.Zhulkovskaya // Steel in Translation. – 2022. – Vol. 52. – № 5. – P. 495–502.

DOI: 10.3103/S0967091222050138

Zhulkovskyi O.O. Features of Mathematical simulation of the processes of com-bined heat transfer in waveguides / O.O. Zhulkovskyi, Iu.V. Savchenko, I.I. Zhulkovska et al. // Proceedings of the 2022 IEEE 4th International Conference on Modern Electrical and Energy System, MEES 2022. – P.452–456.

DOI: 10.1109/MEES58014.2022.10005676