Previous | Next --- Slide 10 of 64
Back to Lecture Thumbnails
haoala

I'm wondering what it would have taken to do dynamic assignment with pthreads on A1P1Q4 (Mandelbrot fractal generation). I guess we could do something similar to the code on this slide - the next row to be processed would be indexed by counter. We would also have to modify the struct WorkerArgs. Even so, the cost of synchronization could outweigh the benefits of dynamic assignment.

mario

The parallel program creates a work queue that may not necessarily update the consecutive element in the array because testing for primality of one number may take more time than doing so for others. Therefore, when 1 thread completes, it may need to go further along the array to find the next element in the array to compute for.

paracon

@haoala, I think if you have each pixel being computed by a different task, then you can rely on the runtime to decide scheduling. Dynamic assignment would work here because a Mandelbrot set produces an image where nearby pixels have very different workloads which cannot be known apriori(unless you know the image that is going to be generated) It will be interesting to see though if we can actually get a good enough speedup by overcoming the overhead of task launches.

rrp123

In this case, we could still have the same issue where one thread gets a very large amount of work to do and finishes much later than the other threads. Thus, part of our program could still be sequential. One way to fix this would be to go in descending order of numbers rather than ascending to ensure that the threads finish their heavier workloads first and leave lighter workloads to the end. This could make the sequential portion (where one thread is working but none of the other are) much smaller.