Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.

Cilk and thread identification

Joseph_S_Intel
Employee
129 Views
Is there a way to tag or identify threads from within a cilk_for loop?
0 Kudos
2 Replies
aazue
New Contributor I
129 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
129 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

Reply