示例#1
0
    /*
     *  Compute velocity due to vortons, for every point in a uniform grid
     *  This routine assumes CreateInfluenceTree has already executed.
     */
    void ComputeVelocityGrid()
    {
        mVelGrid.Clear();                                // Clear any stale velocity information
        mVelGrid.CopyShape(mInfluenceTree[0]);           // Use same shape as base vorticity grid. (Note: could differ if you want.)
        mVelGrid.Init();                                 // Reserve memory for velocity grid.

        uint numZ = mVelGrid.GetNumPoints(2);

        if (mUseMultithreads)
        {
            // Estimate grain size based on size of problem and number of processors.
            int grainSize = (int)Mathf.Max(1, numZ / numberOfProcessors);

            List <ManualResetEvent> handles = new List <ManualResetEvent>();
            for (var i = 0; i < numberOfProcessors; i++)
            {
                ManualResetEvent handle = new ManualResetEvent(false);
                handles.Add(handle);

                // Send the custom object to the threaded method.
                ThreadInfo threadInfo = new ThreadInfo();
                threadInfo.begin     = i * grainSize;
                threadInfo.end       = (i + 1) * grainSize;
                threadInfo.timeStep  = 0;
                threadInfo.vortonSim = this;
                threadInfo.handle    = handle;

                WaitCallback callBack = new WaitCallback(ComputeVelocityGridSliceThreaded);
                Nyahoon.ThreadPool.QueueUserWorkItem(callBack, threadInfo);
            }

            WaitHandle.WaitAll(handles.ToArray());
        }
        else
        {
            ComputeVelocityGridSlice(0, numZ);
        }
    }