Parallel : get cpu usage ?
Joakim
joakim at airpost.net
Sun Dec 22 02:25:29 PST 2013
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.
More information about the Digitalmars-d
mailing list