aTm
aTm

Reputation: 79

parallel task in tbb

I have the following function that I want to run as parallel tasks:

void WuManberFinder::find() 

so I wrote the following:

void WuManberFinder::Parallel_find()
{

 tbb::task_group g;

 for(auto i = 0; i != tbb::tbb_thread::hardware_concurrency(); ++i) 
 {
  g.run(find);
 }

   g.wait();

 }

but it gives me the following errors:

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>&)

Here is the serial code (not complete yet):

 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
     }

I know this might seem weird, but the main idea is I want multiple tasks of this type to traverse a string. The shared variable is pos. Could you give me a hint?

Upvotes: 0

Views: 1181

Answers (2)

timday
timday

Reputation: 24892

If you want to use TBB to parallelise a search, I'd suggest basing your approach on the example code for a parallel find (section 3.3.1 of the TBB tutorial) implemented using TBB's parallel_reduce. With all the mention of locks and critical sections in your posted code, you're really failing to exploit the high level TBB features which make it worth using.

Upvotes: 3

ronag
ronag

Reputation: 51255

I don't think what you are doing is a good idea, though I can't explain better without knowing what find is supposed to do. To get that code working you need to do something like:

g.run(std::bind(&WuManberFinder::find, this));

Upvotes: 3

Related Questions