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. QtConcurre​nt programmin​g need help
QtWS25 Last Chance

QtConcurre​nt programmin​g need help

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 2.1k Views
  • 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.
  • appollosputnikA Offline
    appollosputnikA Offline
    appollosputnik
    Banned
    wrote on last edited by
    #1

    I am working on an existing application where threads are submitted concurrently. he is submitting 8 threads together and then he is waiting for all 8 threads to be finished to submit the next 8 threads. In this way after every 8 threads he is waiting and a lot of time is being taken for waiting. Can you me some suggestions how can I skip this waiting after submitting 8 threads to improve speed. Total number of cpu is 8 so he is submitting 8 threads at a time.

    Submitting threads like this

    [code]

    int nCpus = Environment::Get_No_Of_Cpus(); // ==8

    for(z=0; z<21; z++)

    {

    for (int cpuID=0; cpuID<nCpus; cpuID++)

    {

    Th = QtConcurrent::run(this, zLayerFunction,z,...,cpuID);

    Threads.push_back(Th);

    }

    //then he after submitting 8 threads, he is waiting for all 8 threads to be finished to submit the next 8 threads.

    for(int th=0; th<Threads.size(); th++ )

    {

     Threads.at(th).waitForFinished();
    
     Threads.cancel();
    

    }

    Threads.clear();

    z--;

    }

    [/code]

    How can i improve the speed so that it doesn't wait. How can I make it continuous. Any suggestions would be highly appreciated. Thanks Sujan

    1 Reply Last reply
    0
    • 0 Offline
      0 Offline
      02JanDal
      wrote on last edited by
      #2

      You could have something like this:

      @
      listOfThreads threads; //This is a list of all threads that should be run. We will pull out one after the other
      fillListofThreads(); //Here we fill the above list with threads to run
      listOfThreads runningThreads; //This list will hold all threads currently running
      for(int i = 0; i < 8; i++)
      runningThreads.push(threads.pop()); //We take the first 8 threads and put them into the running list...
      foreach(Thread thread, runningThreads)
      thread.start(); //and start them
      while(listOfThreads is not empty and runningThreads is not empty){ // we continue to loop till we have ran all threads
      foreach(Thread thread, runningThreads){
      if(thread.isFinished(){ //is one of the running threads finished?
      runningThreads.remove(thread); //then remove it...
      if(listOfThreads is not empty){ //..and if we still have threads...
      Thread t = listOfThreads.pop(); //..take the next one...
      t.start(); //...start it...
      runningThreads.push(t); //..and put it into the list for running threads
      }
      }
      }
      @

      This should always have 8 threads running.
      (It's only pseudo code, so don't try to compile it directly :))

      Janf

      1 Reply Last reply
      0
      • appollosputnikA Offline
        appollosputnikA Offline
        appollosputnik
        Banned
        wrote on last edited by
        #3

        Thanks JanDal I'll try this out.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          You also asked this question on the interest@qt-project.org mailinglist, right? What in the answers there wasn't enough to warrant a post here as well?

          1 Reply Last reply
          0
          • appollosputnikA Offline
            appollosputnikA Offline
            appollosputnik
            Banned
            wrote on last edited by
            #5

            I asked both the places at the same time.

            1 Reply Last reply
            0
            • appollosputnikA Offline
              appollosputnikA Offline
              appollosputnik
              Banned
              wrote on last edited by
              #6

              how can I keep track of the cpuID on which the thread is running.
              Th=QtConcurrent::run(this,&UnrstParser::zLayer,z,cpuID);

              I want to submit for z=0 to z =31 total 32 threads in sequence. They should be submitted and run in 8 cpus one by one in sequence. Please help.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                You cannot. At least, Qt won't help you with that.

                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