我有以下要作为并行任务运行的功能:
void WuManberFinder::find()
所以我写了以下内容:
void WuManberFinder::Parallel_find()
{
tbb::task_group g;
for(auto i = 0; i != tbb::tbb_thread::hardware_concurrency(); ++i)
{
g.run(find);
}
g.wait();
}
但它给了我以下错误:
wumanber.cc:139:17: error: no matching function for call to ‘tbb::task_group::run(<unresolved overloaded function type>)’
wumanber.cc:139:17: note: candidates are:
/usr/include/tbb/task_group.h:209:10: note: void tbb::task_group::run(const F&) [with F = void (thru::matching::WuManberFinder::*)()]
/usr/include/tbb/task_group.h:209:10: note: no known conversion for argument 1 from ‘<unresolved overloaded function type>’ to ‘void (thru::matching::WuManberFinder::* const&)()’
/usr/include/tbb/task_group.h:151:10: note: template<class F> void tbb::internal::task_group_base::run(tbb::task_handle<F>&)
这是序列号(尚未完成):
void WuManberFinder::find() {
while(m_pos <= m_text2.size()) {
string bgram = m_text2.substr(m_pos - m_B, m_B);
shift_type::iterator i = m_shift.find(bgram);
if (i == m_shift.end())
{// shared variable lock
m_pos += m_lmin - m_B + 1;
}// unlock
else {
if (i->second == 0) {
vector<size_t>& list = m_hash[bgram];
// Verify all patterns in list against the text.
//shared variable lock
++m_pos;
//unlock
for (size_t j = 0; j < list.size(); ++j) {
string const& str = m_patterns[list[j]];
m_find_pos = m_pos - str.size() - 1;
size_t k = 0;
for (; k < str.size(); ++k)
if (str[k] != m_text2[m_find_pos + k])
break;
if (k == str.size()) {
m_find_pattern_index = list[j];
// cout << "***" << m_patterns[m_find_pattern_index] <<endl;
// return true
// shared variable lock
m_intrusions++;
// unlock
}
}
}
else
{ // access m_pos shared critical section
m_pos += i->second;
} // access m_pos shared critical section
}
}
// return false; nothing found
}
我知道这可能看起来很奇怪,但主要思想是我希望这种类型的多个任务遍历一个字符串。共享变量是pos
。你能给我一个提示吗?