Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Joseph_S_Intel
Employee
45 Views

Cilk and thread identification

Is there a way to tag or identify threads from within a cilk_for loop?
0 Kudos
2 Replies
aazue
New Contributor I
45 Views

Hi

Without practice this lib (backend)..
I don't know is it help you ,

ps -AT giving all identifier , if i remember with my old head now...
(right is (fork (pid) repeated line) left is (sub) thread , ipc ....)
To decrease bottom level side learning:
read source utility ps and extract function just necessary for you
Strange that this function is not already existing with this lib ??
It would be possible to wrong the origin process with that you operate two side ...
regards
jimdempseyatthecove
Black Belt
45 Views

Is there a way to tag or identify threads from within a cilk_for loop?


For tagging threads I use Thread Local Storage to contain a cardinal thread number.
Staticly initialize the variable with -1, then when you want the ID test value of TLS id variable, if .lt. 0 atomic incriment a variable used for the next ID and take the prior value (or incrimented value) and insert into the TLD id variable. Something like the following untested code.

__declspec(thread) long myThreadID = -1;
volatile long myNextThreadID = 0;

inline long getMyThreadID()
{
if(myThreadID >= 0)
return myThreadID;
myThreadID = InterlockedExchangeAdd(&myNextThreadID, 1);
return myThreadID ;
}

Jim Dempsey