Unsolved Why when I use QThread in Qt is slower from a simple Qt main program?
-
@jsulm i have cpu corei5, i want to when main thread is busy, itshould be work(main thread is usded for receiving big data upd socket............),but som times it is not busy,
when data is not received, i only used one core for processing my Qthread, it is slow,i can not use in more optimization way of my cpu cores.......
i lost other core cpu in that time......................- i run RunHardAlgorithm() in a signal udp data received, after that data is buffered in class upd i run RunHardAlgorithm().....................
2)MyComputationThread ,......
i run in a timer ........
3)i measure seconds..................thanks
-
@stackprogramer Sorry I don't understand what you're writing. Sounds like you're doing multi-threading in a wrong way.
You should read https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/ -
@jslum sorry i am in hurry
i saw this links
How To Really, Truly Use QThreads; The Full Explanationhttp://blog.debao.me/2013/08/how-to-use-qthread-in-the-right-way-part-1/
http://www.bogotobogo.com/Qt/Qt5_QThreads_Creating_Threads.php
http://blog.debao.me/2013/08/how-to-use-qthread-in-the-right-way-part-1/
https://github.com/fabienpn/simple-qt-thread-example
https://john.nachtimwald.com/2015/05/02/effective-threading-using-qt/
but my problem has so complication algorithm, i need a effective way. any way thanks very much
-
I think the issue here is not with QThread
@stackprogramer wants his program to use more than 1 CPU core for each thread to make the most out of the available hardware
Mulitthread != Multicore
-
@J.Hilk said in Why when I use QThread in Qt is slower from a simple Qt main program?:
use more than 1 CPU core for each thread
This is not possible. A thread can only run on one CPU at given time. If you want to utilize 4 cores you need at least 4 threads.
-
-
@stackprogramer said in Why when I use QThread in Qt is slower from a simple Qt main program?:
- i run RunHardAlgorithm() in a signal udp data received, after that data is buffered in class upd i run RunHardAlgorithm().....................
2)MyComputationThread ,......
i run in a timer ........
3)i measure seconds..................Sorry, your descriptions are unclear... please post your code.
@stackprogramer said in Why when I use QThread in Qt is slower from a simple Qt main program?:
i think i should switch to multicorre like cuda gpu programming or a same tools.
thread is good but it is not Excellent for my problem.Do you mean you want to do parallel computing? What is the name of your algorithm?
-
You can always break it up "manually"
QList<int> lInt; int cnt = QThread::idealThreadCount(); if(cnt > 1){ int size = lInt.size()/cnt; for(int i = 0; i < cnt; i++){ QList<int> newlInt = lInt.mid(size*i,size); QtConcurrent::run(this, &MyClass::RunHardAlgorithm, newlInt); } }else{ QtConcurrent::run(this, &MyClass::RunHardAlgorithm, lInt); }
-
From what I was able to grasp from your explanation it seems to me you need to parallelize your algorithm rather. However this depends on what your calculation does, and making a sequential computation a parallel one is a big universe; there's no one approach to help with that, and there's no easy fix by just using a class or w/e. As @JKSH said, you need to post your code, so we can examine it and provide a constructive suggestion.
@J.Hilk said in Why when I use QThread in Qt is slower from a simple Qt main program?:
Mulitthread != Multicore
For most cases that's not true. The only distinction between the two can be made if one considers the memory - if it's shared or distributed, and even then the argument is rather weak. @jsulm makes a good point, that a thread can be executed only on a single core and a core can execute a single thread at any one time.
-
@kshegunov said in Why when I use QThread in Qt is slower from a simple Qt main program?:
@J.Hilk said in Why when I use QThread in Qt is slower from a simple Qt main program?:
Mulitthread != Multicore
For most cases that's not true. The only distinction between the two can be made if one considers the memory - if it's shared or distributed, and even then the argument is rather weak.
What I tried to say was, that one does not a necessarily implicate the other.
You can have multiple threads that are handled from a single core.
Also, creating a new thread, its also not automaticaly assured that its handled from a different core as well, I believe that is handled by the OS and the current CPU-load? -
@J.Hilk said in Why when I use QThread in Qt is slower from a simple Qt main program?:
What I tried to say was, that one does not a necessarily implicate the other.
I'm arguing they're one and the same. :)
You can have multiple threads that are handled from a single core
Yes, by means of context switching.
Also, creating a new thread, its also not automaticaly assured that its handled from a different core as well, I believe that is handled by the OS and the current CPU-load?
What core executes what thread at a given time slice is handled by the OS, yes. The actual implementation is in the OS' scheduler.