From 2d87059a0441a0ef0bbd40815518b0162e28fe81 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Fri, 10 Nov 2017 13:59:57 -0800 Subject: [PATCH] Some more constructors --- geobuf.cpp | 14 ++++++++++---- main.cpp | 25 ++++++++++++++++--------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/geobuf.cpp b/geobuf.cpp index ac83e74..c3ac08d 100644 --- a/geobuf.cpp +++ b/geobuf.cpp @@ -425,6 +425,10 @@ struct queue_run_arg { size_t start; size_t end; size_t segment; + + queue_run_arg(size_t start1, size_t end1, size_t segment1) + : start(start1), end(end1), segment(segment1) { + } }; void *run_parse_feature(void *v) { @@ -444,7 +448,6 @@ void runQueue() { } std::vector qra; - qra.resize(CPUS); std::vector pthreads; pthreads.resize(CPUS); @@ -452,10 +455,13 @@ void runQueue() { for (size_t i = 0; i < CPUS; i++) { *((*(feature_queue[0].sst))[i].layer_seq) = *((*(feature_queue[0].sst))[0].layer_seq) + feature_queue.size() * i / CPUS; - qra[i].start = feature_queue.size() * i / CPUS; - qra[i].end = feature_queue.size() * (i + 1) / CPUS; - qra[i].segment = i; + qra.push_back(queue_run_arg( + feature_queue.size() * i / CPUS, + feature_queue.size() * (i + 1) / CPUS, + i)); + } + for (size_t i = 0; i < CPUS; i++) { if (pthread_create(&pthreads[i], NULL, run_parse_feature, &qra[i]) != 0) { perror("pthread_create"); exit(EXIT_FAILURE); diff --git a/main.cpp b/main.cpp index e12b88a..c70d306 100644 --- a/main.cpp +++ b/main.cpp @@ -302,6 +302,10 @@ struct sort_arg { size_t nmerges; long long unit; int bytes; + + sort_arg(int task1, int cpus1, long long indexpos1, struct mergelist *merges1, int indexfd1, size_t nmerges1, long long unit1, int bytes1) + : task(task1), cpus(cpus1), indexpos(indexpos1), merges(merges1), indexfd(indexfd1), nmerges(nmerges1), unit(unit1), bytes(bytes1) { + } }; void *run_sort(void *v) { @@ -726,18 +730,21 @@ void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int split } pthread_t pthreads[CPUS]; - struct sort_arg args[CPUS]; + std::vector args; for (size_t a = 0; a < CPUS; a++) { - args[a].task = a; - args[a].cpus = CPUS; - args[a].indexpos = indexpos; - args[a].merges = merges; - args[a].indexfd = indexfds[i]; - args[a].nmerges = nmerges; - args[a].unit = unit; - args[a].bytes = bytes; + args.push_back(sort_arg( + a, + CPUS, + indexpos, + merges, + indexfds[i], + nmerges, + unit, + bytes)); + } + for (size_t a = 0; a < CPUS; a++) { if (pthread_create(&pthreads[a], NULL, run_sort, &args[a]) != 0) { perror("pthread_create"); exit(EXIT_FAILURE);