In the program I'm working on, I want the user to be able to enter the number of processing threads that their processor has, so that the program can share the workload (it performed general calculations) between the number of threads the user computer has.
Alternatively, is there a way that you can force a program to detect system configuration to get the number of threads without asking the user? That would be preferable, but I don't know if there is a way to do this.
Here is the only thing I could think of. I know this is completely untrue, and you cannot name the stream this way, but I am new (still in high school) and I just wanted to include something to show that I'm trying.
for(int i = 0; i < threads; i++) { Thread thread(i) = new Thread(){ public void run() { double endNum = 0; for(double numberRun = 0; numberRun <= calcs/threads; numberRun++){ endNum += (num * 999999999); } System.out.println("Thread " + i + " complete! The numerical result of the calculation is " + endNum); } }; }
Everyone who is not sure what I'm saying, I am trying to create the number of threads that the computer has, for example, the number of cores, or, if it uses Intel HyperThreading, twice as many cores. You may have more threads than the system can do right away, but I'm trying to do the most efficient thing and divide the total number of calculations by the number of threads that the system can perform at one time. I do not know how to let the user determine the number of threads, and then create this number of threads (or let the program determine the number of threads that the system has, and then create this number).
source share