/// <summary> /// Processes a stream of fixed-size array messages by creating a stream for each element in the array, /// and performing an action on each of these streams. /// </summary> /// <typeparam name="TIn">Type of input array element.</typeparam> /// <param name="source">Source stream.</param> /// <param name="vectorSize">Vector arity.</param> /// <param name="streamAction">Action to apply to the individual element streams.</param> /// <param name="deliveryPolicy">An optional delivery policy.</param> /// <returns>Stream of output arrays.</returns> public static IProducer <TIn[]> Parallel <TIn>( this IProducer <TIn[]> source, int vectorSize, Action <int, IProducer <TIn> > streamAction, DeliveryPolicy deliveryPolicy = null) { var p = new ParallelFixedLength <TIn, TIn>(source.Out.Pipeline, vectorSize, streamAction); source.PipeTo(p, deliveryPolicy); return(source); }
/// <summary> /// Transforms a stream of fixed-size array messages by creating a stream for each element in the array, /// applying a sub-pipeline to each of these streams, and assembling the results into a corresponding output /// array stream. /// </summary> /// <typeparam name="TIn">Type of input array element.</typeparam> /// <typeparam name="TOut">Type of output array element.</typeparam> /// <param name="source">Source stream.</param> /// <param name="vectorSize">Vector arity.</param> /// <param name="streamTransform">Function mapping from an index and stream of input element to a stream of output element.</param> /// <param name="joinOrDefault">When true, a result is produced even if a message is dropped in processing one of the input elements. In this case the corresponding output element is set to default.</param> /// <param name="deliveryPolicy">An optional delivery policy.</param> /// <returns>Stream of output arrays.</returns> public static IProducer <TOut[]> Parallel <TIn, TOut>( this IProducer <TIn[]> source, int vectorSize, Func <int, IProducer <TIn>, IProducer <TOut> > streamTransform, bool joinOrDefault = false, DeliveryPolicy deliveryPolicy = null) { var p = new ParallelFixedLength <TIn, TOut>(source.Out.Pipeline, vectorSize, streamTransform, joinOrDefault); return(PipeTo(source, p, deliveryPolicy)); }
/// <summary> /// Transforms a stream of fixed-size array messages by creating a stream for each element in the array, /// applying a sub-pipeline to each of these streams, and assembling the results into a corresponding output /// array stream. /// </summary> /// <typeparam name="TIn">Type of input array element.</typeparam> /// <typeparam name="TOut">Type of output array element.</typeparam> /// <param name="source">Source stream.</param> /// <param name="vectorSize">Vector arity.</param> /// <param name="streamTransform">Function mapping from an index and stream of input element to a stream of output element.</param> /// <param name="outputDefaultIfDropped">When true, a result is produced even if a message is dropped in processing one of the input elements. In this case the corresponding output element is set to a default value.</param> /// <param name="defaultValue">Default value to use when messages are dropped in processing one of the input elements.</param> /// <param name="deliveryPolicy">An optional delivery policy.</param> /// <returns>Stream of output arrays.</returns> public static IProducer <TOut[]> Parallel <TIn, TOut>( this IProducer <TIn[]> source, int vectorSize, Func <int, IProducer <TIn>, IProducer <TOut> > streamTransform, bool outputDefaultIfDropped = false, TOut defaultValue = default, DeliveryPolicy deliveryPolicy = null) { var p = new ParallelFixedLength <TIn, TOut>(source.Out.Pipeline, vectorSize, streamTransform, outputDefaultIfDropped, defaultValue); return(PipeTo(source, p, deliveryPolicy)); }
public void ParallelComponentIssolationTest() { // verify that Parallel* components don't expose emitters of inner Subpipeline using (var p = Pipeline.Create()) { var parallel = new ParallelFixedLength <int, int>(p, 10, (i, prod) => prod, false); Assert.AreEqual(p, parallel.Out.Pipeline); // composite components shouldn't expose subpipelines var parallelVarLen = new ParallelVariableLength <int, int>(p, (i, prod) => prod, false); Assert.AreEqual(p, parallelVarLen.Out.Pipeline); // composite components shouldn't expose subpipelines var parallelSparse = new ParallelSparseSelect <Dictionary <int, int>, int, int, int, Dictionary <int, int> >(p, _ => _, (i, prod) => prod, _ => _, false); Assert.AreEqual(p, parallelSparse.Out.Pipeline); // composite components shouldn't expose subpipelines } }