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. Spreading CPU intensive function over multiple cores
Forum Updated to NodeBB v4.3 + New Features

Spreading CPU intensive function over multiple cores

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.2k 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.
  • J Offline
    J Offline
    jh224
    wrote on last edited by
    #1

    I have a CPU intensive function that I have no control over. When it runs, it runs only on one core. I do have it on a separate thread from the main thread. But since I have no control over the function, I can't spread it over more threads to force it to use more cores. Any suggestions on how to spread it across more cores?

    1 Reply Last reply
    0
    • 8 Offline
      8 Offline
      8majkel8
      wrote on last edited by
      #2

      you can slice it by input parameters probably (eq. you can sort one part of array in one thread, second in another and than just merge results). You can introduce dynamic programming to make it more cache friendly.

      but you have to tell more details about this function, what parameter do it take and return. What algorithm does it execute etc.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        davidwriter
        wrote on last edited by
        #3

        By no control I assume you mean that it is a black box which you can only control the inputs and record the outputs. If this is so and if you 1) have the inputs in advance and 2) the values calculated by the function are independent of each other, you could create a N (equal to the number of threads) arrays of the input data, of approximately the same size and run these in separate threads. The data would be written to N different output arrays. If you use a single input and output array you would have to lock and unlock them using mutexes.

        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