/* ------------------------------------------------------------------ * Special method for a directory to clean up after itself if it has * spawned any threads. * ------------------------------------------------------------------ */ void handle_directory(params *P, visited_dir *list, char *nextpath, dev_t dev, ino_t ino, char *prevpath, int dir_d) { pthread_t new_thread; dir_info *new_dir_info; visited_dir *parent_dir; parent_dir = list; inc_stat(P, t_dirs, 1); pthread_mutex_lock(&stack_mutex); list = add_visited(list, prevpath, dev, ino); pthread_mutex_unlock(&stack_mutex); pthread_mutex_lock(&stats_mutex); if (!enabled(P, THREAD_LIMIT) || (P->threads_left) > 0) { pthread_mutex_unlock(&stats_mutex); new_dir_info = create_dir_info(P, list, nextpath, dir_d); if (pthread_create(&new_thread, NULL, thread_dir_setup, new_dir_info) == 0) { add_child(parent_dir, new_thread); } else { inc_stat(P, t_threadfails, 1); explore_dir(P, list, nextpath, dir_d); free_dir_info(new_dir_info); } } else { pthread_mutex_unlock(&stats_mutex); inc_stat(P, t_threadskips, 1); explore_dir(P, list, nextpath, dir_d); } }
std::vector<configState*> Astar::run(configState* s, wsState* t){ std::cout << "Initializing Start and Target\n"; target = t; start = s; std::cout << "Target: "; wsstate_tostring(target); std::cout << "Initialize start data structures\n"; /* Runtime checks */ float avg_frontier_pop = 0; int pop_count = 0; float avg_vis_add = 0; int vis_add_count = 0; float avg_expansion = 0; int expansion_count = 0; /* Init */ visData* startv = create_visdata(); startv->current = start; startv->prev = 0; startv->value = heuristic(start); frontier.push(startv); visData* next = 0; wsState* wscurrent = fk(start); while(distance(target, wscurrent) > target_threshold){ clock_t pqstart = clock(); next = frontier.top(); frontier.pop(); float secsElapsed = (float)(clock() - pqstart)/CLOCKS_PER_SEC; avg_frontier_pop += secsElapsed; pop_count++; delete(wscurrent); wscurrent = fk(next->current); if(next != 0){ clock_t visaddstart = clock(); add_visited(next->current, next); secsElapsed= (float)(clock() - visaddstart)/CLOCKS_PER_SEC; avg_vis_add += secsElapsed; vis_add_count ++; clock_t expstart = clock(); expand_frontier(next->current); secsElapsed = (float)(clock() - expstart)/CLOCKS_PER_SEC; avg_expansion += secsElapsed; expansion_count++; } else { std::vector<configState*> path; return path; } } std::cout << "Visited Set: "<< visited_set.size() << '\n'; std::cout << "Queue: "<< frontier.size() << '\n'; std::cout << "Completed Search\n"; std::cout << "Runtimes: \n\n\n\n"; std::cout << "Frontier Popping :" << avg_frontier_pop << '\n'; std::cout << "Expansion: " << avg_expansion << '\n'; std::cout << " Vis Gets: " << get_visdata_time << '\n'; std::cout << " Value Comp Time: " << value_comp_time << '\n'; std::cout << " Frontier Push Time: " << frontier_insert_time << '\n'; std::cout << " Mem_Time: " << mem_time << '\n'; std::cout << " VisAdd :" << avg_vis_add*3 << '\n'; std::cout << "Counts: " << pop_count << '\n'; visData* current = next; std::vector<configState*> path; std::cout << "Backtracing path\n"; while(current != 0){ path.push_back(current->current); if(current -> prev == 0){ current = 0; continue; } current = get_visdata(current->prev); } std::cout << "Back trace completed\n"; return path; }