Re: gthread: how many cores do I have?
- From: Ryan Lortie <desrt desrt ca>
- To: Sven Neumann <sven gimp org>
- Cc: gtk-devel-list gnome org
- Subject: Re: gthread: how many cores do I have?
- Date: Thu, 18 Mar 2010 23:56:56 -0500
On Mon, 2010-03-15 at 23:43 +0100, Sven Neumann wrote:
> Feel free to use the implementation in GIMP as a starting point:
> 
>  http://git.gnome.org/browse/gimp/tree/app/base/base-utils.c#n54
See also:
http://qt.gitorious.org/qt/qt/blobs/4.7/src/corelib/thread/qthread_unix.cpp
http://qt.gitorious.org/qt/qt/blobs/4.7/src/corelib/thread/qthread_win.cpp
the QThread::idealThreadCount() function.
On Windows, that's:
    SYSTEM_INFO sysinfo;
    GetSystemInfo(&sysinfo);
    return sysinfo.dwNumberOfProcessors;
MacOS X:
    MPProcessorsScheduled();
HPUX:
    struct pst_dynamic psd;
    if (pstat_getdynamic(&psd, sizeof(psd), 1, 0) == -1) {
        perror("pstat_getdynamic");
        cores = -1;
    } else {
        cores = (int)psd.psd_proc_cnt;
    }
{Free,Net,Open}BSD:
    size_t len = sizeof(cores);
    int mib[2];
    mib[0] = CTL_HW;
    mib[1] = HW_NCPU;
    if (sysctl(mib, 2, &cores, &len, NULL, 0) != 0) {
        perror("sysctl");
        cores = -1;
    }
"integrity" OS, symbian: hard-coded to one core.
VXWorks: a loop to check if CPU #n exists until it fails (see link)
IRIX:
    cores = (int)sysconf(_SC_NPROC_ONLN);
all other Unix (including Linux):
    cores = (int)sysconf(_SC_NPROCESSORS_ONLN);
Cheers
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]