Bridge++  Ver. 2.0.2
mult_common_th-inc.h
Go to the documentation of this file.
1 
10 #ifndef QXS_MULT_COMMON_TH_INCLUDED
11 #define QXS_MULT_COMMON_TH_INCLUDED
12 
13 #ifdef USE_BENCHMARK
14 #include <omp.h>
15 #else
17 #endif
18 
19 namespace {
20 //====================================================================
21 // case (a): tasks are equally assgined to all threads
22 
23  inline void set_threadtask(int& ith, int& nth, int& is, int& ns,
24  const int size)
25  {
28 
29  is = size * ith / nth;
30  ns = size * (ith + 1) / nth;
31  }
32 
33 
34 //====================================================================
35 // case (b): tasks are almost assigned to slave threads.
36 
37 /*
38 inline void set_threadtask(int& ith, int& nth, int& is, int& ns,
39  const int size)
40 {
41  nth = ThreadManager::get_num_threads();
42  ith = ThreadManager::get_thread_id();
43 
44  if(nth > 1){
45  int offset = size % (nth-1);
46  int ntask = size/(nth-1);
47  is = offset + ntask * (ith-1);
48  if(ith == 0) is = 0;
49  ns = offset + ntask * ith;
50  }else{
51  is = 0;
52  ns = size;
53  }
54 
55 }
56 */
57 //====================================================================
58 // case (c): tasks are assigned only to slave threads.
59 
60 /*
61 inline void set_threadtask(int& ith, int& nth, int& is, int& ns,
62  const int size)
63 {
64 #ifdef USE_BENCHMARK
65  nth = omp_get_num_threads();
66  ith = omp_get_thread_num();
67 #else
68  nth = ThreadManager::get_num_threads();
69  ith = ThreadManager::get_thread_id();
70 #endif
71 
72  if(nth == 1){
73  is = 0;
74  ns = size;
75  }else{
76  is = size * (ith - 1) / (nth-1);
77  if(ith == 0) is = 0;
78  ns = size * ith / (nth-1);
79  }
80 
81 }
82 */
83  inline void set_threadtask_without_master(int& ith, int& nth, int& is, int& ns,
84  const int size)
85  {
86 #ifdef USE_BENCHMARK
87  nth = omp_get_num_threads();
88  ith = omp_get_thread_num();
89 #else
92 #endif
93 
94  if (nth == 1) {
95  is = 0;
96  ns = size;
97  } else {
98  if (ith == 0) {
99  is = 0;
100  ns = 0;
101  } else {
102  int ith_tmp = ith - 1;
103  int nth_tmp = nth - 1;
104  if (nth_tmp == 1) {
105  is = 0;
106  ns = size;
107  } else {
108  is = size * (ith_tmp - 1) / (nth_tmp - 1);
109  if (ith_tmp == 1) is = 0;
110  ns = size * ith_tmp / (nth_tmp - 1);
111  }
112  }
113  }
114  }
115 
116 
117 //====================================================================
118 } // nameless namespace end
119 
120 #endif
121 //============================================================END=====
ThreadManager::get_num_threads
static int get_num_threads()
returns available number of threads.
Definition: threadManager.cpp:246
threadManager.h
ThreadManager::get_thread_id
static int get_thread_id()
returns thread id.
Definition: threadManager.cpp:253