Skip to content

Commit

Permalink
don't call library function in header file Parallel.h -> move it to .cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Soeren Sonnenburg committed Aug 20, 2011
1 parent a7f397a commit e8bff92
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
21 changes: 21 additions & 0 deletions src/shogun/base/Parallel.cpp
Expand Up @@ -10,6 +10,14 @@

#include <shogun/base/Parallel.h>

#if defined(LINUX) && defined(_SC_NPROCESSORS_ONLN)
#include <unistd.h>
#elif defined(DARWIN)
#include <sys/types.h>
#include <sys/sysctl.h>
#endif


using namespace shogun;

Parallel::Parallel() : refcount(0), num_threads(1)
Expand All @@ -24,3 +32,16 @@ Parallel::Parallel(const Parallel& orig) : refcount(0)
Parallel::~Parallel()
{
}

int32_t Parallel::get_num_cpus() const
{
#if defined(LINUX) && defined(_SC_NPROCESSORS_ONLN)
return sysconf( _SC_NPROCESSORS_ONLN );
#elif defined(DARWIN)
int num; /* for calling external lib */
size_t size=sizeof(num);
if (!sysctlbyname("hw.ncpu", &num, &size, NULL, 0))
return num;
#endif
return 1;
}
20 changes: 1 addition & 19 deletions src/shogun/base/Parallel.h
Expand Up @@ -15,13 +15,6 @@
#include <shogun/lib/config.h>
#include <shogun/io/SGIO.h>

#if defined(LINUX) && defined(_SC_NPROCESSORS_ONLN)
#include <unistd.h>
#elif defined(DARWIN)
#include <sys/types.h>
#include <sys/sysctl.h>
#endif

#ifdef HAVE_PTHREAD
#ifdef _POSIX_SPIN_LOCKS
#define PTHREAD_LOCK_T pthread_spinlock_t
Expand Down Expand Up @@ -61,18 +54,7 @@ class Parallel
/** get num of cpus
* @return number of CPUs
*/
inline int32_t get_num_cpus() const
{
#if defined(LINUX) && defined(_SC_NPROCESSORS_ONLN)
return sysconf( _SC_NPROCESSORS_ONLN );
#elif defined(DARWIN)
int num; /* for calling external lib */
size_t size=sizeof(num);
if (!sysctlbyname("hw.ncpu", &num, &size, NULL, 0))
return num;
#endif
return 1;
}
int32_t get_num_cpus() const;

/** set number of threads
* @param n number of threads
Expand Down

0 comments on commit e8bff92

Please sign in to comment.