void clever_runner( std::size_t thread_index, std::size_t iteration, atomic_count_t& counter, data_t& data) { fill_data(data.at(thread_index)); if (++counter == data_t::static_size) { compute_send_data(data); ++ iteration; if (iteration == 1000) { // exiting, because 1000 iterations are done tasks_processor::get().stop(); return; } counter = 0; for (std::size_t i = 0; i < data_t::static_size; ++ i) { tasks_processor::get().push_task(boost::bind( clever_runner, i, iteration, boost::ref(counter), boost::ref(data) )); } } }
void construct(point &root, data_t dataset){ if (dataset.size() == 0) return; root = new point_t(); vector< double > buff; for (size_t i = 0; i < dataset.at(0).size(); i++){ buff.push_back(variation(dataset, i)); } size_t split = 0; double min; for (size_t i = 0; i < buff.size(); i++){ if (i == 0){ min = buff.at(i); } else{ if (min < buff.at(i)){ min = buff.at(i); split = i; } } } sort(dataset.begin(), dataset.end(), [split](vec_t a, vec_t b){ return a.at(split) < b.at(split); }); size_t middle = dataset.size() / 2; root->split = split; for (size_t i = 0; i < dataset.at(middle).size(); i++){ root->node.push_back(dataset.at(middle).at(i)); } root->dim = root->node.size(); data_t lDataset, rDataset; for (size_t i = 0; i < middle; i++){ lDataset.push_back(dataset.at(i)); } for (size_t i = middle + 1; i < dataset.size(); i++){ rDataset.push_back(dataset.at(i)); } construct(root->left, lDataset); construct(root->right, rDataset); if (root->left) root->left->parent = root; if (root->right) root->right->parent = root; return; }
void runner(std::size_t thread_index, boost::barrier& data_barrier, data_t& data) { for (std::size_t i = 0; i < 1000; ++ i) { fill_data(data.at(thread_index)); data_barrier.wait(); if (!thread_index) { compute_send_data(data); } data_barrier.wait(); } }