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. QFutureWatcher - timing issue
Forum Updated to NodeBB v4.3 + New Features

QFutureWatcher - timing issue

Scheduled Pinned Locked Moved Unsolved General and Desktop
27 Posts 5 Posters 3.6k 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.
  • A Anonymous_Banned275

    @SGaist said in QFutureWatcher - timing issue:

    @AnneRanch said in QFutureWatcher - timing issue:

    I do not need my coding style criticized by Peanut gallery .

    I'd avoid getting rude.

    @AnneRanch said in QFutureWatcher - timing issue:

    the end is set at "10" - should be 100 , but how - default again ?

    The dialog creation/initialisation is missing from your code snippet.

    @AnneRanch said in QFutureWatcher - timing issue:

    is it even possible to monitor modal dialog for changes?
    perhaps adding my own slots to connect to QProgressDialog ?

    What monitoring do you have in mind ?

    As fae as I can tell the QProgressDialog can only follow what QFutureWatcher SIGNALS value and range is being set.
    Since I opeted to use QProgressDialog dialog,exec() I really have no tracking means to see these.
    Of course I could replace the dialog,exec() with code from documents.

    OK, here is my current code - lock , stock and barrel...

    #include "configuredialog.h"
    #include "ui_configuredialog.h"
    #include "project_commonheader.h"
    
    
    ConfigureDialog::ConfigureDialog(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::ConfigureDialog)
    {
        ui->setupUi(this);
    }
    
    ConfigureDialog::~ConfigureDialog()
    {
        delete ui;
    }
    
    // #of iteration ?? netartion is actaully
    // % step
    // when in 20 it takes steps in 20 %  of total
    // this emulates the time consuming function
    void spin(int& iteration)
    {
    #ifdef PROCESS
    #ifdef TRACE
        // qDebug() << "QDEBUG TRACE ";
        qDebug () << " delay spin pass #" << iteration ;
        qDebug() << "QDEBUG TRACE TASK \n\t\t emulate the time consuming function \n";
        //qDebug() << "QDEBUG TRACE TASK \n\t\t find nearby BT devices \n";
    #ifdef BYPASS
        qDebug() << "file     " << __FILE__;
        qDebug() << "function "<<__FUNCTION__;
        qDebug() << "@line    " << __LINE__;
        qDebug()<<"TEMPORARY EXIT ";
        //exit(99);
    #endif
    #endif
    #endif
        
        int static access;
        if(!access )
        {
    #ifdef PROCESS
            qDebug() << "RUN  START long process ....";
    #endif
            access++;
        }
    #ifdef PROCESS
        qDebug() << "RUN  CONTINUE long process ....";
        
        // actuall steps MN
        // adding elapsed timer
        //    int  Time_Step  = ui->spinBoxIterations_2->text().toInt();
    #endif
        
        QElapsedTimer timer;
        timer.start();
        //slowOperation();  // we want to measure the time of this slowOperation()
        // qDebug() << timer.elapsed();
        //#ifdef BYPASS
        do
        {
            //qDebug() << " do / while timer.elapsed()";
            ;
        }while(timer.elapsed() <= 1000); // MN  1 second Time_Step);
        //#endif
        
    #ifdef BYPASS
        const int work = 10000 * 1000 * 33;      // increased by 1000
        volatile int v = 0;
        // the time emulator
        for (int j = 0; j < work; ++j)
            ++v;                                       // step delay loop MN
    #endif
        qDebug() << "Estimated single iteration delay elapsed time " << timer.elapsed()<< " mS";
        
    #ifdef PROCESS
        qDebug() << "iteration" << iteration << "in thread" << QThread::currentThreadId();
        //slowOperation();  // we want to measure the time of this slowOperation()
        qDebug() << "Estimated single iteration delkay elapsed time " << timer.elapsed()<< " mS";
    #endif
        
        qDebug() << "iteration # " << iteration << "in thread" << QThread::currentThreadId();
        
        
        
        
        
    }
    
    #ifdef BYPASS
    What defaults? The connection, I've shown above and which is used in your example,
    sets up the QProgressDialog according to your QFutureWatchers "watched" work.
    
    progressRangeChanged(int,int) will set the range (0% - 100%) to (0, 10), where 10 = 100%. So each iteration (total of 10) equals 10%.
            Every time one iteration is done (one iteration = count from 0 to 1000*1000*40), progressValueChanged(int) is emitted and sets the corresponding percentage in your QProgressDialog.
    Then, in the end, waitForFinished() is called to "block" the main thread until all future work has been done (and to ensure that you have all results from all threads, when reaching this point in your code).
    
    Probably your QElapsedTimer causes the issue, because it traps your thread in your do - while loop.
    
    #endif
    // initialize time consuming task
    void ConfigureDialog::on_doTaskButton_clicked()
    {
        
        
    # ifdef TRACE
        qDebug() << "QDEBUG TRACE START void TaskDialog::on_doTaskButton_clicked()";
        qDebug() << "file     " << __FILE__;
        qDebug() << "function "<<__FUNCTION__;
        qDebug() << "@line    " << __LINE__;
        //qDebug()<<"TEMPORARY EXIT ";
        //   return;#ifdef BYPASS
    #endif
        // start run overall timer
        QElapsedTimer timer;
        timer.start();
        
        // Prepare the vector.
        // what does it really do ?
        
        int iterations = ui->spinBoxIterations->text().toInt();
        // how may iotera5tions to display 100% competion ??
        // temporary MN
        iterations = 10;
        
        qDebug()  << " Setup # of iterations = toatal delay " << iterations  << " seconds";
        
    #ifdef PROCESS
        qDebug()<<" # of iterations ?? " << iterations ; // vector.append(i) LOOP ";
        // return;
        qDebug() << "Estimated elapsed time " << timer.elapsed()<< " mS";
        // dynamic array # one for each iteration
        // how often to update progress dialog
    #endif
        qDebug()  << " Setup # of iterations as vector array ";
        QVector<int> vector;
        for (int i = 0; i < iterations; ++i)
        {
    #ifdef PROCESS
            //qDebug()<<" interations loop ?? index " << i;
            qDebug()<<" vector.append(i) index " << i; // LOOP ";
            // another delay "iterations
            //qDebug()<<" another delay iterations (?) ";
    #endif
            vector.append(i);
        }
        
        
    #ifdef BYPASS
        QLabel *label = new QLabel;
        QScrollBar *scrollBar = new QScrollBar;
        QObject::connect(scrollBar, SIGNAL(valueChanged(int)),
                         label,  SLOT(setNum(int)));
    #endif
        
        
        // return;
        // Create a progress dialog. implements iteration
        // shows progress ion %
        // BUG doe not finish 100%
        
        qDebug()<<" Setup Create a QProgressDialog dialog - set paramaters ";
        // this is a default QProgressDialog constructor
        //QProgressDialog dialog;
        //    	QProgressDialog(const QString & labelText,
        //    const QString & cancelButtonText, int minimum, int maximum,
        //            QWidget * parent = 0, Qt::WindowFlags f = 0)
        QProgressDialog dialog ( "TEST window title   ",
                                 " BUTTON text", 0, iterations ,0 ,0);
        //BUG  did not set to TEST window title  here
        // dialog.setWindowModality(Qt::WindowModal);
        
        //     dialog.labelText(" what is label ?" ); no matching function ??
        dialog.setWindowTitle("TEST window title  ");
        
        dialog.setFixedWidth(500);                    //W.setWindowTitle("TEST window title  ");
        
        // set defaulrs  of what ???
        //    dialog.setMaximum(100);
        //    dialog.setRange(10, 1000 );
        
        //    If set to 0, the dialog is always shown as soon as any progress is set.
        //    The default is 4000 milliseconds.
        //    int	minimumDuration() const
        //    void	setMinimumDuration(int ms)
        
        dialog.setMinimumDuration(0);
        
        // single shot label only
        //This is done querying the number of processor cores
        dialog.setLabelText(QString("Progressing using %1 thread(s)...\nTODO Elapsed time %2  [mS] ")
                            .arg(QThread::idealThreadCount()).arg(timer.elapsed()));
        
        // Create a QFutureWatcher and connect signals and slots.
        qDebug()<<" Setup Create a QFutureWatcher";
        QFutureWatcher<void> futureWatcher;
        
        qDebug()<<" setup futureWatcher and dialog connect SIGNAL  SLOT ";
        // # of iterations ?? " << iterations ; // vector.append(i) LOOP ";
        
        qDebug()<<" setup future WatcherSIGNAL(finished()";
        // Resets the progress dialog. The progress dialog becomes hidden if autoClose() is true.
        //QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset())); // reset to what ??
        
        
        qDebug()<<" setup dialog, SIGNAL(canceled()";
        //QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel())); // TOK
        
        // how to emulate these ??
        QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int,int)), &dialog, SLOT(setRange(int,int)));
        QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int)));
        
        // Start the computation.
        qDebug()<<" Start the computation - ";
        qDebug()<< "apply delay function spin to each vector";
        
        futureWatcher.setFuture(QtConcurrent::map(vector, spin));
        
        //  futureWatcher.setFuture();
        
        // Display the dialog and start the event loop.
        qDebug()<<" RUN dialog.exec() Display the dialog and start the dialog event loop";
        
        //   dialog.setMaximum(50);
        // dialog.setRange(10, 50 );
        
        qDebug()<<" START dialog.exec() " ; // ? << dialog.setRange(10,30);
        // progress dialog event loop
        //dialog.setAutoClose(false); // test do not close disklog when finished
        // show % of completion in progress bar
        // timing loop runs thru # of iterations
        // show / run modal dialog
        // NOTE perror is phoney
        
        // test real duration of dialog here
        QElapsedTimer timer_wait;
        timer_wait.start();
        //     futureWatcher.progressValue()
        qDebug()<<"futureWatcher.progressValue() " << futureWatcher.progressValue();
        
        dialog.exec(); // run modal dialog 
        
        qDebug()<<"futureWatcher.progressValue() " << futureWatcher.progressValue();
        
        
        //qDebug()<<" START Display current range " ; // ? << dialog.setRange(10,30);
    #ifdef BYPASS
        if( dialog.exec())
            \
        {
            perror("Accepted = 1 - sucess ");
        }
        else
        {
            perror("??  Accepted  != 1  say what ?? ");
        }
        ; // timing loop runs thru # of iterations
    #endif
        qDebug()<<" END dialog.exec() "<< timer_wait.elapsed()<< " mS";
        //   qDebug() << "test real duration of dialog here " << timer_wait.elapsed()<< " mS";
        
        return;
        
        qDebug() << "Completed END FULL Estimated elapsed time " << timer.elapsed()<< " mS";
        
        // show last iteration result %
        qDebug()<<"last iteration resul t %  "<< iterations;
        qDebug()<<" END  Display current range ?? " ; // ? << dialog.setRange(10,30);
        // qDebug()<<" futureWatcher.waitForFinished()";
        // when setAUtoCLose is true   defualkt no need to wait for finshed ??
        // test wait time if any
        
        // this makes no snese since connect(&futureWatcher, SIGNAL(finished())
        // runs &dialog, SLOT(reset())
        
    #ifdef PROCESS
        QElapsedTimer timer_wait;
        timer_wait.start();
        futureWatcher.waitForFinished();
        qDebug() << "test wait futureWatcher.waitForFinished()  time if any " << timer_wait.elapsed()<< " mS";
        
        // Query the future to check if was canceled.
        qDebug() << "DONE   (was) Canceled?" << futureWatcher.future().isCanceled();
    #endif
        
    # ifdef TRACE
        qDebug() << "QDEBUG TRACE END void TaskDialog::on_doTaskButton_clicked()";
        qDebug() << "file     " << __FILE__;
        qDebug() << "function "<<__FUNCTION__;
        qDebug() << "@line    " << __LINE__;
        //qDebug()<<"TEMPORARY EXIT ";
        //   return;#ifdef BYPASS
    #endif
        
    }
    
    
    #ifdef BYPASS
    
    	QFutureWatcher
    #ifdef BYPASS
    
    \temoprary bypaSS POROIGNAL
     
     
    #include "taskdialog.h"
    #include "ui_taskdialog.h"
    #include <QtConcurrent>
    #include <QProgressDialog>
    #include <qtconcurrentmap.h>
     
     TaskDialog::TaskDialog(QWidget *parent) :
         QDialog(parent),
         ui(new Ui::TaskDialog)
     {
         ui->setupUi(this);
     }
     
     TaskDialog::~TaskDialog()
     {
         delete ui;
     }
     
     void spin(int& iteration)
     {
         const int work = 1000 * 1000 * 40;
         volatile int v = 0;
         for (int j = 0; j < work; ++j)
             ++v;
         
         qDebug() << "iteration" << iteration << "in thread" << QThread::currentThreadId();
     }
     
     void TaskDialog::on_doTaskButton_clicked()
     {
         
    # ifdef TRACE
         qDebug() << "QDEBUG TRACE void TaskDialog::on_doTaskButton_clicked()";
         qDebug() << "file     " << __FILE__;
         qDebug() << "function "<<__FUNCTION__;
         qDebug() << "@line    " << __LINE__;
         qDebug()<<"TEMPORARY EXIT ";
         return;#ifdef BYPASS
            #endif
                 
                 
                 // Prepare the vector.
                 int iterations = ui->spinBoxIterations->text().toInt();
         QVector<int> vector;
         for (int i = 0; i < iterations; ++i)
             vector.append(i);
         
         // Create a progress dialog.
         // all defualts ?? no form ??
         
         QProgressDialog dialog;
         
         dialog.setLabelText(QString("Progressing using %1 thread(s)...").arg(QThread::idealThreadCount()));
         
         dialog.setLabelText(QString("Progressing using %1 thread(s)...").arg(QThread::idealThreadCount()));
         
         
         
         
         
         
         // Create a QFutureWatcher and connect signals and slots.
         QFutureWatcher<void> futureWatcher;
         QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset()));
         QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel()));
         QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int,int)), &dialog, SLOT(setRange(int,int)));
         QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int)));
         
         // Start the computation.
         // futureWatcher.setFuture(QtConcurrent::map(vector, spin));
         futureWatcher.setFuture(QtConcurrent::map(vector, spin));
         
         // Display the dialog and start the event loop.
         
         // this may be wrong
         
         
         
         
         
         
         
         
         
         
         
         dialog.exec();
         
         // this may be wrong
         
         
         futureWatcher.waitForFinished();
         
         // Query the future to check if was canceled.
         qDebug() << "Canceled?" << futureWatcher.future().isCanceled();
     }
    #endif
     
     
     
    #endif
     
     
     
    #ifdef BYPASS
     // Operation constructor
     Operation::Operation(QObject *parent)
         : QObject(parent), steps(0)
     {
         pd = new QProgressDialog("Operation in progress.", "Cancel", 0, 100);
         connect(pd, SIGNAL(canceled()), this, SLOT(cancel()));
         t = new QTimer(this);
         connect(t, SIGNAL(timeout()), this, SLOT(perform()));
         t->start(0);
     }
     
     void Operation::perform()
     {
         pd->setValue(steps);
         //... perform one percent of the operation
         steps++;
         if (steps > pd->maximum())
             t->stop();
     }
     
     void Operation::cancel()
     {
         t->stop();
         //... cleanup
     }
     
     
    #endif
     
     
    

    And here is my current output

    QDEBUG TRACE START void TaskDialog::on_doTaskButton_clicked()
    file      ../CAT_V1/configuredialog.cpp
    function  on_doTaskButton_clicked
    @line     111
     Setup # of iterations = toatal delay  10  seconds
     Setup # of iterations as vector array 
     Setup Create a QProgressDialog dialog - set paramaters 
     Setup Create a QFutureWatcher
     setup futureWatcher and dialog connect SIGNAL  SLOT 
     setup future WatcherSIGNAL(finished()
     setup dialog, SIGNAL(canceled()
     Start the computation - 
    apply delay function spin to each vector
     RUN dialog.exec() Display the dialog and start the dialog event loop
     START dialog.exec() 
    futureWatcher.progressValue()  0
    Estimated single iteration delay elapsed time  1001  mS
    iteration #  0 in thread 0x7f6db5c91700
    Estimated single iteration delay elapsed time  1001  mS
    iteration #  2 in thread 0x7f6d9e581700
    Estimated single iteration delay elapsed time  1004  mS
    iteration #  1 in thread 0x7f6d9d57f700
    Estimated single iteration delay elapsed time  1001  mS
    iteration #  3 in thread 0x7f6d9dd80700
    Estimated single iteration delay elapsed time  1001  mS
    iteration #  4 in thread 0x7f6db5c91700
    Estimated single iteration delay elapsed time  1001  mS
    iteration #  6 in thread 0x7f6d9d57f700
    Estimated single iteration delay elapsed time  1004  mS
    iteration #  5 in thread 0x7f6d9e581700
    Estimated single iteration delay elapsed time  1001  mS
    iteration #  7 in thread 0x7f6d9dd80700
    Estimated single iteration delay elapsed time  1001  mS
    iteration #  8 in thread 0x7f6db5c91700
    Estimated single iteration delay elapsed time  1001  mS
    iteration #  9 in thread 0x7f6d9d57f700
    futureWatcher.progressValue()  10
     END dialog.exec()  3034  mS
    

    Note the last line - it should be approximately 10 seconds.

    Pl45m4P Offline
    Pl45m4P Offline
    Pl45m4
    wrote on last edited by
    #12

    @AnneRanch said in QFutureWatcher - timing issue:

    Note the last line - it should be approximately 10 seconds.

    Is this your only issue?! Are you aware that QElapsedTimer only counts the seconds from last (re-)start?!
    So if you restart the same timer multiple times, it measures the time from last start to end only.

    Can you confirm that every single task needs about one 1 second?! Or is this output wrong and it only takes 3 secs for all 10 tasks, which should take 10?


    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

    ~E. W. Dijkstra

    A 1 Reply Last reply
    1
    • Pl45m4P Pl45m4

      @AnneRanch said in QFutureWatcher - timing issue:

      Note the last line - it should be approximately 10 seconds.

      Is this your only issue?! Are you aware that QElapsedTimer only counts the seconds from last (re-)start?!
      So if you restart the same timer multiple times, it measures the time from last start to end only.

      Can you confirm that every single task needs about one 1 second?! Or is this output wrong and it only takes 3 secs for all 10 tasks, which should take 10?

      A Offline
      A Offline
      Anonymous_Banned275
      wrote on last edited by
      #13

      @Pl45m4 said in QFutureWatcher - timing issue:

      @AnneRanch said in QFutureWatcher - timing issue:

      Note the last line - it should be approximately 10 seconds.

      Is this your only issue?! ''
      YES

      Are you aware that QElapsedTimer only counts the seconds from last (re-)start?!

      YES

      So if you restart the same timer multiple times, it measures the time from last start to end only.

      Name specific time that is incorrectly restarted that way .

      Can you confirm that every single task needs about one 1 second?!
      YES
      I am after 10 seconds delay, using 10 iterations that = approximately 10 * 1 seconds. The time precision is irrelevant.

      Or is this output wrong and it only takes 3 secs for all 10 tasks, which should take 10?

      YES

      The desired execution of dialog.exec() is 10 seconds - the current execution takes approximately 3 seconds.

      Here is a crazy idea
      If I set the iteration to 50 - the total delay time is approximately 13
      seconds.

      If I set the iteration to 100 - the total delay time is approximately 25 seconds.

      The "spin" delay runs in its own thread - which is not necessary since the delay is cumulative - no need for parallel processing.

      BUT the dialog.exec() "uses" all four CPU cores ( as noted in the progress dialog text ) - hence four threads .
      Thinking up-loud - since each iteration runs in four threads - is the delay really 1 second? Sounds really crazy...
      Keeping in mind that I really do not have means monitoring the dialog.exec()
      iterations.
      Could that be the issue?

      I should be able to track both SIGNALS - I 'll take a look how it can be done.

      kshegunovK 1 Reply Last reply
      0
      • A Anonymous_Banned275

        @Pl45m4 said in QFutureWatcher - timing issue:

        @AnneRanch said in QFutureWatcher - timing issue:

        Note the last line - it should be approximately 10 seconds.

        Is this your only issue?! ''
        YES

        Are you aware that QElapsedTimer only counts the seconds from last (re-)start?!

        YES

        So if you restart the same timer multiple times, it measures the time from last start to end only.

        Name specific time that is incorrectly restarted that way .

        Can you confirm that every single task needs about one 1 second?!
        YES
        I am after 10 seconds delay, using 10 iterations that = approximately 10 * 1 seconds. The time precision is irrelevant.

        Or is this output wrong and it only takes 3 secs for all 10 tasks, which should take 10?

        YES

        The desired execution of dialog.exec() is 10 seconds - the current execution takes approximately 3 seconds.

        Here is a crazy idea
        If I set the iteration to 50 - the total delay time is approximately 13
        seconds.

        If I set the iteration to 100 - the total delay time is approximately 25 seconds.

        The "spin" delay runs in its own thread - which is not necessary since the delay is cumulative - no need for parallel processing.

        BUT the dialog.exec() "uses" all four CPU cores ( as noted in the progress dialog text ) - hence four threads .
        Thinking up-loud - since each iteration runs in four threads - is the delay really 1 second? Sounds really crazy...
        Keeping in mind that I really do not have means monitoring the dialog.exec()
        iterations.
        Could that be the issue?

        I should be able to track both SIGNALS - I 'll take a look how it can be done.

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by
        #14

        @AnneRanch said in QFutureWatcher - timing issue:

        The "spin" delay runs in its own thread - which is not necessary since the delay is cumulative

        In its own threads.

        - no need for parallel processing.

        Then why do you explicitly use parallel processing? ... then wonder why the time is approximately scaled by the number of pooled threads ... this is all very confusing ...

        BUT the dialog.exec() "uses" all four CPU cores ( as noted in the progress dialog text ) - hence four threads .

        QDialog::exec doesn't use any cores at all. Your QtConcurrent::map does.

        Keeping in mind that I really do not have means monitoring the dialog.exec()
        iterations.

        There are no iterations. QDialog::exec waits for an event to appear in the event queue, if there's none it just sleeps until one happens to appear (be it a GUI event or a signal/slot meta-call - a.k.a. queued connection call).

        Read and abide by the Qt Code of Conduct

        A 1 Reply Last reply
        2
        • kshegunovK kshegunov

          @AnneRanch said in QFutureWatcher - timing issue:

          The "spin" delay runs in its own thread - which is not necessary since the delay is cumulative

          In its own threads.

          - no need for parallel processing.

          Then why do you explicitly use parallel processing? ... then wonder why the time is approximately scaled by the number of pooled threads ... this is all very confusing ...

          BUT the dialog.exec() "uses" all four CPU cores ( as noted in the progress dialog text ) - hence four threads .

          QDialog::exec doesn't use any cores at all. Your QtConcurrent::map does.

          Keeping in mind that I really do not have means monitoring the dialog.exec()
          iterations.

          There are no iterations. QDialog::exec waits for an event to appear in the event queue, if there's none it just sleeps until one happens to appear (be it a GUI event or a signal/slot meta-call - a.k.a. queued connection call).

          A Offline
          A Offline
          Anonymous_Banned275
          wrote on last edited by Anonymous_Banned275
          #15

          @kshegunov said in QFutureWatcher - timing issue:

          @AnneRanch said in QFutureWatcher - timing issue:

          The "spin" delay runs in its own thread - which is not necessary since the delay is cumulative

          In its own threads.

          - no need for parallel processing.

          Then why do you explicitly use parallel processing? ... then wonder why the time is approximately scaled by the number of pooled threads ... this is all very confusing ...

          As pointed out many times - I am following a tutorial.
          I have also said that most of the tutorial steps are not commented WHAT they do . Basically blindly following the tutorial - and the result is obvious.
          Confusing to you , frustrating to me.

          BUT the dialog.exec() "uses" all four CPU cores ( as noted in the progress dialog text ) - hence four threads .

          Which does not make sense.

          QDialog::exec doesn't use any cores at all. Your QtConcurrent::map does.

          Keeping in mind that I really do not have means monitoring the dialog.exec()
          iterations.

          I do not like to get sidteracked by niticking on sentic.
          The QProgresDialog ( n tutorial ) outputs

          dialog.setLabelText(QString("Progressing using %1 thread(s)...\nTODO Elapsed time %2  [mS] ")
                              .arg(QThread::idealThreadCount()).arg(timer.elapsed()));
          

          So why should I question WHO is using the threads - dialog or QtConcurrent?

          How does that leads to solution ?
          I am not complaining about your comment, just trying to maintain some priorities in logic to find the problem.

          > There are no iterations. QDialog::exec waits for an event to appear in the event queue, if there's none it just sleeps until one happens to appear (be it a GUI event or a signal/slot meta-call - a.k.a. queued connection call).

          **OK THIS IS VERY GOOD POINT and IMPORTANT,

          My test delay process is initialized by standard button push...
          "" can somebody describe WHAT EVENT actually starts QProgressDialog::exec ?**

          I am under the impression that QProgressDialog constructor does that.
          Am I wrong ?

          And HOW does the delay process continue from starting point ?

          Secondly
          so what are "iterations" for ?
          They are passed to QProgressDialog constructor...

          Challenge to group
          Would somebody some up with old fashioned flow chart to put the process
          from "button pushed" to "delay completed " ?
          My verbal output track sort of does it , but obviously needs better explanations what each step does.

          New crazy thought - the original tutorial code worked (!) but it used default
          constructor - without any parameters passed to the class and without setting any parameters in code - just used all unpublished defaults.
          With one of the defaults , forgot which one, the actual progress bar supposedly should show up AFTER 4 second delay .

          In current failure mode the progress bar shows 10% (immediately) then shows 50% ( after about 3 seconds) - the percentage is exactly "4 seconds " between the updates when iteration is set to 10 !

          kshegunovK 1 Reply Last reply
          0
          • A Anonymous_Banned275

            @kshegunov said in QFutureWatcher - timing issue:

            @AnneRanch said in QFutureWatcher - timing issue:

            The "spin" delay runs in its own thread - which is not necessary since the delay is cumulative

            In its own threads.

            - no need for parallel processing.

            Then why do you explicitly use parallel processing? ... then wonder why the time is approximately scaled by the number of pooled threads ... this is all very confusing ...

            As pointed out many times - I am following a tutorial.
            I have also said that most of the tutorial steps are not commented WHAT they do . Basically blindly following the tutorial - and the result is obvious.
            Confusing to you , frustrating to me.

            BUT the dialog.exec() "uses" all four CPU cores ( as noted in the progress dialog text ) - hence four threads .

            Which does not make sense.

            QDialog::exec doesn't use any cores at all. Your QtConcurrent::map does.

            Keeping in mind that I really do not have means monitoring the dialog.exec()
            iterations.

            I do not like to get sidteracked by niticking on sentic.
            The QProgresDialog ( n tutorial ) outputs

            dialog.setLabelText(QString("Progressing using %1 thread(s)...\nTODO Elapsed time %2  [mS] ")
                                .arg(QThread::idealThreadCount()).arg(timer.elapsed()));
            

            So why should I question WHO is using the threads - dialog or QtConcurrent?

            How does that leads to solution ?
            I am not complaining about your comment, just trying to maintain some priorities in logic to find the problem.

            > There are no iterations. QDialog::exec waits for an event to appear in the event queue, if there's none it just sleeps until one happens to appear (be it a GUI event or a signal/slot meta-call - a.k.a. queued connection call).

            **OK THIS IS VERY GOOD POINT and IMPORTANT,

            My test delay process is initialized by standard button push...
            "" can somebody describe WHAT EVENT actually starts QProgressDialog::exec ?**

            I am under the impression that QProgressDialog constructor does that.
            Am I wrong ?

            And HOW does the delay process continue from starting point ?

            Secondly
            so what are "iterations" for ?
            They are passed to QProgressDialog constructor...

            Challenge to group
            Would somebody some up with old fashioned flow chart to put the process
            from "button pushed" to "delay completed " ?
            My verbal output track sort of does it , but obviously needs better explanations what each step does.

            New crazy thought - the original tutorial code worked (!) but it used default
            constructor - without any parameters passed to the class and without setting any parameters in code - just used all unpublished defaults.
            With one of the defaults , forgot which one, the actual progress bar supposedly should show up AFTER 4 second delay .

            In current failure mode the progress bar shows 10% (immediately) then shows 50% ( after about 3 seconds) - the percentage is exactly "4 seconds " between the updates when iteration is set to 10 !

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #16

            @AnneRanch said in QFutureWatcher - timing issue:

            As pointed out many times - I am following a tutorial.
            I have also said that most of the tutorial steps are not commented WHAT they do . Basically blindly following the tutorial - and the result is obvious.

            Then read in docs what they do so you understand it, at least that's my advice. QtConcurrent::map isn't an alien we need a team of scientists to talk to, right? Just look it up, that's what I do when I follow tutorials.

            Confusing to you , frustrating to me.

            Yes, yes, frustration leads to anger, anger leads to the dark side and all that. Less emotion, more practicality helps, I've found out.

            I do not like to get sidteracked by niticking on sentic.

            Actually you do, you just don't realize it. You have an unknown machine you're trying to figure out, but you claim you're not interested in how the cogs it's made of fit together. Should I mention such an approach is utterly futile?

            The QProgresDialog ( n tutorial ) outputs

            dialog.setLabelText(QString("Progressing using %1 thread(s)...\nTODO Elapsed time %2  [mS] ")
                                .arg(QThread::idealThreadCount()).arg(timer.elapsed()));
            

            So? This is evaluated before the dialog is even shown to the screen and has nothing to do with the dialog itself.

            So why shoudI question WHO is using the threads - dialog or QtConcurren ?

            It should, so you know where the problem lies. If you don't understand where the error is, then you're not going to be able to fix it, ever.

            How does that leads to solution?

            I don't know exactly what kind of solution you expect as I can't seem to fathom the problem. You split and process some vector in several threads, I get that. But I don't get what times and delays and elapsed timers have to do with it ...

            For reference, what's the output of the following snippet:

            QObject::connect(&futureWatcher, &decltype(futureWatcher)::progressRangeChanged, [] (int from, int to) -> void  {
                qDebug() << "Map from " << from << " to " << to;
            });
            QObject::connect(&futureWatcher, &decltype(futureWatcher)::progressValueChanged, [] (int value) -> void  {
                qDebug() << "Map progress: " << value;
            });

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            2
            • A Offline
              A Offline
              Anonymous_Banned275
              wrote on last edited by
              #17

              Assuming the QprogressDialog is advanced / controlled by QFutureWacher SIGNALs of :"value" and "range"

              I have added means of monitoring these signals

               // create test SLOT to monitor progressValueChanged(int)
              

              qDebug() << "create test SLOT to monitor progressValueChanged(int)";
              QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), this, SLOT(on_doTaskButton_2_clicked));
              QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int,int)),this, SLOT(on_doTaskButton_3_clicked)));

              The result output is here

               Start the computation - 
              apply delay function spin to each vector
               RUN dialog.exec() Display the dialog and start the dialog event loop
               START dialog.exec() 
              futureWatcher.progressValue()  0
              QDEBUG TRACE track  SIGNAL SLOT
              file      ../CAT_V1/configuredialog.cpp
              function  on_doTaskButton_2_clicked
              @line     512
               SLOT value access  0
              QDEBUG TRACE track  SIGNAL SLOT
              file      ../CAT_V1/configuredialog.cpp
              function  on_doTaskButton_2_clicked
              @line     512
               SLOT value access  1
              Estimated single iteration delay elapsed time  1001  mS
              iteration #  0 in thread 0x7f380b7fe700
              Estimated single iteration delay elapsed time  1001  mS
              iteration #  1 in thread 0x7f37fbfff700
              QDEBUG TRACE track  SIGNAL SLOT
              file      ../CAT_V1/configuredialog.cpp
              function  on_doTaskButton_2_clicked
              @line     512
               SLOT value access  2
              QDEBUG TRACE track  SIGNAL SLOT
              file      ../CAT_V1/configuredialog.cpp
              function  on_doTaskButton_2_clicked
              @line     512
               SLOT value access  3
              Estimated single iteration delay elapsed time  1001  mS
              iteration #  2 in thread 0x7f3808eea700
              Estimated single iteration delay elapsed time  1008  mS
              iteration #  3 in thread 0x7f37fb7fe700
              QDEBUG TRACE track  SIGNAL SLOT
              file      ../CAT_V1/configuredialog.cpp
              function  on_doTaskButton_2_clicked
              @line     512
               SLOT value access  4
              QDEBUG TRACE track  SIGNAL SLOT
              file      ../CAT_V1/configuredialog.cpp
              function  on_doTaskButton_2_clicked
              @line     512
               SLOT value access  5
              Estimated single iteration delay elapsed time  1001  mS
              iteration #  5 in thread 0x7f37fbfff700
              Estimated single iteration delay elapsed time  1008  mS
              iteration #  4 in thread 0x7f380b7fe700
              QDEBUG TRACE track  SIGNAL SLOT
              file      ../CAT_V1/configuredialog.cpp
              function  on_doTaskButton_2_clicked
              @line     512
               SLOT value access  6
              Estimated single iteration delay elapsed time  1001  mS
              iteration #  6 in thread 0x7f3808eea700
              QDEBUG TRACE track  SIGNAL SLOT
              file      ../CAT_V1/configuredialog.cpp
              function  on_doTaskButton_2_clicked
              @line     512
               SLOT value access  7
              Estimated single iteration delay elapsed time  1001  mS
              iteration #  7 in thread 0x7f37fb7fe700
              Estimated single iteration delay elapsed time  1001  mS
              iteration #  8 in thread 0x7f37fbfff700
              Estimated single iteration delay elapsed time  1001  mS
              iteration #  9 in thread 0x7f380b7fe700
              QDEBUG TRACE track  SIGNAL SLOT
              file      ../CAT_V1/configuredialog.cpp
              function  on_doTaskButton_2_clicked
              @line     512
               SLOT value access  8
              QDEBUG TRACE track  SIGNAL SLOT
              file      ../CAT_V1/configuredialog.cpp
              function  on_doTaskButton_2_clicked
              @line     512
               SLOT value access  9
              QDEBUG TRACE track  SIGNAL SLOT
              file      ../CAT_V1/configuredialog.cpp
              function  on_doTaskButton_2_clicked
              @line     512
               SLOT value access  10
              QDEBUG TRACE track  SIGNAL SLOT
              file      ../CAT_V1/configuredialog.cpp
              function  on_doTaskButton_2_clicked
              @line     512
               SLOT value access  11
              futureWatcher.progressValue()  10
               END dialog.exec()  3030  mS
              

              Conclusion
              the SIGNAL monitoring the value is changed 11 times - pretty much what is expected. I'll add showing the actual "value" at each time int changes - just to further verify it - it should be 10, 20, 30 etc.

              The range does not change and it should not - should remain 0 thru 100.

              kshegunovK 1 Reply Last reply
              0
              • A Anonymous_Banned275

                Assuming the QprogressDialog is advanced / controlled by QFutureWacher SIGNALs of :"value" and "range"

                I have added means of monitoring these signals

                 // create test SLOT to monitor progressValueChanged(int)
                

                qDebug() << "create test SLOT to monitor progressValueChanged(int)";
                QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), this, SLOT(on_doTaskButton_2_clicked));
                QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int,int)),this, SLOT(on_doTaskButton_3_clicked)));

                The result output is here

                 Start the computation - 
                apply delay function spin to each vector
                 RUN dialog.exec() Display the dialog and start the dialog event loop
                 START dialog.exec() 
                futureWatcher.progressValue()  0
                QDEBUG TRACE track  SIGNAL SLOT
                file      ../CAT_V1/configuredialog.cpp
                function  on_doTaskButton_2_clicked
                @line     512
                 SLOT value access  0
                QDEBUG TRACE track  SIGNAL SLOT
                file      ../CAT_V1/configuredialog.cpp
                function  on_doTaskButton_2_clicked
                @line     512
                 SLOT value access  1
                Estimated single iteration delay elapsed time  1001  mS
                iteration #  0 in thread 0x7f380b7fe700
                Estimated single iteration delay elapsed time  1001  mS
                iteration #  1 in thread 0x7f37fbfff700
                QDEBUG TRACE track  SIGNAL SLOT
                file      ../CAT_V1/configuredialog.cpp
                function  on_doTaskButton_2_clicked
                @line     512
                 SLOT value access  2
                QDEBUG TRACE track  SIGNAL SLOT
                file      ../CAT_V1/configuredialog.cpp
                function  on_doTaskButton_2_clicked
                @line     512
                 SLOT value access  3
                Estimated single iteration delay elapsed time  1001  mS
                iteration #  2 in thread 0x7f3808eea700
                Estimated single iteration delay elapsed time  1008  mS
                iteration #  3 in thread 0x7f37fb7fe700
                QDEBUG TRACE track  SIGNAL SLOT
                file      ../CAT_V1/configuredialog.cpp
                function  on_doTaskButton_2_clicked
                @line     512
                 SLOT value access  4
                QDEBUG TRACE track  SIGNAL SLOT
                file      ../CAT_V1/configuredialog.cpp
                function  on_doTaskButton_2_clicked
                @line     512
                 SLOT value access  5
                Estimated single iteration delay elapsed time  1001  mS
                iteration #  5 in thread 0x7f37fbfff700
                Estimated single iteration delay elapsed time  1008  mS
                iteration #  4 in thread 0x7f380b7fe700
                QDEBUG TRACE track  SIGNAL SLOT
                file      ../CAT_V1/configuredialog.cpp
                function  on_doTaskButton_2_clicked
                @line     512
                 SLOT value access  6
                Estimated single iteration delay elapsed time  1001  mS
                iteration #  6 in thread 0x7f3808eea700
                QDEBUG TRACE track  SIGNAL SLOT
                file      ../CAT_V1/configuredialog.cpp
                function  on_doTaskButton_2_clicked
                @line     512
                 SLOT value access  7
                Estimated single iteration delay elapsed time  1001  mS
                iteration #  7 in thread 0x7f37fb7fe700
                Estimated single iteration delay elapsed time  1001  mS
                iteration #  8 in thread 0x7f37fbfff700
                Estimated single iteration delay elapsed time  1001  mS
                iteration #  9 in thread 0x7f380b7fe700
                QDEBUG TRACE track  SIGNAL SLOT
                file      ../CAT_V1/configuredialog.cpp
                function  on_doTaskButton_2_clicked
                @line     512
                 SLOT value access  8
                QDEBUG TRACE track  SIGNAL SLOT
                file      ../CAT_V1/configuredialog.cpp
                function  on_doTaskButton_2_clicked
                @line     512
                 SLOT value access  9
                QDEBUG TRACE track  SIGNAL SLOT
                file      ../CAT_V1/configuredialog.cpp
                function  on_doTaskButton_2_clicked
                @line     512
                 SLOT value access  10
                QDEBUG TRACE track  SIGNAL SLOT
                file      ../CAT_V1/configuredialog.cpp
                function  on_doTaskButton_2_clicked
                @line     512
                 SLOT value access  11
                futureWatcher.progressValue()  10
                 END dialog.exec()  3030  mS
                

                Conclusion
                the SIGNAL monitoring the value is changed 11 times - pretty much what is expected. I'll add showing the actual "value" at each time int changes - just to further verify it - it should be 10, 20, 30 etc.

                The range does not change and it should not - should remain 0 thru 100.

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #18

                @AnneRanch said in QFutureWatcher - timing issue:

                The range does not change and it should not - should remain 0 thru 100.

                I somehow doubt that assertion, more specifically the numbers you cite, and the conclusions you draw from it. This is why I requested the output from the snippet in my previous post.

                Read and abide by the Qt Code of Conduct

                1 Reply Last reply
                1
                • A Offline
                  A Offline
                  Anonymous_Banned275
                  wrote on last edited by
                  #19

                  "Programs written with QtConcurrent automatically adjust the number of threads used according to the number of processor cores available. "

                  Hence there is no single usage of QFuture vectors - but FOUR of them are used running in four CPU cores at once.
                  Hence QProgressDialog "runs out" the correctly timed iterations FOUR times faster.
                  Thus the total desired time delay is incorrect.

                  Pl45m4P 1 Reply Last reply
                  0
                  • A Anonymous_Banned275

                    "Programs written with QtConcurrent automatically adjust the number of threads used according to the number of processor cores available. "

                    Hence there is no single usage of QFuture vectors - but FOUR of them are used running in four CPU cores at once.
                    Hence QProgressDialog "runs out" the correctly timed iterations FOUR times faster.
                    Thus the total desired time delay is incorrect.

                    Pl45m4P Offline
                    Pl45m4P Offline
                    Pl45m4
                    wrote on last edited by Pl45m4
                    #20

                    @AnneRanch said in QFutureWatcher - timing issue:

                    FOUR times faster.

                    Four threads won't increase the processing time of your whole task by a factor of four (if they share the same data)

                    Might be interesting:
                    (esp. the Concurrent part)

                    • https://www.logicbig.com/quick-info/programming/multi-threading.html

                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    A 1 Reply Last reply
                    1
                    • Pl45m4P Pl45m4

                      @AnneRanch said in QFutureWatcher - timing issue:

                      FOUR times faster.

                      Four threads won't increase the processing time of your whole task by a factor of four (if they share the same data)

                      Might be interesting:
                      (esp. the Concurrent part)

                      • https://www.logicbig.com/quick-info/programming/multi-threading.html
                      A Offline
                      A Offline
                      Anonymous_Banned275
                      wrote on last edited by
                      #21

                      @Pl45m4 said in QFutureWatcher - timing issue:

                      @AnneRanch said in QFutureWatcher - timing issue:

                      FOUR times faster.

                      Four threads won't increase the processing time of your whole task by a factor of four (if they share the same data)

                      Might be interesting:
                      (esp. the Concurrent part)

                      • https://www.logicbig.com/quick-info/programming/multi-threading.html

                      Hence there is no single usage of QFuture vectors - but FOUR of them are used running in four CPU cores at once.
                      Hence QProgressDialog "runs out" the correctly timed iterations FOUR times faster.
                      Thus the total desired time delay is incorrect.

                      SGaistS kshegunovK 2 Replies Last reply
                      0
                      • A Anonymous_Banned275

                        @Pl45m4 said in QFutureWatcher - timing issue:

                        @AnneRanch said in QFutureWatcher - timing issue:

                        FOUR times faster.

                        Four threads won't increase the processing time of your whole task by a factor of four (if they share the same data)

                        Might be interesting:
                        (esp. the Concurrent part)

                        • https://www.logicbig.com/quick-info/programming/multi-threading.html

                        Hence there is no single usage of QFuture vectors - but FOUR of them are used running in four CPU cores at once.
                        Hence QProgressDialog "runs out" the correctly timed iterations FOUR times faster.
                        Thus the total desired time delay is incorrect.

                        SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #22

                        @AnneRanch said in QFutureWatcher - timing issue:

                        Hence there is no single usage of QFuture vectors - but FOUR of them are used running in four CPU cores at once.
                        Hence QProgressDialog "runs out" the correctly timed iterations FOUR times faster.
                        Thus the total desired time delay is incorrect.

                        You are using the wrong assumption that the four cores of your machine are each running exclusively one of these tasks.

                        They are not. Your processor cores are shared and runs variety of tasks from which your application and its threads.

                        Just take a look at your platform system analyser. You'll see that there's a lot happening under the hood.

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

                        A 1 Reply Last reply
                        2
                        • A Anonymous_Banned275

                          @Pl45m4 said in QFutureWatcher - timing issue:

                          @AnneRanch said in QFutureWatcher - timing issue:

                          FOUR times faster.

                          Four threads won't increase the processing time of your whole task by a factor of four (if they share the same data)

                          Might be interesting:
                          (esp. the Concurrent part)

                          • https://www.logicbig.com/quick-info/programming/multi-threading.html

                          Hence there is no single usage of QFuture vectors - but FOUR of them are used running in four CPU cores at once.
                          Hence QProgressDialog "runs out" the correctly timed iterations FOUR times faster.
                          Thus the total desired time delay is incorrect.

                          kshegunovK Offline
                          kshegunovK Offline
                          kshegunov
                          Moderators
                          wrote on last edited by
                          #23

                          @AnneRanch said in QFutureWatcher - timing issue:

                          Hence there is no single usage of QFuture vectors - but FOUR of them are used running in four CPU cores at once.

                          Hm, very weird, if only someone had mentioned this before ...!

                          Hence QProgressDialog "runs out" the correctly timed iterations FOUR times faster.

                          Approximately. Which is the whole point of running anything in parallel.

                          Thus the total desired time delay is incorrect.

                          There's no such thing, I believe I already said that on more than one occasion. GUI programming is event driven, there's no specific time for waiting, or specific order in which things happen; you get events, you respond to events, this is all. If it takes 3 seconds or 5, or 10 seconds or an hour is beside the point. When the event/signal is sent/emitted, then you process it and this is all ...

                          @SGaist said in QFutureWatcher - timing issue:

                          You are using the wrong assumption that the four cores of your machine are each running exclusively one of these tasks.

                          It's possible, albeit rather rare.

                          @Pl45m4 said in QFutureWatcher - timing issue:

                          Four threads won't increase the processing time of your whole task by a factor of four (if they share the same data)

                          Actually, they should. They usually don't as per Amdahl's law. I've a piece I'd written for work that scales almost perfectly with the number of cores, however the task I'd implemented is such that it is extremely parallelizable.

                          Read and abide by the Qt Code of Conduct

                          Pl45m4P 1 Reply Last reply
                          2
                          • kshegunovK kshegunov

                            @AnneRanch said in QFutureWatcher - timing issue:

                            Hence there is no single usage of QFuture vectors - but FOUR of them are used running in four CPU cores at once.

                            Hm, very weird, if only someone had mentioned this before ...!

                            Hence QProgressDialog "runs out" the correctly timed iterations FOUR times faster.

                            Approximately. Which is the whole point of running anything in parallel.

                            Thus the total desired time delay is incorrect.

                            There's no such thing, I believe I already said that on more than one occasion. GUI programming is event driven, there's no specific time for waiting, or specific order in which things happen; you get events, you respond to events, this is all. If it takes 3 seconds or 5, or 10 seconds or an hour is beside the point. When the event/signal is sent/emitted, then you process it and this is all ...

                            @SGaist said in QFutureWatcher - timing issue:

                            You are using the wrong assumption that the four cores of your machine are each running exclusively one of these tasks.

                            It's possible, albeit rather rare.

                            @Pl45m4 said in QFutureWatcher - timing issue:

                            Four threads won't increase the processing time of your whole task by a factor of four (if they share the same data)

                            Actually, they should. They usually don't as per Amdahl's law. I've a piece I'd written for work that scales almost perfectly with the number of cores, however the task I'd implemented is such that it is extremely parallelizable.

                            Pl45m4P Offline
                            Pl45m4P Offline
                            Pl45m4
                            wrote on last edited by
                            #24

                            @kshegunov said in QFutureWatcher - timing issue:

                            Actually, they should. They usually don't as per Amdahl's law. I've a piece I'd written for work that scales almost perfectly with the number of cores, however the task I'd implemented is such that it is extremely parallelizable.

                            If you use threads on all your processor cores, at least some of them have other tasks to do (OS background services etc.), so you will always lose some msec to a few secs or am I wrong?


                            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                            ~E. W. Dijkstra

                            kshegunovK 1 Reply Last reply
                            0
                            • SGaistS SGaist

                              @AnneRanch said in QFutureWatcher - timing issue:

                              Hence there is no single usage of QFuture vectors - but FOUR of them are used running in four CPU cores at once.
                              Hence QProgressDialog "runs out" the correctly timed iterations FOUR times faster.
                              Thus the total desired time delay is incorrect.

                              You are using the wrong assumption that the four cores of your machine are each running exclusively one of these tasks.

                              They are not. Your processor cores are shared and runs variety of tasks from which your application and its threads.

                              Just take a look at your platform system analyser. You'll see that there's a lot happening under the hood.

                              A Offline
                              A Offline
                              Anonymous_Banned275
                              wrote on last edited by
                              #25

                              @SGaist said in QFutureWatcher - timing issue:

                              @AnneRanch said in QFutureWatcher - timing issue:

                              Hence there is no single usage of QFuture vectors - but FOUR of them are used running in four CPU cores at once.
                              Hence QProgressDialog "runs out" the correctly timed iterations FOUR times faster.
                              Thus the total desired time delay is incorrect.

                              You are using the wrong assumption that the four cores of your machine are each running exclusively one of these tasks.

                              They are not. Your processor cores are shared and runs variety of tasks from which your application and its threads.

                              Just take a look at your platform system analyser. You'll see that there's a lot happening under the hood.

                              My "assumption " is based on debug output which outputs 4 calls to "spin" in one shot. Then it pauses (1second) and does another 4 calls , pauses and output 2 calls - thus exhausting the 10 size vector array , set for 1 second each, in 3 seconds.
                              I could add another emit SIGNAL at 1 second intervals and output debug time marks at each second, but I do not need any further proves for myself.

                              BTW - recall my remark about Peanut gallery ?
                              From start I was after to find out why the OVERALL timing discrepancy and now I am getting all kinds of "advises" . For example - why I cannot have precision in mS . I do not need "precision". But that seem to be trend in some discussions - sidetrack to irrelevant issue instead of staying on main task.
                              (And you call my opinion rude? Yes, I am being rude because my only defense is to ignore these superficial and sometime repetitious posts. What else can I do ?)
                              Posters have "right" to opinions, but I am " being rude" when I state mine in my language style. I am no longer referring to your remark in this post - this is my general feeling about how it works 'lopsided" in this forum.
                              As long as I agree with stated opinion it is fine, if not then IBTL ...

                              .

                              1 Reply Last reply
                              0
                              • Pl45m4P Pl45m4

                                @kshegunov said in QFutureWatcher - timing issue:

                                Actually, they should. They usually don't as per Amdahl's law. I've a piece I'd written for work that scales almost perfectly with the number of cores, however the task I'd implemented is such that it is extremely parallelizable.

                                If you use threads on all your processor cores, at least some of them have other tasks to do (OS background services etc.), so you will always lose some msec to a few secs or am I wrong?

                                kshegunovK Offline
                                kshegunovK Offline
                                kshegunov
                                Moderators
                                wrote on last edited by kshegunov
                                #26

                                @Pl45m4 said in QFutureWatcher - timing issue:

                                If you use threads on all your processor cores, at least some of them have other tasks to do (OS background services etc.), so you will always lose some msec to a few secs or am I wrong?

                                Sure, the quantity of such overhead varies depending on the setup/usage, though. In the specific case I was mentioning, the piece of code was run on a cluster, specifically for the purposes of numbercrunching, so there's only the bare minimum of cpu time consumers. Also notably, it depends heavily on the problem itself. Some problems lend themselves well to computing in parallel, while others require you to have either memory fences, or serializations that kill the "ideal" scalability.

                                @AnneRanch said in QFutureWatcher - timing issue:

                                I could add another emit SIGNAL at 1 second intervals and output debug time marks at each second, but I do not need any further proves for myself.

                                Proofs of? That QtConcurrent::map does exactly what's documented?

                                Posters have "right" to opinions, but I am " being rude" when I state mine in my language style. I am no longer referring to your remark in this post - this is my general feeling about how it works 'lopsided" in this forum.
                                As long as I agree with stated opinion it is fine, if not then IBTL ...

                                Everybody has a right to an opinion, this doesn't mean others are obliged to respect said opinion just because it is (i.e. exists), though. And just to add some context, opinions are opinions, but a statement of fact isn't an opinion; things work in a specific way regardless of your opinion, or mine.

                                As a physicist I'd allow myself the brazenness to give you some food for thought (an observation if you will) - you seem to be one of these people that believe that the universe should conform to their expectations, and if it doesn't then it is wrong. However, the real world doesn't operate like this and you'd be doing yourself a favor to cure yourself of such aspirations; you'd have a much more productive and happier time.

                                Read and abide by the Qt Code of Conduct

                                1 Reply Last reply
                                3
                                • A Offline
                                  A Offline
                                  Anonymous_Banned275
                                  wrote on last edited by
                                  #27

                                  SUCCESS !

                                  Here is the tail of current debug output.
                                  Works as expected , but needs some time tweaking.
                                  The artificial 1 second "progress ticks" are done in about 7 seconds , while the real time consuming HCI scanner takes about 10 seconds to complete .

                                  In closing I would like to thank to all who help by "holding my hand " and hugely contributed to success.

                                  THANKS

                                   SLOT value access #  17
                                  futureWatcher.progressValue()  20
                                   END dialog.exec()  7037  mS
                                  TODO // set total delay to configuration dialog 
                                  QDEBUG TRACE END of  time consuming task
                                  file      ../CAT_V1/configuredialog.cpp
                                  function  on_doTaskButton_clicked
                                  @line     408
                                  end timer TODO  
                                  elapsed timer TODO  
                                  success #num_res   2
                                  success inquiry_info TODO   2
                                  Elapsed real time  10238 [mS] 
                                   success nearby BT device  B8:27:EB:11:3F:82  ARM
                                  success nearby BT device  00:15:83:15:A2:CB  d-SATA #1
                                  code_text
                                  
                                  1 Reply Last reply
                                  1

                                  • Login

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