Add num_cores() stdlib routine. Issue #102.

This commit is contained in:
Matt Pharr
2011-09-28 16:16:58 -07:00
parent aad269fdf4
commit c999c8a237
3 changed files with 39 additions and 0 deletions

View File

@@ -51,6 +51,12 @@
*/
#ifdef _MSC_VER
#include <windows.h>
#else
#include <unistd.h>
#endif // !_MSC_VER
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
@@ -139,3 +145,14 @@ void __do_print(const char *format, const char *types, int width, int mask,
}
fflush(stdout);
}
int __num_cores() {
#ifdef _MSC_VER
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
return sysInfo.dwNumberOfProcessors;
#else
return sysconf(_SC_NPROCESSORS_ONLN);
#endif // !_MSC_VER
}