Parallelizing my existing code in TBB please help me with this errors

Parallelizing my existing code in TBB please help me with this errors

Hi ,

I am new to TBB and working on parallelizing my existing code.

I could easilt paralleize with OpenMP but we need to check the performance of our code in Both TBB and OpenMP after parallelization hence i tried parallelizing the code but i am getting errors which i am not able to reslove please help kindly help me with these errors.My code is as below just using a parallel for loop and lambda function i ahve all serial , openmp and tbb changes i have made please do look at teh code and tell me what else i shud change for tbb to work.

        case openmp:
        {
            #pragma omp parallel for private (iter, currentDB, db)
            for (iter = 1; iter < numDB; iter++)
            {

                currentDB = this->associateDBs->GetAssociateDB(iter);
                db = this->dbGroup.getDatabase( currentDB );
                GeoRanking::GeoVerifierResultVector  resLocal;
                db->recog( fg, InternalName, resLocal );
                LOG(info,omp_get_thread_num()) << "Thread : "<<"currentDB :" <<currentDB<< "No of Res Matches: "<<resLocal.getNumberOfMatchesFound()<<"Match Names :"<<resLocal.getMatch();
                #pragma omp critical
                res.push_back(resLocal);
            }
        }
        break;
        case serial:
        {
                for (iter = 1; iter < numDB; iter++)
                    {
                        currentDB = this->associateDBs->GetAssociateDB(iter);
                        db = this->dbGroup.getDatabase( currentDB );
                        db->recog( fg, InternalName, res );
                    }
        }

break;
        case tbb:
#ifdef USING_TBB
        {
                    size_t GRAIN_SIZE= 10; //boost::thread::hardware_concurrency();
                 // tbb::blocked_range<size_t> range( 0, numDB, GRAIN_SIZE);
                //  tbb::parallel_for( range, fg, InternalName, res);
            parallel_for( tbb::blocked_range<size_t>(0, numDB,GRAIN_SIZE ),
        [&](const tbb::blocked_range<size_t>& r ) ->void {
                    for(size_t iter = r.begin(); iter != r.end(); iter++ )
                    {
                        std::string currentDB = this->associateDBs->GetAssociateDB(iter);
                        DatabaseAccessor_ptr db = this->dbGroup.getDatabase( currentDB );
                        GeoRanking::GeoVerifierResultVector  resLocal;
                        db->recog( fg, InternalName, resLocal );
                        res.push_back(resLocal);}

            });
            }
#endif
        break;

error i am getting is as below:-

/home/girijag/ripe/src/index/forward_db/ForwardDatabaseAccessor.cpp:410:5: error: no matching function for call to ‘parallel_for(tbb::blocked_range<long unsigned int>, indexing::forward::ForwardDatabaseAccessor::recog(cv::Mat, features::Camera::Type, const string&, GeoRanking::GeoVerifierResultVector&, boost::shared_ptr<features::FeatureGroup>&) const::<lambda(const tbb::blocked_range<long unsigned int>&)>)’
/home/girijag/ripe/src/index/forward_db/ForwardDatabaseAccessor.cpp:410:5: note: candidates are:
/usr/local/include/tbb/parallel_for.h:215:6: note: template<class Index, class Function> void tbb::strict_ppl::parallel_for(Index, Index, Index, const Function&)
/usr/local/include/tbb/parallel_for.h:228:6: note: template<class Index, class Function> void tbb::strict_ppl::parallel_for(Index, Index, const Function&)
/usr/local/include/tbb/parallel_for.h:235:6: note: template<class Index, class Function> void tbb::strict_ppl::parallel_for(Index, Index, Index, const Function&, tbb::task_group_context&)
/usr/local/include/tbb/parallel_for.h:248:6: note: template<class Index, class Function> void tbb::strict_ppl::parallel_for(Index, Index, const Function&, tbb::task_group_context&)
/usr/local/include/tbb/parallel_for.h:204:6: note: template<class Range, class Body> void tbb::parallel_for(const Range&, const Body&, tbb::affinity_partitioner&, tbb::task_group_context&)
/usr/local/include/tbb/parallel_for.h:197:6: note: template<class Range, class Body> void tbb::parallel_for(const Range&, const Body&, const tbb::auto_partitioner&, tbb::task_group_context&)
/usr/local/include/tbb/parallel_for.h:190:6: note: template<class Range, class Body> void tbb::parallel_for(const Range&, const Body&, const tbb::simple_partitioner&, tbb::task_group_context&)
/usr/local/include/tbb/parallel_for.h:182:6: note: template<class Range, class Body> void tbb::parallel_for(const Range&, const Body&, tbb::affinity_partitioner&)
/usr/local/include/tbb/parallel_for.h:175:6: note: template<class Range, class Body> void tbb::parallel_for(const Range&, const Body&, const tbb::auto_partitioner&)
/usr/local/include/tbb/parallel_for.h:168:6: note: template<class Range, class Body> void tbb::parallel_for(const Range&, const Body&, const tbb::simple_partitioner&)
/usr/local/include/tbb/parallel_for.h:161:6: note: template<class Range, class Body> void tbb::parallel_for(const Range&, const Body&)
/home/girijag/ripe/src/index/forward_db/ForwardDatabaseAccessor.cpp: At global scope:
/home/girijag/ripe/src/index/forward_db/ForwardDatabaseAccessor.cpp:464:6: warning: unused parameter ‘abortIndexing’ [-Wunused-parameter]
make[2]: *** [index/forward_db/CMakeFiles/forward_db.dir/ForwardDatabaseAccessor.cpp.o] Error 1
make[1]: *** [index/forward_db/CMakeFiles/forward_db.dir/all] Error 2

error i am getting is as below

4 posts / novo 0
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.

Not being expert on TBB, I'd guess that you didn't include TBB libraries in your link step (which you didn't show), or that the header file doesn't match your library.  Are you using a gcc implementation of TBB?

The experts on TBB are more readily engaged on the specific TBB forum.

Hi yes i have included the TBB header files

#include <tbb/blocked_range.h>
#include <tbb/parallel_for.h>

The parallel_for() overloads are rather strange. The original was with Range and Body. Now there are new ones that take a function object (which can be specified by a lambda), but you can only use them with separate index arguments and an optional step argument, and while they allow simple_partitioner they don't take a grainsize argument (otherwise part of Range).

So, if you agree to trust auto_partitioner, which normally does a good job, replacing "tbb::blocked_range<size_t>(0, numDB,GRAIN_SIZE )" with "0, numDB" and using a function object that takes one index argument should do the trick (not verified).

(Added 2013-09-28) Hmm, I had a look at the code again, and I may have written this before, but shouldn't the end() be hoisted out of the loop in parallel_for_body::operator() for optimisation to be likely? Has anyone timed this? And why pass a non-const my_range directly to my_body::operator() instead of through a cast to const to prevent accidents?

Faça login para deixar um comentário.