Parallel.h

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 #ifndef PARALLEL_H__
00012 #define PARALLEL_H__
00013 
00014 #include <shogun/lib/config.h>
00015 #include <shogun/lib/common.h>
00016 #include <shogun/io/SGIO.h>
00017 
00018 #ifdef HAVE_PTHREAD
00019 #ifdef USE_SPINLOCKS
00020     #define PTHREAD_LOCK_T pthread_spinlock_t
00021     #define PTHREAD_LOCK_INIT(lock) pthread_spin_init(lock, 0)
00022     #define PTHREAD_LOCK_DESTROY(lock) pthread_spin_destroy(lock)
00023     #define PTHREAD_LOCK(lock) pthread_spin_lock(lock)
00024     #define PTHREAD_UNLOCK(lock) pthread_spin_unlock(lock)
00025 #else
00026     #define PTHREAD_LOCK_T pthread_mutex_t
00027     #define PTHREAD_LOCK_INIT(lock) pthread_mutex_init(lock, NULL)
00028     #define PTHREAD_LOCK_DESTROY(lock) pthread_mutex_destroy(lock)
00029     #define PTHREAD_LOCK(lock) pthread_mutex_lock(lock)
00030     #define PTHREAD_UNLOCK(lock) pthread_mutex_unlock(lock)
00031 #endif
00032 #endif
00033 
00034 namespace shogun
00035 {
00042 class Parallel
00043 {
00044 public:
00046     Parallel();
00047 
00049     Parallel(const Parallel& orig);
00050 
00052     virtual ~Parallel();
00053 
00057     int32_t get_num_cpus() const;
00058 
00062     void set_num_threads(int32_t n);
00063 
00067     int32_t get_num_threads() const;
00068 
00072     int32_t ref();
00073 
00077     int32_t ref_count() const;
00078 
00082     int32_t unref();
00083 
00084 private:
00086     int32_t refcount;
00087 
00089     int32_t num_threads;
00090 };
00091 }
00092 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation