Now parallelize the merge of thread-local maps:


Edit

            // Merge thread-local maps into data
            std::cerr << "  Merging thread-local results..." << std::endl;
            for (auto& tm : thread_maps) {
                for (auto& [cell_id, ids] : tm.ways) {
                    auto& target = data.cell_to_ways[cell_id];
                    target.insert(target.end(), ids.begin(), ids.end());
                }
                for (auto& [cell_id, ids] : tm.interps) {
                    auto& target = data.cell_to_interps[cell_id];
                    target.insert(target.end(), ids.begin(), ids.end());
                }
            }

            // Merge thread-local maps into data (ways and interps in parallel)
            std::cerr << "  Merging thread-local results..." << std::endl;
            auto merge_ways = std::async(std::launch::async, [&] {
                for (auto& tm : thread_maps) {
                    for (auto& [cell_id, ids] : tm.ways) {
                        auto& target = data.cell_to_ways[cell_id];
                        target.insert(target.end(), ids.begin(), ids.end());
                    }
                    tm.ways.clear();
                }
            });
            auto merge_interps = std::async(std::launch::async, [&] {
                for (auto& tm : thread_maps) {
                    for (auto& [cell_id, ids] : tm.interps) {
                        auto& target = data.cell_to_interps[cell_id];
                        target.insert(target.end(), ids.begin(), ids.end());
                    }
                    tm.interps.clear();
                }
            });
            merge_ways.get();
            merge_interps.get();