| 466 | } |
| 467 | |
| 468 | void run(SparseFlow *flower, int max_iter, int topk) { |
| 469 | for (size_t i = 0; i < threads_; i++) { |
| 470 | contexts_.emplace_back(flower->create_context()); |
| 471 | contexts_[i]->set_topk(topk); |
| 472 | contexts_[i]->set_debug_mode(g_debug_mode); |
| 473 | } |
| 474 | |
| 475 | // Do bench |
| 476 | signal(SIGINT, stop); |
| 477 | bench_result_.mark_start(); |
| 478 | auto start_time = Monotime::MilliSeconds(); |
| 479 | for (size_t i = 0; i < threads_; ++i) { |
| 480 | pool_->execute(this, &SparseBench<T>::start_bench, flower, max_iter, |
| 481 | &STOP_NOW); |
| 482 | } |
| 483 | |
| 484 | while (!pool_->is_finished()) { |
| 485 | this_thread::sleep_for(chrono::milliseconds(1)); |
| 486 | if (Monotime::MilliSeconds() - start_time > bench_secs_ * 1000) { |
| 487 | STOP_NOW = true; |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | pool_->wait_finish(); |
| 492 | |
| 493 | bench_result_.mark_end(); |
| 494 | bench_result_.print(); |
| 495 | } |
| 496 | |
| 497 | private: |
| 498 | void start_bench(SparseFlow *flower, size_t max_iter, const bool *is_stop) { |
nothing calls this directly
no test coverage detected