In the program I'm working on, I want the user to be able to input the number of processing threads that their processor has so that the program can divide the workload (it's doing general calculations) between the number of threads the user's computer has.
Alternatively, is there a way that you can get the program to detect the system configuration to get the number of threads without asking the user? This would be preferable, but I don't know if there is a way to do this.
Here is the only thing I've been able to think of. I know that it is completely incorrect, and that you can't name a thread that way, but I'm a beginner (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 isn't sure what I'm saying, I'm trying to create the number of threads that the computer has, aka the number of cores, or, if it's using Intel's HyperThreading, twice the number of cores. You can have more threads than the system is capable of executing at once, but I'm trying to do the most efficient thing and divide the total number of calculations into the number of threads that the system is capable of executing simultaneously. I do not know how to let the user define the number of threads and then create that number of threads (or let the program determine the number of threads the system has and then create that number).