Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <shogun/base/Parallel.h>
00012
00013 #if defined(LINUX) && defined(_SC_NPROCESSORS_ONLN)
00014 #include <unistd.h>
00015 #elif defined(DARWIN)
00016 #include <sys/types.h>
00017 #include <sys/sysctl.h>
00018 #endif
00019
00020
00021 using namespace shogun;
00022
00023 Parallel::Parallel() : refcount(0), num_threads(1)
00024 {
00025 }
00026
00027 Parallel::Parallel(const Parallel& orig) : refcount(0)
00028 {
00029 num_threads=orig.get_num_threads();
00030 }
00031
00032 Parallel::~Parallel()
00033 {
00034 }
00035
00036 int32_t Parallel::get_num_cpus() const
00037 {
00038 #if defined(LINUX) && defined(_SC_NPROCESSORS_ONLN)
00039 return sysconf( _SC_NPROCESSORS_ONLN );
00040 #elif defined(DARWIN)
00041 int num;
00042 size_t size=sizeof(num);
00043 if (!sysctlbyname("hw.ncpu", &num, &size, NULL, 0))
00044 return num;
00045 #endif
00046 return 1;
00047 }