Пример #1
0
        protected double[] run(DoubleMatrix2D A, Boolean collectResults, Matrix2DMatrix2DFunction fun)
        {
            DoubleMatrix2D[] blocks;
            blocks = this.smp.SplitBlockedNN(A, NN_THRESHOLD, A.Rows * A.Columns);
            //blocks = this.smp.splitStridedNN(A, NN_THRESHOLD, A.Rows*A.Columns);
            int b = blocks != null ? blocks.Length : 1;

            double[] results = collectResults ? new double[b] : null;

            if (blocks == null)
            { // too small -> sequential
                double result = fun(A, null);
                if (collectResults)
                {
                    results[0] = result;
                }
                return(results);
            }
            else
            { // parallel
                this.smp.Run(blocks, null, ref results, fun);
            }
            return(results);
        }
Пример #2
0
        public void Run(DoubleMatrix2D[] blocksA, DoubleMatrix2D[] blocksB, ref double[] results, Matrix2DMatrix2DFunction function)
        {
            double[] buf = new double[blocksA.Length];

            Action <int> task = (i =>
            {
                double result = function(blocksA[i], blocksB != null ? blocksB[i] : null);
                if (buf != null)
                {
                    buf[i] = result;
                }
                //Console.Write(".");
            });

            for (int i = 0; i < blocksA.Length; i++)
            {
                int k = i;

                taskGroup.QueueTask(() => task(k));
            }

            results = buf;

            #region Original Java Code
            //            FJTask[] subTasks = new FJTask[blocksA.Length];
            //            for (int i = 0; i < blocksA.Length; i++)
            //            {
            //                int k = i;
            //                subTasks[i] = new FJTask()
            //                {

            //            public void run()
            //                {
            //                    double result = function(blocksA[k], blocksB != null ? blocksB[k] : null);
            //                    if (results != null) results[k] = result;
            //                    //Console.Write(".");
            //                }
            //            };
            //        }

            //	// run tasks and wait for completion
            //	try {
            //		this.taskGroup.invoke(

            //            new FJTask()
            //        {
            //            public void run()
            //            {
            //                coInvoke(subTasks);
            //            }
            //        }
            //		);
            //	} catch (InterruptedException exc) {}
            //}
            #endregion
        }