Calculate how many threads should be run

This commit is contained in:
Eric Fischer
2015-07-09 15:24:47 -07:00
parent 5d4ab6df1b
commit 2bdb51e995
+18 -7
View File
@@ -827,21 +827,32 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpo
unlink(geomname); unlink(geomname);
} }
int useful_threads = 0;
long long todo = 0; long long todo = 0;
long long along = 0; long long along = 0;
for (j = 0; j < TEMP_FILES; j++) { for (j = 0; j < TEMP_FILES; j++) {
todo += geom_size[j]; todo += geom_size[j];
printf("%d", geom_size[j] != 0); printf("%d", geom_size[j] != 0);
if (geom_size[j] > 0) {
useful_threads++;
}
} }
printf("\n"); printf("\n");
// XXX Should be the number of temp files that have data, #define MAX_THREADS 20 // XXX Obtain from sysctl(hw.ncpu), /proc/cpuinfo, etc.
// capped by the number of processor threads we can actually run
// or by the number of temp files divided by 4, or by int threads = MAX_THREADS;
// some number larger than 4 if we are trying to skip zooms. if (threads > TEMP_FILES / 4) {
// threads = TEMP_FILES / 4;
// Will need to be a power of 2 to make sharding come out right. }
int threads = 1; // XXX is it useful to divide further if we know we are skipping
// some zoom levels? Is it faster to have fewer CPUs working on
// sharding, but more deeply, or fewer CPUs, less deeply?
if (threads > useful_threads) {
threads = useful_threads;
}
// Round down to a power of 2
threads = 1 << (int)(log(threads) / log(2));
int thread = 0; int thread = 0;