[JBR] 9-13-2012 Cribbed from [http://tip.tcl.tk/377%|%TIP 377] and other pages on the interweb. ====== package provide nproc 0.5 critcl::ccode { #ifdef _WIN32 #include #elif MACOS #include #include #else #include #endif } critcl::cproc nproc {} int { #ifdef WIN32 SYSTEM_INFO sysinfo; GetSystemInfo(&sysinfo); return sysinfo.dwNumberOfProcessors; #elif MACOS int nm[2]; size_t len = 4; uint32_t count; nm[0] = CTL_HW; nm[1] = HW_AVAILCPU; sysctl(nm, 2, &count, &len, NULL, 0); if(count < 1) { nm[1] = HW_NCPU; sysctl(nm, 2, &count, &len, NULL, 0); if(count < 1) { count = 1; } } return count; #elif __linux return sysconf(_SC_NPROCESSORS_ONLN); #else return 1; #endif } ====== ---- '''[AK] - 2012-09-13 16:56:13''' See also [http://tcl-hwloc.googlecode.com/%|%tcl-hwloc] which came out of [GSoC Idea: Binding To Hwloc].