/* Linux */ #include <sched.h> int sched_getaffinity(pid_t pid, unsigned int cpusetsize, cpu_set_t *mask);
static inline int num_processors() { unsigned int bit; int np; cpu_set_t aff; memset(&aff, 0, sizeof(aff) ); sched_getaffinity(0, sizeof(aff), &aff ); for(np = 0, bit = 0; bit < 8*sizeof(aff); bit++) np += (((char *)&aff)[bit / 8] >> (bit % 8)) & 1; return np; } /* Mac OS X */ #include <sys/types.h> #include <sys/sysctl.h> static inline int num_processors() { int np = 1; size_t length = sizeof( np ); sysctlbyname("hw.ncpu", &np, &length, NULL, 0); return np; } /* Windows NT */ #include <windows.h> static inline int num_processors() { SYSTEM_INFO info; GetSystemInfo(&info); return info.dwNumberOfProcessors; } --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---