#include <stdarg.h>
+#if defined __linux__ || defined __APPLE__
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif
+
namespace cv
{
#endif
}
+int getNumberOfCPUs(void)
+{
+#if defined WIN32 || defined _WIN32
+ SYSTEM_INFO sysinfo;
+ GetSystemInfo( &sysinfo );
+
+ return (int)sysinfo.dwNumberOfProcessors;
+#elif defined __linux__
+ return (int)sysconf( _SC_NPROCESSORS_ONLN );
+#elif defined __APPLE__
+ int numCPU=0;
+ int mib[4];
+ size_t len = sizeof(numCPU);
+
+ /* set the mib for hw.ncpu */
+ mib[0] = CTL_HW;
+ mib[1] = HW_AVAILCPU; // alternatively, try HW_NCPU;
+
+ /* get the number of CPUs from the system */
+ sysctl(mib, 2, &numCPU, &len, NULL, 0);
+
+ if( numCPU < 1 )
+ {
+ mib[1] = HW_NCPU;
+ sysctl( mib, 2, &numCPU, &len, NULL, 0 );
+
+ if( numCPU < 1 )
+ numCPU = 1;
+ }
+
+ return (int)numCPU;
+#else
+ return 1;
+#endif
+}
string format( const char* fmt, ... )
{