I am making a simulation based game that does a lot of complicated math calculations. I have all of the math scripts separated from the main scripts, but what I need is a way to allocate a certain amount (a set number in a script preferably) of cpu cores to those scripts math so that the calculations don’t take up all the cores.
It would be nice to have, say 25-50 percent of the cores running the complex math functions, and the rest running everything else. Or in simpler terms, for a 4 core cpu, I would like 1 core to do the function.
If there is a way to make a script that allows this that would be amazing! It would help alot because I could possibly change how many cores are running the complex math during runtime.
And for those who are wondering what type of math functions I am running here is an example:
float elwd = 1/math.tanh(b0 + b1*lwd);
Yes, I am using hyperbolic tangents in my scripts.
Any ideas help! Thanks in advance!
In general i’d say - No this is impossible. Why? Because core allocation is (afaik) done on system level per thread. So your system assignes threads to run on a given core and so on. But even on this level it is hard/impossible to free one core so that only one thread/programm is executed on one core alone. (I tried once to achive this for a flight-controller programm on a raspberri pi 3 - did not work out)
But as it is so often the case, the question here is “Why?”. Why do you need this? What do you hope to achive with this? You only write that you want this so that “The calculations don’t take up all the cores”. But in the end you would not win anything from a different execution distribution on your CPU. All the Tasks still have to be run at some point, just executing them in a different order will not make them take less time. So it might be that this - if you manage to achive it - might even do the opposite and slow your simulation down.
If you provide more background we might give you some better alternatives on how to deal with what your issue is. If performance in general is your problem i’d suggest you take a look at the profiler first and general code optimization. Then if that is exhausted you can also look into the ECS and the Job-System.