0

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?

Rafał Rawicki
  • 22,324
  • 5
  • 59
  • 79
aTm
  • 79
  • 2
  • 10
  • 1
    I don't think this is what you want to do. Please show us what exactly find does. – ronag Apr 09 '12 at 18:58
  • My suspicions too. Since TBB introduced the explicit threading constructs (in 3.0?), TBB newcomers are drawn to them like moths to a flame rather than figuring out how to work within the task-parallel work-stealing framework. – timday Apr 09 '12 at 19:08

2 Answers2

3

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));
ronag
  • 49,529
  • 25
  • 126
  • 221
3

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.

timday
  • 24,582
  • 12
  • 83
  • 135
  • yeah but I can't partition the string – aTm Apr 09 '12 at 19:39
  • I must search every character as each depends on the previous – aTm Apr 09 '12 at 19:39
  • so what I do is a predict what shifts I could do by activating another tasks that run dependent on a shared pos – aTm Apr 09 '12 at 19:40
  • 1
    OK more complex than I assumed; personally I'd still be looking to make it work within TBB's parallel_do, pipeline or worst case task tree stuff. e.g take a look at the fibonnacci example in 11.3 in the tutorial. If you're using TBB right, you won't need any mention of locks or critical sections in your own code. – timday Apr 09 '12 at 19:49