--- trunk/src/lib/parallel-target/cpu.c 2011/05/16 23:37:52 1232 +++ trunk/src/lib/parallel-target/cpu.c 2011/06/09 23:58:40 1301 @@ -24,82 +24,82 @@ /* Get information from /proc/cpuinfo. The interesting * fields are: * - * processor : # logical processor id - * physical id : # node id - * core id : # core id (per node) - * cpu cores : # number of cores per node + * processor : # logical processor id + * physical id : # node id + * core id : # core id (per node) + * cpu cores : # number of cores per node */ FILE *cpuinfo = fopen("/proc/cpuinfo", "r"); char buf[1024]; if (cpuinfo != NULL) { - int maxProcId = 0, maxNodeId = 0, maxCoreId = 0, nCores = 0; - while (fgets(buf, sizeof(buf), cpuinfo) != 0) { - int tmp; - if (sscanf(buf, "processor : %d", &tmp) == 1) { - maxProcId = (tmp > maxProcId) ? tmp : maxProcId; - } - else if (sscanf(buf, "physical id : %d", &tmp) == 1) { - maxNodeId = (tmp > maxNodeId) ? tmp : maxNodeId; - } - else if (sscanf(buf, "core id : %d", &tmp) == 1) { - maxCoreId = (tmp > maxCoreId) ? tmp : maxCoreId; - } - else if (sscanf(buf, "cpu cores : %d", &tmp) == 1) { - nCores = (tmp > nCores) ? tmp : nCores; - } - } - fclose (cpuinfo); + int maxProcId = 0, maxNodeId = 0, maxCoreId = 0, nCores = 0; + while (fgets(buf, sizeof(buf), cpuinfo) != 0) { + int tmp; + if (sscanf(buf, "processor : %d", &tmp) == 1) { + maxProcId = (tmp > maxProcId) ? tmp : maxProcId; + } + else if (sscanf(buf, "physical id : %d", &tmp) == 1) { + maxNodeId = (tmp > maxNodeId) ? tmp : maxNodeId; + } + else if (sscanf(buf, "core id : %d", &tmp) == 1) { + maxCoreId = (tmp > maxCoreId) ? tmp : maxCoreId; + } + else if (sscanf(buf, "cpu cores : %d", &tmp) == 1) { + nCores = (tmp > nCores) ? tmp : nCores; + } + } + fclose (cpuinfo); #ifdef HAVE_LIBNUMA - info->numHWThreads = info->numHWCores = maxProcId + 1; - info->numHWNodes = numa_max_node()+1; - info->numThdsPerCore = 1; - info->numCoresPerNode = info->numHWThreads / info->numHWNodes; + info->numHWThreads = info->numHWCores = maxProcId + 1; + info->numHWNodes = numa_max_node()+1; + info->numThdsPerCore = 1; + info->numCoresPerNode = info->numHWThreads / info->numHWNodes; #else - info->numHWNodes = maxNodeId + 1; - info->numHWCores = info->numHWNodes * nCores; - info->numHWThreads = maxProcId + 1; - info->numCoresPerNode = nCores; - info->numThdsPerCore = info->numHWThreads / info->numHWCores; + info->numHWNodes = maxNodeId + 1; + info->numHWCores = info->numHWNodes * nCores; + info->numHWThreads = maxProcId + 1; + info->numCoresPerNode = nCores; + info->numThdsPerCore = info->numHWThreads / info->numHWCores; #endif - return true; + return true; } else { - fprintf(stderr, "unable to determine the number of processors\n"); - return false; + fprintf(stderr, "unable to determine the number of processors\n"); + return false; } #elif defined(__APPLE__) - size_t len = sizeof(int); + size_t len = sizeof(int); /* the number of nodes */ if (sysctlbyname("hw.packages", &(info->numHWNodes), &len, 0, 0) < 0) { - if (errno == ENOENT) { - // "hw.packages" is not known - info->numHWNodes = 1; - } - else { - fprintf(stderr, "unable to determine the number of nodes\n"); - return false; - } + if (errno == ENOENT) { + // "hw.packages" is not known + info->numHWNodes = 1; + } + else { + fprintf(stderr, "unable to determine the number of nodes\n"); + return false; + } } /* the number of cores */ if (sysctlbyname("hw.physicalcpu", &(info->numHWCores), &len, 0, 0) < 0) { - fprintf(stderr, "unable to determine the number of physical CPUs\n"); - return false; + fprintf(stderr, "unable to determine the number of physical CPUs\n"); + return false; } /* the number of hardware threads */ if (sysctlbyname("hw.logicalcpu", &(info->numHWThreads), &len, 0, 0) < 0) { - if (errno == ENOENT) { - // "hw.packages" is not known - info->numHWThreads = info->numHWCores; - } - else { - fprintf(stderr, "unable to determine the number of logical CPUs\n"); - return false; - } + if (errno == ENOENT) { + // "hw.packages" is not known + info->numHWThreads = info->numHWCores; + } + else { + fprintf(stderr, "unable to determine the number of logical CPUs\n"); + return false; + } } info->numCoresPerNode = info->numHWCores / info->numHWNodes;
Click to toggle
does not end with </html> tag
does not end with </body> tag
The output has ended thus: return false; + } } info->numCoresPerNode = info->numHWCores / info->numHWNodes;