Parallel calculation leads to random corruption of the results



  • I am learning Qt parallel namespace on the Mandelbrot set test app.
    When I run regular single-threaded calculation over the data vector, the result is always the same.
    But when the parallel calculation runs using QtConcurrent::map, the results become corrupt after about 300,000 elements of the vector and corruption is seemingly random (the last screen shows that no corruption occurred even though the 1st and 2nd were corrupt).

    Attaching the Zipped Netbeans project and the screenshots of parallel computation.
    Project
    Snapshot1
    Snapshot2
    Snapshot3

    Can anyone please point me in the right direction of what I am doing wrong?

    Thank you!


  • Lifetime Qt Champion

    Hi,

    You don't wait for map to finish before updating the picture.



  • Excellent, I totally mis-read the tutorials and was convinced that assigning to the future was supposed to do that.
    Now this works perfect:

        QFutureWatcher<void> fw;
        fw.setFuture(QtConcurrent::map(vec, mandelbrot));    
        fw.waitForFinished();

  • Lifetime Qt Champion

    Since you want to do multithreading, why not use the finished signal ? Beware, you'll have to refactor the code a bit.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.