Skip to main content

quantrs2_sim/automatic_parallelization/
autoparallelengine_aggregate_distributed_results_group.rs

1//! # AutoParallelEngine - aggregate_distributed_results_group Methods
2//!
3//! This module contains method implementations for `AutoParallelEngine`.
4//!
5//! 🤖 Generated with [SplitRS](https://github.com/cool-japan/splitrs)
6
7use quantrs2_core::{
8    error::{QuantRS2Error, QuantRS2Result},
9    gate::GateOp,
10    qubit::QubitId,
11};
12use scirs2_core::parallel_ops::{current_num_threads, IndexedParallelIterator, ParallelIterator};
13use scirs2_core::Complex64;
14
15use super::autoparallelengine_type::AutoParallelEngine;
16
17impl AutoParallelEngine {
18    /// Aggregate results from distributed execution
19    pub(super) fn aggregate_distributed_results(
20        node_results: Vec<Vec<Complex64>>,
21    ) -> QuantRS2Result<Vec<Complex64>> {
22        use scirs2_core::parallel_ops::{IndexedParallelIterator, ParallelIterator};
23        let total_elements: usize = node_results.iter().map(std::vec::Vec::len).sum();
24        let mut aggregated = Vec::with_capacity(total_elements);
25        for node_result in node_results {
26            aggregated.extend(node_result);
27        }
28        Ok(aggregated)
29    }
30}