| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2026 Tiger Data, Inc. | ||
| 3 | * Licensed under the PostgreSQL License. See LICENSE for details. | ||
| 4 | * | ||
| 5 | * parallel_scan_standalone.c - Work-stealing vector scan over an array | ||
| 6 | * | ||
| 7 | * Standalone implementation of the parallel build scan (see | ||
| 8 | * prism_build_scan.h). PG builds scan the heap via table_index_build_scan | ||
| 9 | * instead, so this file is compiled only for standalone. | ||
| 10 | */ | ||
| 11 | |||
| 12 | #ifdef VS_STANDALONE | ||
| 13 | |||
| 14 | #include "standalone/parallel_scan.h" | ||
| 15 | |||
| 16 | void | ||
| 17 | 168 | prism_parallel_scan_init( | |
| 18 | PrismParallelScan *ps, | ||
| 19 | const float *vectors, | ||
| 20 | uint32_t nvecs, | ||
| 21 | Dimension dim) | ||
| 22 | { | ||
| 23 | 168 | ps->vectors = vectors; | |
| 24 | 168 | ps->nvecs = nvecs; | |
| 25 | 168 | ps->dim = dim; | |
| 26 | 168 | atomic_store(&ps->cursor, 0); | |
| 27 | 168 | } | |
| 28 | |||
| 29 | double | ||
| 30 | 304 | prism_parallel_scan_run( | |
| 31 | PrismParallelScan *ps, PrismBuildScanCb cb, void *state) | ||
| 32 | { | ||
| 33 | 304 | Dimension dim = ps->dim; | |
| 34 | 304 | double scanned = 0; | |
| 35 | |||
| 36 | for (;;) | ||
| 37 | 776 | { | |
| 38 | 1080 | uint32_t start = atomic_fetch_add(&ps->cursor, PRISM_BUILD_SCAN_CHUNK); | |
| 39 | uint32_t end; | ||
| 40 | |||
| 41 |
2/2✓ Branch 0 taken 304 times.
✓ Branch 1 taken 776 times.
|
1080 | if (start >= ps->nvecs) |
| 42 | 304 | break; | |
| 43 | |||
| 44 | 776 | end = start + PRISM_BUILD_SCAN_CHUNK; | |
| 45 |
2/2✓ Branch 0 taken 168 times.
✓ Branch 1 taken 608 times.
|
776 | if (end > ps->nvecs) |
| 46 | 168 | end = ps->nvecs; | |
| 47 | |||
| 48 |
2/2✓ Branch 0 taken 362278 times.
✓ Branch 1 taken 776 times.
|
363054 | for (uint32_t i = start; i < end; i++) |
| 49 | { | ||
| 50 | ItemPointerData tid; | ||
| 51 | |||
| 52 | /* Reversible: ItemPointerGetBlockNumber(tid) == i. */ | ||
| 53 | 362278 | ItemPointerSet(&tid, i, 1); | |
| 54 | 362278 | cb(state, tid, ps->vectors + (size_t)i * dim); | |
| 55 | } | ||
| 56 | 776 | scanned += end - start; | |
| 57 | } | ||
| 58 | 304 | return scanned; | |
| 59 | } | ||
| 60 | |||
| 61 | #endif /* VS_STANDALONE */ | ||
| 62 |