3
votes

I would like to write parallel code for Intel Xeon Phi using Intel TBB and Cilk Plus but i have a problem with thread affinity. I want to bind one thread to one logical core. Is is possible to set affinity like in OpenMP? I mean KMP_AFFINITY="compact". Thank you in advance. :)

1
What problem are you trying to solve if you must have fine grain controlled thread affinity. TBB doesn't have proper thread affinity, only task level affinity. tbb::affinity_partitioner will already try to preserve cache coherency. - BlamKiwi

1 Answers

3
votes

Yes, it's possible and moreover it is recommended in conjunction with affinity_partitioner on Xeon Phi. Please see the blog for details. Here is a short code snippet to give you idea how does it look like:

class pinning_observer: public tbb::task_scheduler_observer {
public:
    pinning_observer();
    /*override*/ void on_scheduler_entry( bool );
    ~pinning_observer();
};

pinning_observer pinner;
pinner.observe( true );

There are no any special means for doing so in Cilk Plus.