MultiThreader< C > Class Template Reference

#include <kaldi-thread.h>

Collaboration diagram for MultiThreader< C >:

Public Member Functions

 MultiThreader (int32 num_threads, const C &c_in)
 
 ~MultiThreader ()
 

Private Attributes

std::vector< std::thread > threads_
 
std::vector< C > cvec_
 

Detailed Description

template<class C>
class kaldi::MultiThreader< C >

Definition at line 117 of file kaldi-thread.h.

Constructor & Destructor Documentation

◆ MultiThreader()

MultiThreader ( int32  num_threads,
const C &  c_in 
)
inline

Definition at line 119 of file kaldi-thread.h.

References rnnlm::i.

119  :
120  threads_(std::max<int32>(1, num_threads)),
121  cvec_(std::max<int32>(1, num_threads), c_in) {
122  if (num_threads == 0) {
123  // This is a special case with num_threads == 0, which behaves like with
124  // num_threads == 1 but without creating extra threads. This can be
125  // useful in GPU computations where threads cannot be used.
126  cvec_[0].thread_id_ = 0;
127  cvec_[0].num_threads_ = 1;
128  (cvec_[0])();
129  } else {
130  for (int32 i = 0; i < threads_.size(); i++) {
131  cvec_[i].thread_id_ = i;
132  cvec_[i].num_threads_ = threads_.size();
133  threads_[i] = std::thread(std::ref(cvec_[i]));
134  }
135  }
136  }
kaldi::int32 int32
std::vector< C > cvec_
Definition: kaldi-thread.h:144
std::vector< std::thread > threads_
Definition: kaldi-thread.h:143

◆ ~MultiThreader()

~MultiThreader ( )
inline

Definition at line 137 of file kaldi-thread.h.

References rnnlm::i.

137  {
138  for (size_t i = 0; i < threads_.size(); i++)
139  if (threads_[i].joinable())
140  threads_[i].join();
141  }
std::vector< std::thread > threads_
Definition: kaldi-thread.h:143

Member Data Documentation

◆ cvec_

std::vector<C> cvec_
private

Definition at line 144 of file kaldi-thread.h.

◆ threads_

std::vector<std::thread> threads_
private

Definition at line 143 of file kaldi-thread.h.


The documentation for this class was generated from the following file: