Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Parallel calculation leads to random corruption of the results
Forum Updated to NodeBB v4.3 + New Features

Parallel calculation leads to random corruption of the results

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 679 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • nulluseN Offline
    nulluseN Offline
    nulluse
    wrote on last edited by nulluse
    #1

    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!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • nulluseN Offline
        nulluseN Offline
        nulluse
        wrote on last edited by
        #3

        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();
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved