public static T Reduce <T>(IList <T> values, ReduceOp <T> red) { if (values == null || red == null) { throw new ArgumentNullException(); } return(red(values)); }
public static Bits Reduce(ReduceOp op, Bits input, int esize) { int N = input.Count; int half; Bits hi; Bits lo; Bits result = new Bits(esize); if (N == esize) { return(new Bits(input)); } half = N / 2; hi = Reduce(op, input[N - 1, half], esize); lo = Reduce(op, input[half - 1, 0], esize); switch (op) { case ReduceOp.ReduceOp_FMINNUM: /* result = FPMinNum(lo, hi, FPCR); */ break; case ReduceOp.ReduceOp_FMAXNUM: /* result = FPMaxNum(lo, hi, FPCR); */ break; case ReduceOp.ReduceOp_FMIN: /* result = FPMin(lo, hi, FPCR); */ break; case ReduceOp.ReduceOp_FMAX: /* result = FPMax(lo, hi, FPCR); */ break; case ReduceOp.ReduceOp_FADD: /* result = FPAdd(lo, hi, FPCR); */ break; default: case ReduceOp.ReduceOp_ADD: result = lo + hi; break; } return(result); }
internal ReduceTask(ReduceTask <P_IN, P_OUT, R, S> parent, Spliterator <P_IN> spliterator) : base(parent, spliterator) { this.Op = parent.Op; }
internal ReduceTask(ReduceOp <P_OUT, R, S> op, PipelineHelper <P_OUT> helper, Spliterator <P_IN> spliterator) : base(helper, spliterator) { this.Op = op; }
/// <summary> /// A parallel FOR-loop; /// runs <paramref name="operation"/> in parallel, with <see cref="NumThreads"/> number of threads; /// </summary> /// <param name="operation"></param> /// <param name="ReduceOp"></param> /// <param name="i0"> /// start index /// </param> /// <param name="Len"> /// loop lenght /// </param> /// <remarks> /// if at least one thread throws an exception, an exception is thrown. /// </remarks> public static T ReduceFor <T>(int i0, int Len, ReduceForParallel <T> operation, ReduceOp <T> ReduceOp) where T : struct { if (m_CurrentWorker != null) { throw new ApplicationException("allready in parallel section"); } int N = NumThreads; T[] thr_res = new T[N]; Run(delegate(int rnk, int Sz) { int thr_i0 = (Len * rnk) / Sz + i0; int thr_iE = (Len * (rnk + 1)) / Sz + i0; thr_res[rnk] = operation(thr_i0, thr_iE); }); T retval = thr_res[0];// default(T); for (int i = 1; i < N; i++) { ReduceOp(ref retval, ref thr_res[i]); } return(retval); }
public static T Reduce <T>(IList <T> values, MapOp <T> op, ReduceOp <T> red) { Map(values, op); return(red(values)); }