Parellelism in STL | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Parellelism in STL

Hi Please find attached code. Question is related to threads.... With execution strategies as par i.e. parellel, why thread id is not printed differently for each element access due to different different threads ? Thread id is same for this code which means no different threads are created ? https://code.sololearn.com/c6S4hojS3zm1/?ref=app

21st Sep 2021, 10:52 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
3 Answers
+ 2
Ketan Lalcheta afaik, execution policy is just a permission and not requirement, so it is quite possible for algorithm to execute sequentially even if you tell compiler to call parallel overload of the same.
22nd Sep 2021, 5:15 PM
Arsenic
Arsenic - avatar
+ 1
I confirmed that the id being printed is the same as the main thread id. Maybe I am missing something, but I don't see where the code starts any new threads. I expected to find a statement in the form of: std::thread handle (process, params); Side note: multithreading is not necessarily done in parallel. Parallel only occurs if threads get distributed across processors. Otherwise, it is done concurrently.
22nd Sep 2021, 1:52 PM
Brian
Brian - avatar
0
I thought par execution strategy will start new threads and hence increases speed
22nd Sep 2021, 2:41 PM
Ketan Lalcheta
Ketan Lalcheta - avatar