Software Archive
Read-only legacy content

Cilk worker

Haris_R_1
Beginner
623 Views

Hello,

I would like to understand Cilk worker creation a litter better.
I am not sure how to phrase this question so I’ll give it my best.
I have downloaded Intel Cilk runtime release (cilkplus-rtl-003365 -  released 3-May-2013).

I would like to create a new Cilk worker that does not cause cross-threading issues but this new worker would not be a part of the work collective.

For example, if I run “CILK_NWORKERS=4 ./fib 30” 
This means that runtime created with 4 Cilk workers to execute fib. 
When Cilk runtime starts up, I would like to also create a 5th worker that does not participate in stealing and/or executing of fib.
This new 5th worker just prints some string every 2 seconds.

If I’m not mistaken, worker creation begins in “sysdep-unix.c” in function “create_threads()”

From my understanding and the way I have traced worker creation, following takes place:

  1. “create_threads()” in invoked from “__cilkrts_start_workers()”from “sysdep-unix.c”
  2. “__cilkrts_start_workers()” is invoked from “__cilkrts_init_internal()” from “scheduler.c”
  3. Finally, “__cilkrts_init_internal()” is invoked from “CILK_ABI_WORKER_PTR BIND_THREAD_RTN()” found in “cilk-abi.i”

I suppose my questions is, can one get Cilk runtime to create a “non-working” worker that does something very simple like printing a string?
This new worker does not participate in stealing and/or executing BUT it does not interfere with other “working” workers.

I would sincerely appreciate any hint, advice, or recommendation. I can also provide more detail on what I’m trying to do if it helps.

Thank you for your time,
Haris

0 Kudos
2 Replies
Hansang_B_Intel
Employee
623 Views

Hi,

I don't think there is an easy way to exclude a Cilk worker from being scheduled for Cilk tasks, but you should be able to create a separate thread (i.e., pthread_create) and make it run the task you want as long as it does not need to interfere with the working workers and is not involved in any Cilk activities (spawn, sync, cilk_for) during its execution. In this case, a user-created thread does not use any data structure for a Cilk worker and is not part of the team managed by the Cilk scheduler.

Hope this helps you.

0 Kudos
Barry_T_Intel
Employee
623 Views

As Hansang said, you can use pthread_create (or CreateThread) to create your own threads, or another threading package like OpenMP or TBB. However, I wanted to add that you can use the Cilk keywords in these threads without a problem. User-created threads are referred to as "user" threads to differentiate them from the "worker" threads that the Cilk runtime creates. The worker threads are shared among all of the user workers 

There's are a couple of subtle differences in the way user and worker threads are handled:

  • A worker thread can steal work from any thread that has available work and joins the team of that the thread it steals from. A user thread can only steal work from another thread that's on it's team. If a user worker attempts to steal work for another team, the steal fails and the worker will loop around the steal loop, looking for a thread on it's team with work it can steal. This guarantees that a user thread is always making progress on it's tasks instead of being co-opted to work for another thread.
  • Only a user thread can continue from a top-level sync. This is how we guarantee that you'll be on the same thread when you leave the top-level spawning function, so thread-local storage works as expected outside of Cilk parallel regions.

The major thing you have to be careful of is "sandwiches"; OpenMP code which calls Cilk code which calls OpenMP code. This can lead to a combinatorial explosion of threads, since OpenMP will create teams of threads at both levels. Of course, you have the same problem with OpenMP calling OpenMP. If you do the sandwich the other way (Cilk calling OpenMP calling Cilk) you're OK since Cilk will only create a single set of worker threads and share them as I described above. And the Cilk and TBB teams have worked together to make sure that this isn't a problem when mixing Cilk and TBB.

    - Barry

0 Kudos
Reply