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

Task affinity example?

irisshinra308
Beginner
830 Views
I am new to Intel TBB, and I am trying to add some new features on it.
However, I do not quite understand how to use the note_affinity and set_affinity methods?
I am wondering if there are some example codes with these methods?

Any help would be grateful.
Thanks for reading.

0 Kudos
1 Solution
Andrey_Marochko
New Contributor III
830 Views
Actually note_affinity and set_affinity are part of the low-level TBB tasking support. Our general recommendation is to start your TBB work with learning TBB algorithms (like tbb::parallel_for, tbb::parallel_reduce, tbb::pipeline and so on). These algorithms are easy to use and cover the vast majority of parallelization scenarios, so that only in the most non-trivial cases you may need to resort to manual building task hierarchies.

As long as tbb::parallel_for or tbb::parallel_reduce suit your purposes you can use tbb::affinity_partitioner with them. This partitioner internally uses tbb::task::note_affinity and tbb::task::set_affinity methods to take advantage of cache locality.

You can find more iformation about affinity partitioner in the "Bandwidth and Cache Affinity" article in the TBB Tutorial, and examples of code using it in GettingStarted/substring_finder and parallel_for/seismic (the standard TBB examples).

View solution in original post

0 Kudos
2 Replies
Andrey_Marochko
New Contributor III
831 Views
Actually note_affinity and set_affinity are part of the low-level TBB tasking support. Our general recommendation is to start your TBB work with learning TBB algorithms (like tbb::parallel_for, tbb::parallel_reduce, tbb::pipeline and so on). These algorithms are easy to use and cover the vast majority of parallelization scenarios, so that only in the most non-trivial cases you may need to resort to manual building task hierarchies.

As long as tbb::parallel_for or tbb::parallel_reduce suit your purposes you can use tbb::affinity_partitioner with them. This partitioner internally uses tbb::task::note_affinity and tbb::task::set_affinity methods to take advantage of cache locality.

You can find more iformation about affinity partitioner in the "Bandwidth and Cache Affinity" article in the TBB Tutorial, and examples of code using it in GettingStarted/substring_finder and parallel_for/seismic (the standard TBB examples).

0 Kudos
Dmitry_Vyukov
Valued Contributor I
830 Views
I am curious as to what you are trying to implement with note_affinity()/set_affinity(). Please provide some brief description (if it's not a trade secret of course).

0 Kudos
Reply