Esempio n. 1
0
        public override void Run(WaveSpectrumCondition condition, float time)
        {
            if (!this.IsDone())
            {
                throw new InvalidOperationException("Can not run when there are tasks that have not finished");
            }
            base.TimeValue   = time;
            base.HasRun      = true;
            base.BeenSampled = false;
            if (this.EnabledBuffers() == 0)
            {
                return;
            }
            this.Initilize(condition, time);
            if (Ocean.DISABLE_FOURIER_MULTITHREADING)
            {
                this.m_initTask.Start();
                this.m_initTask.Run();
                this.m_initTask.End();
            }
            int num = this.m_buffers.Length;

            for (int i = 0; i < num; i++)
            {
                if (!this.m_buffers[i].disabled)
                {
                    if (this.m_fourierTasks[i] == null)
                    {
                        this.m_fourierTasks[i] = new FourierTask(this, this.m_fourier, i, this.m_initTask.NumGrids);
                    }
                    else
                    {
                        this.m_fourierTasks[i].Reset(i, this.m_initTask.NumGrids);
                    }
                    FourierTask fourierTask = this.m_fourierTasks[i];
                    if (fourierTask.Done)
                    {
                        throw new InvalidOperationException("Fourier task should not be done before running");
                    }
                    if (Ocean.DISABLE_FOURIER_MULTITHREADING)
                    {
                        fourierTask.Start();
                        fourierTask.Run();
                        fourierTask.End();
                    }
                    else
                    {
                        fourierTask.RunOnStopWaiting = true;
                        fourierTask.WaitOn(this.m_initTask);
                        this.m_scheduler.AddWaiting(fourierTask);
                    }
                }
            }
            if (!Ocean.DISABLE_FOURIER_MULTITHREADING)
            {
                this.m_initTask.NoFinish = true;
                this.m_scheduler.Run(this.m_initTask);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates the data for this conditions spectrum for this time value.
        /// </summary>
        public override void Run(WaveSpectrumCondition condition, float time)
        {
            //Can only run if all tasks have finished.
            if (!IsDone())
            {
                throw new InvalidOperationException("Can not run when there are tasks that have not finished");
            }

            TimeValue   = time;
            HasRun      = true;
            BeenSampled = false;

            //If no buffers are enabled nothing to do.
            if (EnabledBuffers() == 0)
            {
                return;
            }

            //Create the Initialization task.
            //This is created by the superclass
            //to the m_initTask object.
            Initilize(condition, time);

            //Must run init task first if mutithreading disabled
            if (Ocean.DISABLE_FOURIER_MULTITHREADING)
            {
                //Multithreading disabled, run now on this thread.
                m_initTask.Start();
                m_initTask.Run();
                m_initTask.End();
            }

            int numBuffers = m_buffers.Length;

            //float t = Time.realtimeSinceStartup;

            //for each buffer run a fourier task.
            for (int i = 0; i < numBuffers; i++)
            {
                if (m_buffers[i].disabled)
                {
                    continue;
                }

                if (m_fourierTasks[i] == null)
                {
                    m_fourierTasks[i] = new FourierTask(this, m_fourier, i, m_initTask.NumGrids);
                }
                else
                {
                    m_fourierTasks[i].Reset(i, m_initTask.NumGrids);
                }

                FourierTask task = m_fourierTasks[i];

                if (task.Done)
                {
                    throw new InvalidOperationException("Fourier task should not be done before running");
                }

                if (Ocean.DISABLE_FOURIER_MULTITHREADING)
                {
                    //Multithreading disabled, run now on this thread.
                    task.Start();
                    task.Run();
                    task.End();
                }
                else
                {
                    //Multithreading enabled, run now on another thread.

                    //If init task has not finished yet the
                    //fourier task must wait on it to finish.
                    task.RunOnStopWaiting = true;
                    task.WaitOn(m_initTask);
                    m_scheduler.AddWaiting(task);
                }
            }

            //Debug.Log("Run Fourier time = " + (Time.realtimeSinceStartup - t) * 1000.0f + " tasks = " + m_fourierTasks.Count);

            //Must run init task last if mutithreading not disabled
            if (!Ocean.DISABLE_FOURIER_MULTITHREADING)
            {
                //Must run init task after tasks the are waiting
                //have been added. Otherwise init task may finish
                //before there other tasks have been added and a
                //exception will be thrown.
                m_initTask.NoFinish = true;
                m_scheduler.Run(m_initTask);
            }
        }