1#ifndef SEAMS_TUM_DEVICE_H_
2#define SEAMS_TUM_DEVICE_H_
18#ifdef SEAMS_HAS_OFFLOAD
19#pragma omp declare target
30static_assert(
kRowCap <= 32,
"ddcFrom marks row entries in 32-bit masks");
32inline bool bonded(
const int *deg,
const int *cols,
int nAtoms,
int kMax,
34 if (a < 0 || b < 0 || a >= nAtoms || b >= nAtoms) {
38 const int row = a * kMax;
39 for (
int t = 0; t < d; ++t) {
40 if (cols[row + t] == b) {
47inline bool inSix(
const int *r,
int atom) {
48 for (
int t = 0; t < 6; ++t) {
57 for (
int i = 0; i < 6; ++i) {
67 for (
int i = 0; i < 6; ++i) {
76 for (
int i = 0; i < 6; ++i) {
84inline bool shareNeigh(
const int *deg,
const int *cols,
int nAtoms,
int kMax,
86 const int da = deg[a];
87 const int ra = a * kMax;
88 for (
int t = 0; t < da; ++t) {
89 if (
bonded(deg, cols, nAtoms, kMax, b, cols[ra + t])) {
98inline int hopsAtMost(
const int *deg,
const int *cols,
int nAtoms,
int kMax,
99 int a,
int b,
int cap) {
103 if (
bonded(deg, cols, nAtoms, kMax, a, b)) {
109 if (
shareNeigh(deg, cols, nAtoms, kMax, a, b)) {
117 int nAtoms,
int kMax) {
118 const int pairI[9] = {0, 1, 2, 3, 4, 5, 0, 1, 2};
119 const int pairJ[9] = {2, 3, 4, 5, 0, 1, 3, 4, 5};
120 const int ringHops[9] = {2, 2, 2, 2, 2, 2, 3, 3, 3};
121 for (
int t = 0; t < 9; ++t) {
122 if (
hopsAtMost(deg, cols, nAtoms, kMax, r[pairI[t]], r[pairJ[t]],
123 ringHops[t] - 1) >= 0) {
131 int kMax,
const int *trip,
const int *
ring) {
132 for (
int i = 0; i < 3; ++i) {
133 for (
int j = 0; j < 6; ++j) {
134 if (
bonded(deg, cols, nAtoms, kMax,
ring[j], trip[i])) {
148 int kMax,
const int *b1,
const int *b2) {
149 const int perm[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2},
150 {1, 2, 0}, {2, 0, 1}, {2, 1, 0}};
151 for (
int q = 0; q < 2; ++q) {
152 const int oddT[3] = {b2[q + 1], b2[q + 3], b2[(q + 5) % 6]};
156 for (
int p = 0; p < 2; ++p) {
157 for (
int s = 0; s < 6; ++s) {
159 for (
int t = 0; t < 3 && all; ++t) {
160 all =
bonded(deg, cols, nAtoms, kMax, b1[p + 2 * t],
161 b2[q + 2 * perm[s][t]]);
173 const int *C,
int nC,
int skipA,
int skipB,
int *out,
179 while (i < nA && j < nB && k < nC) {
183 if (x == y && y == z) {
184 if (x != skipA && x != skipB && n < cap) {
215#pragma omp atomic capture
225inline void enumSixFrom(
int i,
const int *deg,
const int *cols,
int nAtoms,
226 int kMax,
int maxRings,
int *nRings,
int *ringAtoms) {
227 const int di = deg[i];
231 const int irow = i * kMax;
232 for (
int ia = 0; ia < di; ++ia) {
233 const int a = cols[irow + ia];
234 for (
int ib = ia + 1; ib < di; ++ib) {
235 const int b = cols[irow + ib];
236 const int da = deg[a];
237 const int db = deg[b];
238 const int arow = a * kMax;
239 const int brow = b * kMax;
240 for (
int ix = 0; ix < da; ++ix) {
241 const int x = cols[arow + ix];
242 if (x == i || x == b) {
245 for (
int iy = 0; iy < db; ++iy) {
246 const int y = cols[brow + iy];
247 if (y == i || y == a || y == x) {
250 const int dx = deg[x];
251 const int xrow = x * kMax;
252 for (
int iz = 0; iz < dx; ++iz) {
253 const int z = cols[xrow + iz];
254 if (z == i || z == a || z == b || z == y) {
257 if (!
bonded(deg, cols, nAtoms, kMax, z, y)) {
260 const int cyc[6] = {i, a, x, z, y, b};
262 for (
int t = 1; t < 6; ++t) {
274 if (slot >= maxRings) {
277 const int dest = slot * 6;
278 for (
int t = 0; t < 6; ++t) {
279 ringAtoms[dest + t] = cyc[t];
291 int nAtoms,
int maxPer,
int *throughCount,
296 const int *
ring = ringAtoms + r * 6;
297 for (
int t = 0; t < 6; ++t) {
298 const int atom =
ring[t];
299 if (atom < 0 || atom >= nAtoms) {
302 const int slot =
fetchAdd(throughCount + atom);
304 through[atom * maxPer + slot] = r;
310 for (
int a = 1; a < n; ++a) {
311 const int key = row[a];
313 while (p > 0 && row[p - 1] > key) {
324inline bool seenEarlier(
const int *bi,
const int *deg,
const int *cols,
325 const int *throughCount,
const int *through,
326 int nAtoms,
int kMax,
int maxPer,
int slot,
int n,
328 for (
int s = 0; s <= slot; ++s) {
329 const int anchor = bi[s];
330 if (anchor < 0 || anchor >= nAtoms) {
333 const int arow = anchor * kMax;
334 const int stop = s < slot ? deg[anchor] : n;
335 for (
int m = 0; m < stop; ++m) {
336 const int nb = cols[arow + m];
337 if (nb < 0 || nb >= nAtoms) {
340 const int nr = throughCount[nb];
341 const int *row = through + nb * maxPer;
342 for (
int t = 0; t < nr; ++t) {
356 const int *deg,
const int *cols,
357 const int *throughCount,
const int *through,
358 int nAtoms,
int kMax,
int maxPer,
int maxPairs,
359 int *nPairs,
int *pairs) {
363 const int *bi = ringAtoms + i * 6;
364 for (
int slot = 0; slot < 2; ++slot) {
365 const int anchor = bi[slot];
366 if (anchor < 0 || anchor >= nAtoms) {
369 const int da = deg[anchor];
370 const int arow = anchor * kMax;
371 for (
int n = 0; n < da; ++n) {
372 const int nb = cols[arow + n];
373 if (nb < 0 || nb >= nAtoms) {
376 const int nr = throughCount[nb];
377 const int *row = through + nb * maxPer;
378 for (
int t = 0; t < nr; ++t) {
379 const int j = row[t];
383 if (
seenEarlier(bi, deg, cols, throughCount, through, nAtoms, kMax,
384 maxPer, slot, n, j)) {
387 const int *bj = ringAtoms + j * 6;
395 if (slotp < maxPairs) {
396 pairs[slotp * 2] = i;
397 pairs[slotp * 2 + 1] = j;
404inline void applyHcPair(
int p,
const int *nPairs,
const int *pairs,
405 const int *ringAtoms,
const int *throughCount,
406 const int *through,
int nAtoms,
int maxPer,
int *hc) {
410 const int i = pairs[p * 2];
411 const int j = pairs[p * 2 + 1];
414 const int *bi = ringAtoms + i * 6;
415 const int *bj = ringAtoms + j * 6;
416 for (
int q = 0; q < 6; ++q) {
418 for (
int m = 0; m < 3; ++m) {
419 trip[m] = bi[(q + m) % 6];
421 const int nA = throughCount[trip[0]];
422 const int nB = throughCount[trip[1]];
423 const int nC = throughCount[trip[2]];
424 const int *A = through + trip[0] * maxPer;
425 const int *B = through + trip[1] * maxPer;
426 const int *C = through + trip[2] * maxPer;
429 for (
int c = 0; c < nc; ++c) {
430 const int kr = cand[c];
431 const int *bk = ringAtoms + kr * 6;
434 for (
int u = 0; u < 6; ++u) {
436 if (a != trip[0] && a != trip[1] && a != trip[2]) {
443 if (rest == 3 && restInJ == 3) {
455inline void ddcFrom(
int i,
const int *nRings,
const int *ringAtoms,
456 const int *throughCount,
const int *through,
const int *hc,
457 int nAtoms,
int maxPer,
int *ddc) {
464 const int *bi = ringAtoms + i * 6;
465 for (
int m = 0; m < 6; ++m) {
466 const int atom = bi[m];
467 if (atom < 0 || atom >= nAtoms) {
470 const int nr = throughCount[atom];
471 const int *row = through + atom * maxPer;
473 for (
int t = 0; t < nr; ++t) {
485 for (
int k = 0; k < 6; ++k) {
487 for (
int t = 0; t < 3; ++t) {
488 trip[t] = bi[(k + t) % 6];
490 const int nA = throughCount[trip[0]];
491 const int nB = throughCount[trip[1]];
492 const int nC = throughCount[trip[2]];
493 const int *A = through + trip[0] * maxPer;
494 const int *B = through + trip[1] * maxPer;
495 const int *C = through + trip[2] * maxPer;
502 unsigned used[6] = {0U, 0U, 0U, 0U, 0U, 0U};
504 for (
int a = 0; a < nT[0]; ++a) {
505 const int r0 = T[0][a];
506 const int *p0 = ringAtoms + r0 * 6;
507 for (
int c = 0; c < nT[2]; ++c) {
508 const int r2 = T[2][c];
509 const int *p2 = ringAtoms + r2 * 6;
514 for (
int e = 0; e < nT[4]; ++e) {
515 const int r4 = T[4][e];
516 const int *p4 = ringAtoms + r4 * 6;
523 const unsigned mE = (e40 && e02 ? 1U : 0U) |
524 (e02 && e24 ? 2U : 0U) |
525 (e24 && e40 ? 4U : 0U);
531 unsigned partners = 0U;
532 for (
int t = 0; t < 3; ++t) {
533 if ((mE >> t) & 1U) {
534 partners |= (1U << t) | (1U << ((t + 2) % 3));
537 for (
int b = 0; b < nT[1]; ++b) {
538 const int r1 = T[1][b];
539 const int *p1 = ringAtoms + r1 * 6;
540 if (r1 == r0 || r1 == r2 || r1 == r4) {
543 for (
int d = 0; d < nT[3]; ++d) {
544 const int r3 = T[3][d];
545 const int *p3 = ringAtoms + r3 * 6;
546 if (r3 == r0 || r3 == r2 || r3 == r4 || r3 == r1) {
550 for (
int g = 0; g < nT[5]; ++g) {
551 const int r5 = T[5][g];
552 const int *p5 = ringAtoms + r5 * 6;
553 if (r5 == r0 || r5 == r2 || r5 == r4 || r5 == r1 || r5 == r3 ||
559 const unsigned mO = (o51 && o13 ? 1U : 0U) |
560 (o13 && o35 ? 2U : 0U) |
561 (o35 && o51 ? 4U : 0U);
562 if ((partners & mO) == 0U) {
582 for (
int k = 0; k < 6; ++k) {
583 for (
int t = 0; t < nT[k]; ++t) {
584 if ((used[k] >> t) & 1U) {
591inline void atomIceFrom(
int r,
const int *nRings,
const int *ringAtoms,
592 const int *hc,
const int *ddc,
int nAtoms,
int *atomHc,
597 const int *
ring = ringAtoms + r * 6;
598 const int isHc = hc[r];
599 const int isDdc = ddc[r];
600 for (
int t = 0; t < 6; ++t) {
601 const int a =
ring[t];
602 if (a < 0 || a >= nAtoms) {
617#ifdef SEAMS_HAS_OFFLOAD
618#pragma omp end declare target
Topological network criteria functions.
bool shareNeigh(const int *deg, const int *cols, int nAtoms, int kMax, int a, int b)
bool inSix(const int *r, int atom)
bool seenEarlier(const int *bi, const int *deg, const int *cols, const int *throughCount, const int *through, int nAtoms, int kMax, int maxPer, int slot, int n, int j)
True when ring j is in the through row of a bond neighbour of bi[0] or bi[1] visited before (slot,...
void emitBasalFrom(int i, const int *nRings, const int *ringAtoms, const int *deg, const int *cols, const int *throughCount, const int *through, int nAtoms, int kMax, int maxPer, int maxPairs, int *nPairs, int *pairs)
Ordered basal pairs (i, j).
void applyHcPair(int p, const int *nPairs, const int *pairs, const int *ringAtoms, const int *throughCount, const int *through, int nAtoms, int maxPer, int *hc)
void invertOneRing(int r, const int *nRings, const int *ringAtoms, int nAtoms, int maxPer, int *throughCount, int *through)
throughCount counts every stored ring through the atom; only the first maxPer ids are kept.
int ringsThrough(const int *A, int nA, const int *B, int nB, const int *C, int nC, int skipA, int skipB, int *out, int cap)
bool bonded(const int *deg, const int *cols, int nAtoms, int kMax, int a, int b)
constexpr int kRowCap
Longest atom row the kernels accept.
bool notNeighboursOfRing(const int *deg, const int *cols, int nAtoms, int kMax, const int *trip, const int *ring)
bool commonInThree(const int *a, const int *b, const int *c)
void sortThroughRow(int *row, int n)
void ddcFrom(int i, const int *nRings, const int *ringAtoms, const int *throughCount, const int *through, const int *hc, int nAtoms, int maxPer, int *ddc)
epsilon(i) for a ring that is not HC, as ring::equatorialConditions: every atom in 3 other rings,...
int commonCount(const int *a, const int *b)
void atomIceFrom(int r, const int *nRings, const int *ringAtoms, const int *hc, const int *ddc, int nAtoms, int *atomHc, int *atomDdc)
bool shareAtoms(const int *a, const int *b)
void enumSixFrom(int i, const int *deg, const int *cols, int nAtoms, int kMax, int maxRings, int *nRings, int *ringAtoms)
Enumerate hop-bound primitive six-rings whose lowest vertex is i.
bool hopBoundPrimitiveSix(const int *r, const int *deg, const int *cols, int nAtoms, int kMax)
Hop-bounded Franzblau SP test on a six-cycle of the bond graph.
bool basalConditions(const int *deg, const int *cols, int nAtoms, int kMax, const int *b1, const int *b2)
beta(b1, b2) for rings sharing no atom: some alternating triplet {l_p, l_p+2, l_p+4}...
int hopsAtMost(const int *deg, const int *cols, int nAtoms, int kMax, int a, int b, int cap)
Graph distance from a to b when it is at most cap, else -1.