Previous | Next --- Slide 26 of 64
Back to Lecture Thumbnails
taz

Is there any advantage of the 2nd photo (spawning foo() and bar()) over the 1st (only spawning foo())? Since the 2nd photo probably has more overhead, so why would you ever do it? Easier to understand? Convention?

Qiaoyu

@taz, my understanding is that we can treat them as master and slaves. While the slaves are busy at computation, master can do other things that are hard to parallelize such as work scheduling. Of course,I think we can also see the third picture as master is running some scheduling function "buzz()" while others is working in parallel.

whitelez

@taz, I think there is no advantages in this particular one (Image 2) compare to Image 1. The image is just indicating there would be extra overhead (potential) of spawning every function. However if the runtime assign only one thread to this code, image 1 and image 2 doesn't make any different.

bschmuck

Is it possible to specify a block of code or function to run after the function called asynchronously with cilk_spawn has been completed? For a case where there is code that follows that is dependent on the async thread, this would sometimes be a better solution than stalling the entire program with cilk_sync.

M12

@bschmuck I don't believe cilk requires any specific API call for such a request. Consider the buzz() function. As long as buzz() contains independent computations (from that of the other three functions), this is work that is done without actually waiting. The cilk programmer would just want to make it so that the buzz() function does about the same amount of work as the other three functions -- which would minimize waiting.

Not sure if you had something else in mind though..

themj

How does the program know that all of the spawned threads have completed so that it can sync them all together?

fxffx

The second example does the same work as the first example, but may cause longer time because of thread spawning overhead. So the first one is better.