private void ExecuteCore(int coreNumber)
        {
            try
            {
                if (InDebugMode)
                {
                    MyExecutionBlock currentBlock = CurrentDebuggedBlocks[coreNumber];

                    if (SimulationStep == 0 && currentBlock == null)
                    {
                        ExecutionPlan[coreNumber].InitStepPlan.Reset();
                        currentBlock = ExecutionPlan[coreNumber].InitStepPlan;
                        m_debugStepComplete = false;
                    }

                    MyExecutionBlock lastBlock = null;

                    do
                    {
                        lastBlock = currentBlock;
                        currentBlock.SimulationStep = SimulationStep;
                        currentBlock = currentBlock.ExecuteStep();
                    }
                    while (currentBlock != null && currentBlock.CurrentChild == null);

                    if (currentBlock == null)
                    {
                        ExecutionPlan[coreNumber].StandardStepPlan.Reset();
                        currentBlock = ExecutionPlan[coreNumber].StandardStepPlan;
                    }
                    else
                    {
                        m_debugStepComplete = false;
                    }

                    CurrentDebuggedBlocks[coreNumber] = currentBlock;
                }
                else //not in debug mode
                {
                    if (SimulationStep == 0)
                    {
                        ExecutionPlan[coreNumber].InitStepPlan.SimulationStep = 0;
                        ExecutionPlan[coreNumber].InitStepPlan.Execute();
                    }

                    //TODO: here should be else! (but some module are not prepared for this)
                    ExecutionPlan[coreNumber].StandardStepPlan.SimulationStep = SimulationStep;
                    ExecutionPlan[coreNumber].StandardStepPlan.Execute();
                }
            }
            catch (Exception e)
            {
                m_errorOccured = true;
                m_lastException = new MySimulationException(coreNumber, e.Message, e);

                MyKernelFactory.Instance.MarkContextDead(coreNumber);
            }
        }
        // TODO(HonzaS): The coreNumber parameter is not needed, remove it with the StarPU merge.
        private void ExecutePlan(int coreNumber)
        {
            try
            {
                if (InDebugMode)
                {
                    ExecuteDebugStep();
                }
                else
                {
                    ExecuteFullStep();
                }
            }
            catch (Exception e)
            {
                m_errorOccured = true;

                if (e is MySimulationException)
                {
                    m_lastException = e;
                }
                else
                {
                    m_lastException = new MySimulationException(e.Message, e);
                    MyKernelFactory.Instance.MarkContextDead(0);
                }
            }
            finally
            {
                IsStepFinished = m_stepComplete;
            }
        }
        private void ExecuteCore(int coreNumber)
        {
            try
            {
                if (InDebugMode)
                {
                    MyExecutionBlock currentBlock = CurrentDebuggedBlocks[coreNumber];

                    if (SimulationStep == 0 && currentBlock == null)
                    {
                        ExecutionPlan[coreNumber].InitStepPlan.Reset();
                        currentBlock = ExecutionPlan[coreNumber].InitStepPlan;
                        m_debugStepComplete = false;
                    }

                    bool leavingTargetBlock = false;

                    do
                    {
                        currentBlock.SimulationStep = SimulationStep;
                        currentBlock = currentBlock.ExecuteStep();
                        if (StopWhenTouchedBlock != null && currentBlock == StopWhenTouchedBlock)
                            leavingTargetBlock = true;
                    }
                    while (currentBlock != null && currentBlock.CurrentChild == null);

                    if (currentBlock == null)
                    {
                        ExecutionPlan[coreNumber].StandardStepPlan.Reset();
                        currentBlock = ExecutionPlan[coreNumber].StandardStepPlan;
                        leavingTargetBlock = true;
                    }
                    else
                    {
                        m_debugStepComplete = false;
                    }

                    CurrentDebuggedBlocks[coreNumber] = currentBlock;

                    if (DebugStepMode != DebugStepMode.None)
                    {
                        // A step into/over/out is performed.
                        if (leavingTargetBlock)
                            // The target block is being left or the sim step is over - step over/out is finished.
                            EmitDebugTargetReached();

                        if (DebugStepMode == DebugStepMode.StepInto)
                        {
                            // Step into == one step of the simulation.
                            EmitDebugTargetReached();
                        }
                    }

                    if (Breakpoints.Contains(currentBlock.CurrentChild))
                        // A breakpoint has been reached.
                        EmitDebugTargetReached();
                }
                else //not in debug mode
                {
                    if (SimulationStep == 0)
                    {
                        ExecutionPlan[coreNumber].InitStepPlan.SimulationStep = 0;
                        ExecutionPlan[coreNumber].InitStepPlan.Execute();
                    }

                    //TODO: here should be else! (but some module are not prepared for this)
                    ExecutionPlan[coreNumber].StandardStepPlan.SimulationStep = SimulationStep;
                    ExecutionPlan[coreNumber].StandardStepPlan.Execute();
                }
            }
            catch (Exception e)
            {
                m_errorOccured = true;

                if (e is MySimulationException)
                {
                    m_lastException = e;
                }
                else
                {
                    m_lastException = new MySimulationException(coreNumber, e.Message, e);
                    MyKernelFactory.Instance.MarkContextDead(coreNumber);
                }
            }
        }