Previous | Next --- Slide 6 of 45
Back to Lecture Thumbnails
dumbo_

In class question: What's the difference between cilk and pthread? Though they share similar syntax, cilk_spawn creates a new logical thread of control. It doesn’t mean that it will do it in parallel. It just says it’s something independent and you may want to do it in parallel. While pthread_create actually creates a thread.

Basically cilk_spawn is an abstraction which indicates potential parallelism (one reasonable implementation of it can even be sequentially run all the spawned functions). While pthread_create is an implementation of creating new threads.

russt17

I think this abstraction makes Cilk especially useful. You can imagine trying to parallelize some recursive function that traverses a tree using pthreads and accidentally creating an amount of pthreads exponential with the tree's depth...With Cilk you just can safely declare the parallelizable tasks and let the constant size thread pool work through them.

dsaksena

I agree with russt17 here, his example makes sense. It explains why having pthreads wasn't enough and we needed a higher abstraction to have a constant pool.

A follow up question, does cilk also sense the number of cores and SIMD vector-size available and dynamically determine this constant sized pool?

BigFish

@dsaksena Cilk plus provides programmers with interfaces to explicitly set the number of threads: __cilkrts_set_param("nworkers", nthreads);

ghawk

This discussion of possible parallelism of independent instructions spawned by cilk_spawn reminds me of a small quiz before an earlier class in course, as described in this slide.