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

number of cores

Zhongze_L_
Beginner
637 Views
Hi,

Does anybody know how to get the number of cores in TBB?

Thanks,
Zhongze
0 Kudos
7 Replies
christian_roessel
637 Views
Hi Zhongze,

tbb::task_scheduler_init::default_num_threads() returns the number of threads that the task scheduler will use by default. Often this is equal to the number of cores, but I don't know how hyperthreading CPUs are treated.

Regards,
Christian

0 Kudos
Andrey_Marochko
New Contributor III
637 Views
Each HT (or "logical") core is treated in the same way as a full core.

0 Kudos
AJ13
New Contributor I
637 Views
Hi Zhongze,

If you don't mind my asking, what do you need to know the number of cores for?

AJ
0 Kudos
Alexey-Kukanov
Employee
637 Views

MADamarochk:
Each HT (or "logical") core is treated in the same way as a full core.

I would add that this may change in future.

0 Kudos
Andrey_Marochko
New Contributor III
637 Views
To complete the picture, TBB sees only those CPUs/cores (HT or full) that are enabled by the BIOS and OS.

0 Kudos
Zhongze_L_
Beginner
637 Views

I need that number in order to partition a graph. It doesn't make sense to partition a graph into 16 subgraphs on a dual core machine or partition a graph into 2 subgraphs on a quad-core machine.

Thanks,
Zhongze
0 Kudos
Andrey_Marochko
New Contributor III
637 Views
Hi, Zhongze

As I explained in the answer to your other post, you most probably do not need to know the number of cores at all, since the degree of partitioning should depend on the amount of work necessary to process each subgraph. And if your sparse matrices are really large, then you should partition the graph in much more parts then the number of cores.

In fact partitioning into 16 (or even more) subgrapphs on dualcore machine usually makes perfect sence, as the work distribution across the subgraphs is normally very nonuniform (this is one of the problems with running MPI version of this algorithm on the grids). TBB applications running on shared memory systems can benefit from fine grained parallelism. Follow the link above for more details.
0 Kudos
Reply