ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
tiers.c
Go to the documentation of this file.
1#include "tiers.h"
2#include "internal.h"
3#include "logging.h"
4#include "print.h"
5
7
8static void compute_tier_limits (kissat *solver, bool stable,
9 unsigned *tier1_ptr, unsigned *tier2_ptr) {
10 statistics *statistics = &solver->statistics_;
11 uint64_t *used_stats = statistics->used[stable].glue;
12 uint64_t total_used = 0;
13 for (unsigned glue = 0; glue <= MAX_GLUE_USED; glue++)
14 total_used += used_stats[glue];
15 int tier1 = -1, tier2 = -1;
16 if (total_used) {
17 uint64_t accumulated_tier1_limit = total_used * TIER1RELATIVE;
18 uint64_t accumulated_tier2_limit = total_used * TIER2RELATIVE;
19 uint64_t accumulated_used = 0;
20 unsigned glue;
21 for (glue = 0; glue <= MAX_GLUE_USED; glue++) {
22 uint64_t glue_used = used_stats[glue];
23 accumulated_used += glue_used;
24 if (accumulated_used >= accumulated_tier1_limit) {
25 tier1 = glue;
26 break;
27 }
28 }
29 if (accumulated_used < accumulated_tier2_limit) {
30 for (glue = tier1 + 1; glue <= MAX_GLUE_USED; glue++) {
31 uint64_t glue_used = used_stats[glue];
32 accumulated_used += glue_used;
33 if (accumulated_used >= accumulated_tier2_limit) {
34 tier2 = glue;
35 break;
36 }
37 }
38 }
39 }
40 if (tier1 < 0) {
41 tier1 = GET_OPTION (tier1);
42 tier2 = MAX (GET_OPTION (tier2), tier1);
43 } else if (tier2 < 0)
44 tier2 = tier1;
45 KISSAT_assert (0 <= tier1);
46 KISSAT_assert (0 <= tier2);
47 *tier1_ptr = tier1;
48 *tier2_ptr = tier2;
49 LOG ("%s tier1 limit %u", stable ? "stable" : "focused", tier1);
50 LOG ("%s tier2 limit %u", stable ? "stable" : "focused", tier2);
51}
52
54 bool stable = solver->stable;
55 unsigned tier1, tier2;
56 compute_tier_limits (solver, stable, &tier1, &tier2);
57 solver->tier1[stable] = tier1;
58 solver->tier2[stable] = tier2;
59 kissat_phase (solver, "retiered", GET (retiered),
60 "recomputed %s tier1 limit %u and tier2 limit %u "
61 "after %" PRIu64 " conflicts",
62 stable ? "stable" : "focused", tier1, tier2, CONFLICTS);
63}
64
65static unsigned decimal_digits (uint64_t i) {
66 unsigned res = 1;
67 uint64_t limit = 10;
68 for (;;) {
69 if (i < limit)
70 return res;
71 limit *= 10;
72 res++;
73 }
74}
75
77 unsigned tier1, tier2;
78 compute_tier_limits (solver, stable, &tier1, &tier2);
79 statistics *statistics = &solver->statistics_;
80 uint64_t *used_stats = statistics->used[stable].glue;
81 uint64_t total_used = 0;
82 for (unsigned glue = 0; glue <= MAX_GLUE_USED; glue++)
83 total_used += used_stats[glue];
84 const char *mode = stable ? "stable" : "focused";
85 KISSAT_assert (tier1 <= tier2);
86 unsigned span = tier2 - tier1 + 1;
87 const unsigned max_printed = 5;
88 KISSAT_assert (max_printed & 1), KISSAT_assert (max_printed / 2 > 0);
89 unsigned prefix, suffix;
90 if (span > max_printed) {
91 prefix = tier1 + max_printed / 2 - 1;
92 suffix = tier2 - max_printed / 2 + 1;
93 } else
94 prefix = UINT_MAX, suffix = 0;
95 uint64_t accumulated_middle = 0;
96 int glue_digits = 1, clauses_digits = 1;
97 for (unsigned glue = 0; glue <= MAX_GLUE_USED; glue++) {
98 if (glue < tier1)
99 continue;
100 uint64_t used = used_stats[glue];
101 int tmp_glue = 0, tmp_clauses = 0;
102 if (glue <= prefix || suffix <= glue) {
103 tmp_glue = decimal_digits (glue);
104 tmp_clauses = decimal_digits (used);
105 } else {
106 accumulated_middle += used;
107 if (glue + 1 == suffix) {
108 tmp_glue = decimal_digits (prefix + 1) + decimal_digits (glue) + 1;
109 tmp_clauses = decimal_digits (accumulated_middle);
110 }
111 }
112 if (tmp_glue > glue_digits)
113 glue_digits = tmp_glue;
114 if (tmp_clauses > clauses_digits)
115 clauses_digits = tmp_clauses;
116 if (glue == tier2)
117 break;
118 }
119 char fmt[32];
120 sprintf (fmt, "%%%d" PRIu64, clauses_digits);
121 accumulated_middle = 0;
122 uint64_t accumulated = 0;
123 for (unsigned glue = 0; glue <= MAX_GLUE_USED; glue++) {
124 uint64_t used = used_stats[glue];
125 accumulated += used;
126 if (glue < tier1)
127 continue;
128 if (glue <= prefix || suffix <= glue + 1) {
129 fputs (solver->prefix, stdout);
130 fputs (mode, stdout);
131 fputs (" glue ", stdout);
132 }
133 if (glue <= prefix || suffix <= glue) {
134 int len = printf ("%u", glue);
135 while (len > 0 && len < glue_digits)
136 fputc (' ', stdout), len++;
137 fputs (" used ", stdout);
138 printf (fmt, used);
139 printf (" clauses %5.2f%% accumulated %5.2f%%",
140 kissat_percent (used, total_used),
141 kissat_percent (accumulated, total_used));
142 if (glue == tier1)
143 fputs (" tier1", stdout);
144 if (glue == tier2)
145 fputs (" tier2", stdout);
146 fputc ('\n', stdout);
147 } else {
148 accumulated_middle += used;
149 if (glue + 1 == suffix) {
150 int len = printf ("%u-%u", prefix + 1, suffix - 1);
151 while (len > 0 && len < glue_digits)
152 fputc (' ', stdout), len++;
153 fputs (" used ", stdout);
154 printf (fmt, accumulated_middle);
155 printf (" clauses %5.2f%% accumulated %5.2f%%\n",
156 kissat_percent (accumulated_middle, total_used),
157 kissat_percent (accumulated, total_used));
158 }
159 }
160 if (glue == tier2)
161 break;
162 }
163}
164
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define MAX(a, b)
Definition avl.h:23
#define LOG(...)
#define KISSAT_assert(ignore)
Definition global.h:13
#define solver
Definition kitten.c:211
#define TIER2RELATIVE
Definition options.h:224
#define TIER1RELATIVE
Definition options.h:223
#define GET_OPTION(N)
Definition options.h:295
#define kissat_phase(...)
Definition print.h:48
#define CONFLICTS
Definition statistics.h:335
#define GET(NAME)
Definition statistics.h:416
#define MAX_GLUE_USED
Definition statistics.h:313
Definition mode.h:11
METRICS_COUNTERS_AND_STATISTICS struct statistics::@210323365176300370122154220272050204040253242144 used[2]
uint64_t glue[MAX_GLUE_USED+1]
Definition statistics.h:327
void kissat_compute_and_set_tier_limits(struct kissat *solver)
Definition tiers.c:53
void kissat_print_tier_usage_statistics(kissat *solver, bool stable)
Definition tiers.c:76
char * sprintf()