/// <summary>
        /// Performs partitioning
        /// </summary>
        /// <param name="executionPlan">Generic execution plan</param>
        /// <returns>Execution plans for all GPUs</returns>
        public MyExecutionPlan[] Divide(MyExecutionPlan executionPlan)
        {
            MyExecutionBlock.IteratorAction setGpuAction = delegate(IMyExecutable e)
            {
                if (e is MyTask)
                {
                    (e as MyTask).GenericOwner.GPU = selected;
                }
            };

            executionPlan.InitStepPlan.Iterate(true, setGpuAction);
            executionPlan.StandardStepPlan.Iterate(true, setGpuAction);

            MyExecutionPlan[] partitioning = new MyExecutionPlan[numOfPieces];

            for (int i = 0; i < numOfPieces; i++)
            {
                if (i == selected)
                {
                    partitioning[i] = executionPlan;
                }
                else
                {
                    partitioning[i] = new MyExecutionPlan()
                    {
                        InitStepPlan = new MyExecutionBlock()
                        {
                            Name = executionPlan.InitStepPlan.Name
                        },
                        StandardStepPlan = new MyExecutionBlock()
                        {
                            Name = executionPlan.StandardStepPlan.Name
                        }
                    };
                }
            }

            for (int i = 0; i < numOfPieces; i++)
            {
                partitioning[i].InitStepPlan.Name     += " (GPU " + i + ")";
                partitioning[i].StandardStepPlan.Name += " (GPU " + i + ")";
            }

            return(partitioning);
        }
Example #2
0
        private void ExtractPartitioningFromExecutionPlan()
        {
            HashSet <MyWorkingNode>[] indexTable = new HashSet <MyWorkingNode> [ExecutionPlan.Length];
            NodePartitioning = new List <MyWorkingNode> [ExecutionPlan.Length];

            MyExecutionBlock.IteratorAction extractNodesAction = delegate(IMyExecutable executable)
            {
                if (executable is MyTask)
                {
                    MyWorkingNode taskOwner = (executable as MyTask).GenericOwner;
                    indexTable[taskOwner.GPU].Add(taskOwner);
                }
            };

            for (int i = 0; i < ExecutionPlan.Length; i++)
            {
                indexTable[i] = new HashSet <MyWorkingNode>();

                ExecutionPlan[i].InitStepPlan.Iterate(true, extractNodesAction);
                ExecutionPlan[i].StandardStepPlan.Iterate(true, extractNodesAction);

                NodePartitioning[i] = new List <MyWorkingNode>(indexTable[i]);
            }
        }