Parallel.cpp

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 1999-2009 Soeren Sonnenburg
00008  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
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; /* for calling external lib */
00042         size_t size=sizeof(num);
00043         if (!sysctlbyname("hw.ncpu", &num, &size, NULL, 0))
00044             return num;
00045 #endif
00046         return 1;
00047 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation