public double[] StaticRange() { _name = nameof(StaticRange); this.ClearRanges(); var corr = new double[_values.Length / 2]; Parallel.ForEach( WorkloadPartitioner.Create(_values.Length / 2), range => this.AutoCorrelationToArrayImpl(corr, range) ); return(corr); }
//--------------------------------------------------------------------- internal double[] AutoCorrelationToArrayParallelSimd() { var corr = new double[_length / 2]; int n = _length; var parallelOptions = GetParallelOptions(); const int partitionMultiplier = 8; int partitionCount = parallelOptions.MaxDegreeOfParallelism * partitionMultiplier; Parallel.ForEach( WorkloadPartitioner.Create(n / 2, loadFactorAtStart: n, loadFactorAtEnd: n / 2, partitionCount), parallelOptions, range => this.AutoCorrelationToArrayImpl(corr, range) ); return(corr); }
public double[] TrapezeWorkload() { _name = nameof(TrapezeWorkload); this.ClearRanges(); int n = _values.Length; var corr = new double[n / 2]; var parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = 8 }; Parallel.ForEach( WorkloadPartitioner.Create(n / 2, loadFactorAtStart: n, loadFactorAtEnd: n * 0.5, Environment.ProcessorCount * this.PartitionMultiplier), parallelOptions, range => this.AutoCorrelationToArrayImpl(corr, range)); return(corr); }
public double[] CustomLoop() { _name = nameof(CustomLoop); this.ClearRanges(); int n = _values.Length; var corr = new double[n / 2]; int parallelCount = Environment.ProcessorCount; WorkloadPartitioner partitioner = WorkloadPartitioner.Create(n / 2, loadFactorAtStart: n, loadFactorAtEnd: n * 0.5, Environment.ProcessorCount * this.PartitionMultiplier); IEnumerable <KeyValuePair <long, Range> > partitionEnumerator = partitioner.GetOrderableDynamicPartitions(); var tasks = new Task[parallelCount]; tasks[0] = new Task(Loop, partitionEnumerator); for (int i = 1; i < parallelCount; ++i) { tasks[i] = Task.Factory.StartNew(Loop, partitionEnumerator); } tasks[0].RunSynchronously(); Task.WaitAll(tasks); return(corr); //----------------------------------------------------------------- void Loop(object _) { foreach (KeyValuePair <long, Range> partition in _ as IEnumerable <KeyValuePair <long, Range> > ) { Range range = partition.Value; this.AutoCorrelationToArrayImpl(corr, range); } } }