Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Parallel Programing
Forum Updated to NodeBB v4.3 + New Features

Parallel Programing

Scheduled Pinned Locked Moved C++ Gurus
9 Posts 6 Posters 3.3k Views 4 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.
  • E Offline
    E Offline
    Exotic_Devel
    wrote on last edited by
    #1

    Parallel programing is a ancient subject. But still not very used (my opinion).
    At a simple desktop application (connection with database, sales and purchases), whats the benefits can provide the parallel programing?

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

      Hi,

      When you say parallel programming, do you mean multithreading ?

      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
      • E Offline
        E Offline
        Exotic_Devel
        wrote on last edited by
        #3

        Yes, I know it the parallel programing provide benefice related to performance. But to a simple desktop app (sales, ...), is there a benefice?

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

          The only answer is: it depends. It's really use case based. Threads are not the answer to all e.g. you can do much things asynchronously with Qt.

          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
          • JKSHJ Online
            JKSHJ Online
            JKSH
            Moderators
            wrote on last edited by
            #5

            Parallel processing helps if you have functions that take a long time to return (for example, if your database queries take 5 seconds). In this example, your GUI will freeze if you use 1 thread only.

            Having said that, you might be able to optimize your program in other ways (for example, you could rewrite your SQL query to be more efficient). If you can make your functions return faster, then you don't need parallel programming.

            @Exotic_Devel said:

            Yes, I know it the parallel programing provide benefice related to performance.

            Not always. If you use it wrongly, you can get worse performance.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mcosta
              wrote on last edited by
              #6

              Hi,

              as @JKSH said multi-threading programming helps only if your algorithm can be parallelized.
              Keep in mind that if you use multiple threads you MUST synchronize the access to shared data so, sometimes, make no-sense use threads instead of working with a single thread and asyncrhonous mode

              Once your problem is solved don't forget to:

              • Mark the thread as SOLVED using the Topic Tool menu
              • Vote up the answer(s) that helped you to solve the issue

              You can embed images using (http://imgur.com/) or (http://postimage.org/)

              M 1 Reply Last reply
              0
              • M mcosta

                Hi,

                as @JKSH said multi-threading programming helps only if your algorithm can be parallelized.
                Keep in mind that if you use multiple threads you MUST synchronize the access to shared data so, sometimes, make no-sense use threads instead of working with a single thread and asyncrhonous mode

                M Offline
                M Offline
                Meyer Sound
                wrote on last edited by
                #7

                @mcosta in response to 'MUST synchronize the access to shared data', this is not the only method. There is the 'lock free queue' concept, but as this can be troublesome, and usually only considered as an optimization. I see it coming up in the world of audio plugin development, but I'm sure there are other performance bound contexts.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mcosta
                  wrote on last edited by mcosta
                  #8

                  @Meyer-Sound You're right. sometimes synchronization is not the only way.

                  BTW my concept was that multi-thread programming is NOT the best solution to solve every problem.

                  Keep in mind that creating sub-process or threads consumes resources and sometimes this is a problem.

                  In the original example from @Exotic_Devel (DB connections for simple sales and purchases) you can easly manage all the work with the standard Qt asynchronous mode

                  Once your problem is solved don't forget to:

                  • Mark the thread as SOLVED using the Topic Tool menu
                  • Vote up the answer(s) that helped you to solve the issue

                  You can embed images using (http://imgur.com/) or (http://postimage.org/)

                  1 Reply Last reply
                  1
                  • S Offline
                    S Offline
                    stereomatchingkiss
                    wrote on last edited by
                    #9

                    The other example is when you are trying to rename a lot of files, since I/O is very very slow, you would not like this kind of operations to "freeze" your UI. To give the users a feeling that your UI still "alive", you can create a thread to rename the files, and update the QProgressBar.

                    The chapter 8 of the book "advanced Qt programming", will show you how to do it.

                    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