CILK_NWORKERS don't have impact when using cilk_for

CILK_NWORKERS don't have impact when using cilk_for

Hello,

I use a loop for with cilk_for and when i run my program i use the CILK_NWORKERS to specify the number of workers.

So, when runnig, i see that my loop for is always divised on two workers even i set 8 or another number on the parameter CILK_NWORKERS.

How can i divise my loop for on 2, 4 or 8 workers ?

Thank you,

11 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

cilk_for uses a hueristic to determine the "grain size" that is used by the recursive divide-and-conquer algorithm. The code is in cilk-abi-cilk-for.cpp, if you've got the sources from the cilkplus branch of gcc. Roughly speaking, it's:

Px8 = 8 * g->P * 8;
grain = (loop_count + (Px8 - 1)) / Px8;

Where g-> is the number of workers.

So my first question is, how sure are you that you've specified CILK_NWORKERS correctly? You can use __cilkrts_get_nworkers() to get the number of workers that the Cilk runtime created (or will create).

Then there's the question of how you know how many workers are working on your loop?

- Barry

Hello,

I change successfully the number of workers dynamically by calling__cilkrts_set_param befor my loop as follwing :

__cilkrts_set_param("nworkers", "2");

printf ("nworkers : %d \n", __cilkrts_get_nworkers());

__cilkrts_init();

cilk_for(int k=0;k<50;k++) {.....}

It works fine :)

Thank you,

I'm glad to hear that your code is working now.

Be aware that if you want to change the number of workers during a run, you have to do the following:

  1. Make sure that *ALL* threads have returned from their spawning functions (functions containing a _Cilk_spawn statement).
  2. Call __cilkrts_end_cilk() to have the runtime shutdown. If there are *any* threads running a spawning function, the applicaiton will be aborted with an error message.
  3. Call __cilkrts_set_param("nworkers", "value") to set the new number of workers to use

The next call to a spawning function will automatically restart the runtime with the new number of workers.

- Barry

Thank you a lot for your advices,

I am having a similar problem using gcc-4.7.

To make sure I was not doing something stupid, I downloaded an old version of Cilk++ SDK and used two of the examples qsort and cilk-for. Using Cilk++ SDK both scale nicely to four workers.

If I use gcc-4.7 qsort still scales well, but cilk-for only scales to two - I am printing out the number of workers using __cilkrts_get_nworkers().

John Forrest

Hello John,
Can you please tell me the location from where and whenyou downloaded the Cilk Plus sources?

Thanks,

Balaji V. Iyer.

Balagi,

I am using gcc/branches/cilkplus-4_7-branch (svn at revision 186706). Using the libcilkrts created by compiling that was even worse, so I downloaded cilkplus-rtl-001857.tgz.

I am running 64 bit Ubuntu 11.10 on an Intel CORE I7.

Thanks for any help.

John

Hello John,
Can you please download the one from gcc/branches/cilkplus and try? It is the most up-to-date one.

Thanks,

Balaji V. Iyer.

Balaji,

Downloaded but no luck.

I downloaded
URL: svn://gcc.gnu.org/svn/gcc/branches/cilkplus
Repository Root: svn://gcc.gnu.org/svn/gcc
Repository UUID: 138bc75d-0d04-0410-961f-82ee72b054a4
Revision: 186880
Node Kind: directory
Schedule: normal
Last Changed Author: bviyer
Last Changed Rev: 186838
Last Changed Date: 2012-04-25 20:27:55 +0100 (Wed, 25 Apr 2012)

I built it
../cilk/configure --prefix=/j/mycilk \
--libexecdir=/usr/lib \
--enable-__cxa_atexit \
--enable-clocale=gnu \
--enable-languages=c,c++ \
--disable-multilib \
--disable-bootstrap \
--with-system-zlib \
CFLAGS="-fPIC \
-march=x86-64" \
AS=/usr/local/bin/as AS_FOR_TARGET=/usr/local/bin/as LDFLAGS=-L/usr/lib/x86_64-linux-gnu

Tried with previous runtime library from cilkplus-rtl-001857.tgz
--------------------
john@fasterCoin2:~/trunk/debug2/Clp/examples$ export CILK_NWORKERS=4;time cilk-for
Iterating over 10000 integers

real 0m4.511s
user 0m11.609s
sys 0m5.872s
john@fasterCoin2:~/trunk/debug2/Clp/examples$ export CILK_NWORKERS=2;time cilk-for
Iterating over 10000 integers

real 0m4.352s
user 0m8.517s
sys 0m0.052s
john@fasterCoin2:~/trunk/debug2/Clp/examples$ export CILK_NWORKERS=1;time cilk-for
Iterating over 10000 integers

real 0m8.634s
user 0m8.509s
sys 0m0.004s
----------
So 2 looks good but 4 is bad

with libcilkrts from cilkplus build
john@fasterCoin2:~/trunk/debug2/Clp/examples$ export CILK_NWORKERS=4;time cilk-for
Iterating over 10000 integers

real 0m8.726s
user 0m13.745s
sys 0m20.757s
john@fasterCoin2:~/trunk/debug2/Clp/examples$ export CILK_NWORKERS=2;time cilk-for
Iterating over 10000 integers

real 0m8.651s
user 0m10.117s
sys 0m7.080s
john@fasterCoin2:~/trunk/debug2/Clp/examples$ export CILK_NWORKERS=1;time cilk-for
Iterating over 10000 integers

real 0m8.663s
user 0m8.537s
sys 0m0.012s

Not good at all
------------------
showing that qsort example i.e. spawn is fine
john@fasterCoin2:~/trunk/debug2/Clp/examples$ export CILK_NWORKERS=1;time qsort
Sorting 10000000 integers

real 0m8.791s
user 0m8.593s
sys 0m0.020s
john@fasterCoin2:~/trunk/debug2/Clp/examples$ export CILK_NWORKERS=2;time qsort
Sorting 10000000 integers

real 0m5.586s
user 0m9.509s
sys 0m0.244s
john@fasterCoin2:~/trunk/debug2/Clp/examples$ export CILK_NWORKERS=4;time qsort
Sorting 10000000 integers

real 0m3.686s
user 0m9.521s
sys 0m0.512s
---------------------

Any suggestions?

John Forrest

Thank you for the descriptive message. I will look into it and get back to you!

-Balaji V. Iyer.

Leave a Comment

Please sign in to add a comment. Not a member? Join today