Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

oneAPI tbb + fopenmp: just one core used?

tayttttt
Beginner
579 Views

Edit: NVM I missed some OMP environment variables

 

Hi,

consider the following toy program:

 

 

#include <iostream>

#include <tbb/global_control.h>
#include <tbb/parallel_for.h>
#include <tbb/enumerable_thread_specific.h>

int main(int argc, char *argv[]) {
  tbb::global_control gc{tbb::global_control::max_allowed_parallelism, 8};

  tbb::enumerable_thread_specific<long long> sum;
  for (int it = 0; it < 5; ++it) {
    tbb::parallel_for(0, 500'000'000, [&](const int i) {
                                        sum.local()++;
                                      });
  }
  std::cout << "---" << std::endl;

  for (auto i : sum) { std::cout << i << std::endl; }
}

 

 

Compiling this program with

 

 

g++ test.cc -ltbb

 

 

 Produces a program that uses 8 cores / 8 threads. However, if g++ is called with an additional fopenmp flag:

 

 

g++ test.cc -ltbb -fopenmp

 

 

The program runs approx. 7 times slower since it only uses one core / 2 threads. 

Why does this happen? Is oneAPI TBB incompatible with OpenMP? 

(I'm using GCC 11.1.0 and oneAPI TBB 2021.2.0)

 

Thank you!

0 Kudos
3 Replies
NoorjahanSk_Intel
Moderator
550 Views

Hi,

 

Thanks for reaching out to us.

 

>>I'm using GCC 11.1.0 and oneAPI TBB 2021.2.0

 

GCC 11.1.1 version support has been enabled with oneTBB 2021.4 version, so could you please try with the latest version of oneTBB 2021.4?

 

Refer to the below link for more details:

https://www.intel.com/content/www/us/en/developer/articles/release-notes/intel-oneapi-threading-buil...

 

Please do let us know if you still face any issues along with the OS version being used.

 

I tried with the latest version(2021.4) of Intel oneTBB and g++ (9.3) on Ubuntu and observed that it is utilizing 8threads/cores even with

-fopenmp option included while compiling the code.

 

Please refer to the attached screenshot for more details.

 

 

Thanks & Regards,

Noorjahan.

 

NoorjahanSk_Intel
Moderator
518 Views

Hi,


We haven't heard back from you. Could you please provide an update on your issue?


Thanks & Regards,

Noorjahan.


NoorjahanSk_Intel
Moderator
472 Views

Hi,


I have not heard back from you, so I will close this inquiry now. If you need further assistance, please submit a new question as this thread will no longer be monitored.


Thanks & Regards,

Noorjahan.


Reply