Bridge++  Ver. 2.0.2
mult_common_th-inc.h
Go to the documentation of this file.
1 
10 #ifndef MULT_COMMON_TH_INCLUDED
11 #define MULT_COMMON_TH_INCLUDED
12 
13 #ifdef USE_BENCHMARK
14 #include <omp.h>
15 #endif
16 
17 namespace {
18 //====================================================================
19 // case (a): tasks are equally assgined to all threads
20 
21 /*
22 inline void set_threadtask_mult(int& ith, int& nth, int& is, int& ns,
23  const int size)
24 {
25  nth = ThreadManager::get_num_threads();
26  ith = ThreadManager::get_thread_id();
27 
28  is = size * ith / nth;
29  ns = size * (ith + 1) / nth;
30 
31 }
32 */
33 //====================================================================
34 // case (b): tasks are almost assigned to slave threads.
35 
36 /*
37 inline void set_threadtask_mult(int& ith, int& nth, int& is, int& ns,
38  const int size)
39 {
40  nth = ThreadManager::get_num_threads();
41  ith = ThreadManager::get_thread_id();
42 
43  if(nth > 1){
44  int offset = size % (nth-1);
45  int ntask = size/(nth-1);
46  is = offset + ntask * (ith-1);
47  if(ith == 0) is = 0;
48  ns = offset + ntask * ith;
49  }else{
50  is = 0;
51  ns = size;
52  }
53 
54 }
55 */
56 //====================================================================
57 // case (c): tasks are assigned only to slave threads.
58 
59  inline void set_threadtask_mult(int& ith, int& nth, int& is, int& ns,
60  const int size)
61  {
62 #ifdef USE_BENCHMARK
63  nth = omp_get_num_threads();
64  ith = omp_get_thread_num();
65 #else
68 #endif
69 
70  if (nth == 1) {
71  is = 0;
72  ns = size;
73  } else {
74  is = size * (ith - 1) / (nth - 1);
75  if (ith == 0) is = 0;
76  ns = size * ith / (nth - 1);
77  }
78  }
79 
80 
81 //====================================================================
82 } // nameless namespace end
83 
84 #endif
85 //============================================================END=====
ThreadManager::get_num_threads
static int get_num_threads()
returns available number of threads.
Definition: threadManager.cpp:246
ThreadManager::get_thread_id
static int get_thread_id()
returns thread id.
Definition: threadManager.cpp:253