www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Parallel : get cpu usage ?

reply "Larry" <deco33 hotmail.fr> writes:
The more I use D, the more I like it.

Is there a way to get cpu usage to dynamically set the parallel 
options ?

E.g : I have a dual core, if cpu usage is superior than x, then 
blah.

It would be interesting to :

- to be able to set the execution logic based on the cpu 
capability
- as a consequence of the latter, setting the nice value of the 
current thread dynamically.
- As a consequence of both : to avoid the cpu to burn.


Conclusion :
So it would be useful to have a "std" way to set the nice of the 
pid, and get the cpu usage and eventually deciding on which core 
-obviously the least busy- the parallel will start on and then, 
eventually, deploy to.

Did I miss a hidden functionality that already does this ?

Thanks
Dec 22 2013
next sibling parent "Joakim" <joakim airpost.net> writes:
On Sunday, 22 December 2013 at 09:04:18 UTC, Larry wrote:
 The more I use D, the more I like it.

 Is there a way to get cpu usage to dynamically set the parallel 
 options ?

 E.g : I have a dual core, if cpu usage is superior than x, then 
 blah.

 It would be interesting to :

 - to be able to set the execution logic based on the cpu 
 capability
 - as a consequence of the latter, setting the nice value of the 
 current thread dynamically.
 - As a consequence of both : to avoid the cpu to burn.


 Conclusion :
 So it would be useful to have a "std" way to set the nice of 
 the pid, and get the cpu usage and eventually deciding on which 
 core -obviously the least busy- the parallel will start on and 
 then, eventually, deploy to.

 Did I miss a hidden functionality that already does this ?

 Thanks
I don't think there is a way to do this in D right now. Can you do it in C? If so, you can always call the necessary functions yourself. For example, phobos calls sysconf on linux to figure out the number of CPUs: https://github.com/D-Programming-Language/phobos/blob/19bed560cd7f85f46fe4c2db787cf44ed6439223/std/parallelism.d#L141 If there are other native APIs to do what you want from C, you can always call them from D too, but I don't believe there is already a std way to do this.
Dec 22 2013
prev sibling parent reply Philippe Sigaud <philippe.sigaud gmail.com> writes:
 Is there a way to get cpu usage to dynamically set the parallel options ?
 Conclusion :
 So it would be useful to have a "std" way to set the nice of the pid, and
 get the cpu usage and eventually deciding on which core -obviously the least
 busy- the parallel will start on and then, eventually, deploy to.

 Did I miss a hidden functionality that already does this ?

 Thanks
Doesn't std.parallelism deal with this, with task, taskPool and parallel foreach?
Dec 22 2013
parent "larry" <deco33 hotmail.fr> writes:
Yes,

The Queue seems to manage that.

I will use Python to check all the processes and see if one is 
going wild to nice it.

Solved I think :)

Thanks
Dec 22 2013