searchTimer.cc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
searchTimer.cc
Go to the documentation of this file.
1 /* hasTimer.cc
2 */
3 #include "osl/search/searchTimer.h"
4 #include "osl/search/usiReporter.h"
5 #include <boost/foreach.hpp>
6 #include <iostream>
7
8 osl::search::SearchTimer::~SearchTimer()
9 {
10 }
11
12 void osl::search::SearchTimer::throwStop()
13 {
14 assert(shared_timer->stop_all);
15 if (shared_timer->stop_reason == SearchTimerCommon::NoMoreMemory)
16 throw NoMoreMemory();
17 throw misc::NoMoreTime();
18 }
19
20 static osl::uint64_t maximum_node_count = 0;
21 static double maximum_memory_use_ratio = 0.0;
22 void osl::search::
23 SearchTimer::testAndUpdateNextTimeTest(uint64_t node_count)
24 {
25 SCOPED_LOCK(lk,shared_timer->mutex);
26 if (shared_timer->stop_all)
27 throwStop();
28 if (shared_timer->next_node_count > node_count)
29 return;
30 const double elapsed = this->elapsed();
31 if (elapsed > shared_timer->assigned.max.toSeconds()
32 || (shared_timer->stable && elapsed > shared_timer->assigned.standard.toSeconds())
33 || node_count > shared_timer->node_count_hard_limit) {
34 shared_timer->stop_reason = SearchTimerCommon::NoMoreTime;
35 shared_timer->stop_all = true;
36 throwStop();
37 }
38 MilliSeconds now = MilliSeconds::now();
39 shared_timer->nps = node_count / (0.1+(now - shared_timer->start_time).toSeconds());
40 const int period100 =
41 (shared_timer->node_count_hard_limit != std::numeric_limits<uint64_t>::max())
42 ? 1 : 25;
43 shared_timer->next_node_count = node_count + static_cast<int>(shared_timer->nps * period100 / 100.0);
44 shared_timer->last_tested = now;
45 static int skip = 0;
46 if (++skip % (100 / period100) == 0) {
47 const double memory_use_ratio = OslConfig::memoryUseRatio();
48 shared_timer->last_memory_use1000 = static_cast<int>(1000*memory_use_ratio);
49 if (memory_use_ratio > 0.85) {
50 if (maximum_node_count > 0) {
51 if (node_count > maximum_node_count
52 || (memory_use_ratio > maximum_memory_use_ratio
53 && node_count > 0.85*maximum_node_count)
54 || (memory_use_ratio > 0.87
55 && node_count > 0.8*maximum_node_count))
56 {
57 if (memory_use_ratio > 0.87 && memory_use_ratio > maximum_memory_use_ratio) {
58 maximum_memory_use_ratio = std::min(0.88, memory_use_ratio);
59 maximum_node_count = maximum_node_count * 0.9;
60 }
61 shared_timer->stop_reason = SearchTimerCommon::NoMoreMemory;
62 shared_timer->stop_all = true;
63 std::cerr << "stop by memory full " << memory_use_ratio << " " << node_count << "\n";
64 throwStop();
65 }
66 }
67 maximum_memory_use_ratio = std::max(memory_use_ratio, maximum_memory_use_ratio);
68 } else if (memory_use_ratio < 0.82) {
69 maximum_node_count = std::max(maximum_node_count, node_count);
70 maximum_memory_use_ratio = 0.82;
71 }
72 #ifndef GPSONE
73 if (elapsed > 1.0) {
74 boost::mutex::scoped_lock lk(OslConfig::lock_io);
75 BOOST_FOREACH(const boost::shared_ptr<SearchMonitor>& monitor,
76 this->monitors()) {
77 monitor->timeInfo(node_count, elapsed);
78 monitor->hashInfo(memory_use_ratio);
79 }
80 }
81 #endif
82 }
83 }
84
85 void osl::search::SearchTimer::adjustMemoryUseLimit(double scale)
86 {
87 maximum_node_count *= scale;
88 }
89
90 void osl::search::SearchTimer::
91 addMonitor(const boost::shared_ptr<SearchMonitor>& monitor)
92 {
93 shared_timer->monitors.push_back(monitor);
94 }
95
96
97 /* ------------------------------------------------------------------------- */
98 // ;;; Local Variables:
99 // ;;; mode:c++
100 // ;;; c-basic-offset:2
101 // ;;; End: