Add an option to run mostly synchronously for profiling

This commit is contained in:
Erica Fischer
2022-09-13 13:00:14 -07:00
parent 8e46650da7
commit b3fea7c172
7 changed files with 31 additions and 10 deletions
+2 -2
View File
@@ -302,7 +302,7 @@ void fgbRunQueue() {
}
for (size_t i = 0; i < CPUS; i++) {
if (pthread_create(&pthreads[i], NULL, fgb_run_parse_feature, &qra[i]) != 0) {
if (pthread_create_wrap(&pthreads[i], NULL, fgb_run_parse_feature, &qra[i]) != 0) {
perror("pthread_create");
exit(EXIT_FAILURE);
}
@@ -396,4 +396,4 @@ void parse_flatgeobuf(std::vector<struct serialization_state> *sst, const char *
}
fgbRunQueue();
}
}
+1 -1
View File
@@ -464,7 +464,7 @@ void runQueue() {
}
for (size_t i = 0; i < CPUS; i++) {
if (pthread_create(&pthreads[i], NULL, run_parse_feature, &qra[i]) != 0) {
if (pthread_create_wrap(&pthreads[i], NULL, run_parse_feature, &qra[i]) != 0) {
perror("pthread_create");
exit(EXIT_FAILURE);
}
+17 -3
View File
@@ -468,7 +468,7 @@ void do_read_parallel(char *map, long long len, long long initial_offset, const
}
for (size_t i = 0; i < CPUS; i++) {
if (pthread_create(&pthreads[i], NULL, run_parse_json, &pja[i]) != 0) {
if (pthread_create_wrap(&pthreads[i], NULL, run_parse_json, &pja[i]) != 0) {
perror("pthread_create");
exit(EXIT_FAILURE);
}
@@ -682,7 +682,7 @@ void start_parsing(int fd, STREAM *fp, long long offset, long long len, std::ato
rpa->want_dist = want_dist;
rpa->filters = filters;
if (pthread_create(parallel_parser, NULL, run_read_parallel, rpa) != 0) {
if (pthread_create_wrap(parallel_parser, NULL, run_read_parallel, rpa) != 0) {
perror("pthread_create");
exit(EXIT_FAILURE);
}
@@ -877,7 +877,7 @@ void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int split
}
for (size_t a = 0; a < CPUS; a++) {
if (pthread_create(&pthreads[a], NULL, run_sort, &args[a]) != 0) {
if (pthread_create_wrap(&pthreads[a], NULL, run_sort, &args[a]) != 0) {
perror("pthread_create");
exit(EXIT_FAILURE);
}
@@ -2789,6 +2789,7 @@ int main(int argc, char **argv) {
{"check-polygons", no_argument, &additional[A_DEBUG_POLYGON], 1},
{"no-polygon-splitting", no_argument, &prevent[P_POLYGON_SPLIT], 1},
{"prefer-radix-sort", no_argument, &additional[A_PREFER_RADIX_SORT], 1},
{"single-threaded", no_argument, &prevent[P_THREADS], 1},
{"help", no_argument, 0, 'H'},
{0, 0, 0, 0},
@@ -3451,3 +3452,16 @@ bool progress_time() {
return false;
}
}
static void *donothing(void *arg) {
return arg;
}
int pthread_create_wrap(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) {
if (prevent[P_THREADS]) {
void *ret = start_routine(arg);
return pthread_create(thread, attr, donothing, ret);
} else {
return pthread_create(thread, attr, start_routine, arg);
}
}
+2
View File
@@ -72,4 +72,6 @@ bool progress_time();
#define MAX_ZOOM 24
int pthread_create_wrap(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg);
#endif
+1
View File
@@ -44,6 +44,7 @@
#define P_REVERSE_SOURCE_POLYGON_WINDING ((int) 'W')
#define P_EMPTY_CSV_COLUMNS ((int) 'e')
#define P_BASEZOOM_ABOVE_MAXZOOM ((int) 'b')
#define P_THREADS ((int) 'T')
extern int prevent[256];
extern int additional[256];
+4
View File
@@ -141,6 +141,10 @@ std::string format_commandline(int argc, char **argv) {
std::string out;
for (int i = 0; i < argc; i++) {
if (std::string(argv[i]) == "-pT") {
continue;
}
bool need_quote = false;
for (char *cp = argv[i]; *cp != '\0'; cp++) {
if (!isalpha(*cp) && !isdigit(*cp) &&
+4 -4
View File
@@ -2225,8 +2225,8 @@ long long write_tile(FILE *geoms, std::atomic<long long> *geompos_in, char *meta
args[i].shared_nodes = &shared_nodes;
if (tasks > 1) {
if (pthread_create(&pthreads[i], NULL, partial_feature_worker, &args[i]) != 0) {
perror("pthread_create");
if (pthread_create_wrap(&pthreads[i], NULL, partial_feature_worker, &args[i]) != 0) {
perror("pthread_create_wrap");
exit(EXIT_FAILURE);
}
} else {
@@ -2980,8 +2980,8 @@ int traverse_zooms(int *geomfd, off_t *geom_size, char *metabase, char *stringpo
args[thread].still_dropping = false;
args[thread].strategy = &strategy;
if (pthread_create(&pthreads[thread], NULL, run_thread, &args[thread]) != 0) {
perror("pthread_create");
if (pthread_create_wrap(&pthreads[thread], NULL, run_thread, &args[thread]) != 0) {
perror("pthread_create_wrap");
exit(EXIT_FAILURE);
}
}