Код: Выделить всё
int main()
{
// only the main program thread exists here
#pragma omp parallel num_threads(2)
{
if (omp_get_thread_num() == 0)
{
// this block is guaranteed to be executed by the main program thread
}
}
}
Код: Выделить всё
int main()
{
// only the main program thread exists here
#pragma omp parallel num_threads(2)
{
if (omp_get_thread_num() == 1)
{
#pragma omp parallel num_theads(2)
{
if (omp_get_thread_num() == 0)
{
// this block is NOT executed by the program main thread
}
}
}
}
}
Демонстрация в реальном времени: https://godbolt.org/z/5K3ja8fY1
Мой вопрос заключается в том, есть ли какой-либо способ распознать основной поток программы в параллельной области OpenMP, которая всегда работает.
(Я мог бы использовать для этой цели std::this_thread::get_id(), как показано в демо; однако я не уверен, гарантируется ли переносимость вместе с OpenMP.)
Подробнее здесь: https://stackoverflow.com/questions/798 ... mp-program
Мобильная версия