SHOGUN  v2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Parallel.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * Written (W) 1999-2009 Soeren Sonnenburg
8  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
9  */
10 
11 #ifndef PARALLEL_H__
12 #define PARALLEL_H__
13 
14 #include <shogun/lib/config.h>
15 #include <shogun/lib/common.h>
16 #include <shogun/io/SGIO.h>
17 
18 #ifdef HAVE_PTHREAD
19 #ifdef USE_SPINLOCKS
20  #define PTHREAD_LOCK_T pthread_spinlock_t
21  #define PTHREAD_LOCK_INIT(lock) pthread_spin_init(lock, 0)
22  #define PTHREAD_LOCK_DESTROY(lock) pthread_spin_destroy(lock)
23  #define PTHREAD_LOCK(lock) pthread_spin_lock(lock)
24  #define PTHREAD_UNLOCK(lock) pthread_spin_unlock(lock)
25 #else
26  #define PTHREAD_LOCK_T pthread_mutex_t
27  #define PTHREAD_LOCK_INIT(lock) pthread_mutex_init(lock, NULL)
28  #define PTHREAD_LOCK_DESTROY(lock) pthread_mutex_destroy(lock)
29  #define PTHREAD_LOCK(lock) pthread_mutex_lock(lock)
30  #define PTHREAD_UNLOCK(lock) pthread_mutex_unlock(lock)
31 #endif
32 #endif
33 
34 namespace shogun
35 {
42 class Parallel
43 {
44 public:
46  Parallel();
47 
49  Parallel(const Parallel& orig);
50 
52  virtual ~Parallel();
53 
57  int32_t get_num_cpus() const;
58 
62  void set_num_threads(int32_t n);
63 
67  int32_t get_num_threads() const;
68 
72  int32_t ref();
73 
77  int32_t ref_count() const;
78 
82  int32_t unref();
83 
84 private:
86  int32_t refcount;
87 
89  int32_t num_threads;
90 };
91 }
92 #endif

SHOGUN Machine Learning Toolbox - Documentation