In OpenMP, I can create a set of tasks as follows and execute them asynchronously using some fixed number of threads:
#pragma omp parallel { #pragma omp single { for (int i = 0; i < 1000; i++) { #pragma omp task f(i); } } }
In C ++ 11, I can do something not quite the same std::async:
std::async
std::vector<std::future> futures; for (int i = 0; i < 1000; i++) { auto fut = std::async(f, i); futures.push_back(std::move(fut)); } ... for (auto & fut : futures) { auto res = fut.get(); // do something with res }
I am worried about efficiency. If I am right, in OpenMP , tasks are stored in the pool of some tasks, and then are distributed among threads (automatically using the OpenMP environment).
In C ++ , at the time of a call, the std::asyncruntime decides whether to start asynchronously f(i)in a new thread or delay its execution to the point of call std::future::get.
f(i)
std::future::get
Therefore, either the runtime
, , , , OpenMP ( ).
, OpenMP ++?
UPDATE
: https://wandbox.org/permlink/gLCFPr1IjTofxwQh 12C Xeon E5, GCC 7.2 -O2:
-O2
( ). .
500 000 (n) 1000 (m), :
n
m
2
( pthread_create : qaru.site/questions/873190/...):
pthread_create
(20 000 , 20 000 ):
(500 000 , 1000 ):
, , std::async.
OpenMP , , . untied , -, .
untied
, ++ 11, std::launch::async, std::launch::deferred. std::thread, , wait. , ( ):
std::launch::async
std::launch::deferred
std::thread
wait
, policy launch::async | launch::deferred, , concurrency .
policy
launch::async | launch::deferred
, , , , , , -, ! launch:async , , std::thread - , , .
launch:async
, std::thread , . , , [ <thread>] " " .
<thread>
, . OpenMP .
, std::async, .
, , OpenMP. OpenMP - API, " " , . , . , . , , parallelism.
, OpenMP: , , , , , , , std::async : ( ) , - , , . std::async ( ) . .
, , , std::thread. , , ( ), std::async OpenMP, , .
, , : , OpenMP , . . , , - , .
Source: https://habr.com/ru/post/1691070/More articles:Removing similar but longer duplicates from vector - setJQuery id - javascriptОбъявление свойства PHP принимает массив и не принимает никаких других выражений, которые могут быть оценены в процессе компиляции - oopWhat is the best way to develop Google Sheets scripts and Git versions - githubТребования Кордовы бросают "foreach" undefined - cordovaHow to properly execute / resume unrelated OpenMP tasks? - openmptesting non-exported methods in python - pythonHandling HTTP Errors with ngRx - angularHow to remove Java 9 on macOS Sierra - javaGo to Implementations using sourcelink - c #All Articles