void operator()(const int threadID) const {
     T elem = T(threadID);
     for (size_t i=0; i<MAX_ITER; ++i) {
         q->push(elem);
         (void) q->try_pop(elem);
     }
 }
 void operator()(const int /*threadID*/) const {
     T elem(my_max), last;
     if (q->try_pop(last)) {
         ++counter;
         while(q->try_pop(elem)) {
             ASSERT(!less_than(last, elem), "FAILED pop/priority test in EmptyBody.");
             last = elem;
             elem = my_max;
             ++counter;
         }
     }
 }
 void operator()(const int threadID) const {
     T elem = T(threadID+1);
     for (size_t i=0; i<MAX_ITER; ++i) {
         push_selector(q, elem, i);
         (void) q->try_pop(elem);
     }
 }
 void operator()(const int threadID) const {
     T elem = my_min + T(threadID);
     for (size_t i=0; i<MAX_ITER; ++i) {
         // do some pushes
         q->push(elem);
         if (elem == my_max) elem = my_min;
         elem = elem + T(nThread);
     }
 }
Пример #5
0
void shortpath_helper() {
    vertex_rec u_rec;
    while (open_set.try_pop(u_rec)) {
        vertex_id u = u_rec.first;
        if (u==dst) continue;
        double f = u_rec.second;
        double old_g_u = 0.0;
        {
            spin_mutex::scoped_lock l(locks[u]);
            if (f > f_distance[u]) continue; // prune search space
            old_g_u = g_distance[u];
        }
        for (size_t i=0; i<edges[u].size(); ++i) {
            vertex_id v = edges[u][i];
            double new_g_v = old_g_u + get_distance(vertices[u], vertices[v]);
            double new_f_v = 0.0;
            // the push flag lets us move some work out of the critical section below
            bool push = false;
            {
                spin_mutex::scoped_lock l(locks[v]);
                if (new_g_v < g_distance[v]) {
                    predecessor[v] = u;
                    g_distance[v] = new_g_v;
                    new_f_v = f_distance[v] = g_distance[v] + get_distance(vertices[v], vertices[dst]);
                    push = true;
                }
            }
            if (push) {
                open_set.push(make_pair(v,new_f_v));
                size_t n_spawn = ++num_spawn;
                if (n_spawn < max_spawn) {
#if __TBB_LAMBDAS_PRESENT    
                    sp_group->run([]{ shortpath_helper(); });
#else
                    sp_group->run( shortpath_helper_functor() );
#endif                
                }
                else --num_spawn;
            }
        }
    }
    --num_spawn;
}
Пример #6
0
void shortpath() {
    g_distance[src] = 0.0; // src's distance from src is zero
    f_distance[src] = get_distance(vertices[src], vertices[dst]); // estimate distance from src to dst
    open_set.push(make_pair(src,f_distance[src])); // push src into open_set
#if __TBB_LAMBDAS_PRESENT    
    sp_group->run([](){ shortpath_helper(); });
#else
    sp_group->run( shortpath_helper_functor() );
#endif
    sp_group->wait();
}