Catalog: parallelize all-sky tile prefetch

This commit is contained in:
wyj committed 2026-08-27 03:53:45 -04:00
1 parent d9f2c83b9f
commit 457c0728b4
10 files changed
+371 -55

No files matched your search

+71
View File
@@ -0,0 +1,71 @@
#define _POSIX_C_SOURCE 200809L
#include "catalog.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
static int write_tile(const char *directory, int ra_index, int dec_index,
double longitude) {
char path[4096];
const int written = snprintf(path, sizeof path, "%s/tile_ra%03d_dec%03d.csv",
directory, ra_index, dec_index);
if (written < 0 || written >= (int)sizeof path)
return -1;
FILE *file = fopen(path, "w");
if (file == NULL)
return -1;
const int result =
fputs("longitude_deg,latitude_deg,temperature_K,amplitude\n", file) == EOF ||
fprintf(file, "%.1f,0,7000,1\n", longitude) < 0 ||
fclose(file) != 0;
return result ? -1 : 0;
}
int main(void) {
char directory[] = "/tmp/catalog_prefetch_XXXXXX";
char path[4096];
StarCatalog catalog = {0};
unsigned char requested[CATALOG_ALL_SKY_TILE_COUNT] = {0};
CatalogPrefetchStats first = {0}, second = {0};
int result = 1;
if (mkdtemp(directory) == NULL || write_tile(directory, 0, 90, 0.0) ||
write_tile(directory, 1, 90, 1.0) ||
catalog_load_all_sky(&catalog, directory))
goto done;
requested[90 * CATALOG_ALL_SKY_RA_TILES] = 1;
requested[90 * CATALOG_ALL_SKY_RA_TILES + 1] = 1;
requested[90 * CATALOG_ALL_SKY_RA_TILES + 2] = 1; /* Missing on purpose. */
if (catalog_prefetch_marked_tiles(&catalog, requested, 4, &first) ||
first.requested_tiles != 3 || first.newly_loaded_tiles != 2 ||
first.unavailable_tiles != 1 || first.newly_loaded_stars != 2 ||
catalog.count != 2 ||
catalog.tiles[90 * CATALOG_ALL_SKY_RA_TILES].state != 1 ||
catalog.tiles[90 * CATALOG_ALL_SKY_RA_TILES + 1].state != 1 ||
catalog.tiles[90 * CATALOG_ALL_SKY_RA_TILES + 2].state != -1) {
fputs("parallel catalog prefetch regression failed\n", stderr);
goto done;
}
Star *first_tile = catalog.tiles[90 * CATALOG_ALL_SKY_RA_TILES].stars;
if (catalog_prefetch_marked_tiles(&catalog, requested, 2, &second) ||
second.requested_tiles != 3 || second.newly_loaded_tiles != 0 ||
second.unavailable_tiles != 0 || second.newly_loaded_stars != 0 ||
catalog.count != 2 ||
catalog.tiles[90 * CATALOG_ALL_SKY_RA_TILES].stars != first_tile) {
fputs("catalog prefetch cache reuse regression failed\n", stderr);
goto done;
}
result = 0;
done:
catalog_destroy(&catalog);
for (int ra = 0; ra < 3; ++ra) {
const int written = snprintf(path, sizeof path, "%s/tile_ra%03d_dec090.csv",
directory, ra);
if (written > 0 && written < (int)sizeof path)
unlink(path);
}
rmdir(directory);
return result;
}