private DeferredExecutionContext(VectorExecutionOptions options, IList<NArray> independentVarables)
 {
     _executor = new DeferringExecutor(independentVarables);
     _previousExecutor = ExecutionContext.Executor;
     _options = options;
     ExecutionContext.Executor = _executor;
 }
Ejemplo n.º 2
0
 private DeferredExecutionContext(VectorExecutionOptions options, IList <NArray> independentVarables)
 {
     _executor                 = new DeferringExecutor(independentVarables);
     _previousExecutor         = ExecutionContext.Executor;
     _options                  = options;
     ExecutionContext.Executor = _executor;
 }
        private static IList <NArrayOperation> Simplify(DeferringExecutor executor,
                                                        LinearAlgebraProvider provider)
        {
            var operations = new List <NArrayOperation>();

            //operations.AddRange(executor.Operations);
            RemoveUnnecessaryLocals(operations);
            return(operations);
        }
        public static void Execute(DeferringExecutor executor,
                                   LinearAlgebraProvider provider, VectorExecutionOptions vectorOptions)
        {
            //Console.WriteLine(executor.DebugString());
            int chunksLength   = 1000;
            var arrayPoolStack = ExecutionContext.ArrayPool.GetStack(chunksLength);

            while (arrayPoolStack.Count < 10)
            {
                arrayPoolStack.Push(new double[chunksLength]);
            }

            int length = executor.VectorsLength;

            int chunkCount = length / chunksLength;

            if (length % chunksLength != 0)
            {
                chunkCount++;
            }

            //AssignNArrayStorage(executor.LocalVariables.OfType<NArray<double>>(), chunkCount, chunksLength);
            // and integers too?

            var options = new ParallelOptions();

            if (!vectorOptions.MultipleThreads)
            {
                options.MaxDegreeOfParallelism = 1;
            }

            //for (int i = 0; i < chunkCount; i++)
            var operations = Simplify(executor, provider);

            Parallel.For(0, chunkCount, options, (i) =>
            {
                int startIndex = i * chunksLength;
                List <double[]> temporaryArrays = new List <double[]>();
                int vectorLength = Math.Min(chunksLength, length - startIndex);
                foreach (var operation in operations)
                {
                    if (operation is NArrayOperation <double> )
                    {
                        ExecuteSingleVectorOperation <double>(operation as NArrayOperation <double>,
                                                              arrayPoolStack, temporaryArrays,
                                                              vectorLength,
                                                              i, startIndex);
                    }
                }
                foreach (var array in temporaryArrays)
                {
                    arrayPoolStack.Push(array);
                }
            });
            //};
        }