Example #1
0
        public void ParralelOwnForTransformation(int threads = 0)
        {
            if (threads == 0)
            {
                threads = Environment.ProcessorCount;
            }

            ParallelProcessor.ThreadsCount = threads;
            ParallelProcessor.For(0, size, delegate(int i)
            {
                for (int j = 0; j < size; ++j)
                {
                    if (areNeighbours(i, 0))
                    {
                        Coord elem = new Coord(i, 0);
                        this.Dependency(elem);
                    }
                }
            });
        }
        public static void For(int start, int stop, ForLoopBody loopBody)
        {
            lock (sync)
            {
                ParallelProcessor instance = Instance;

                instance.currentIndex = start - 1;
                instance.stopIndex    = stop;
                instance.loopBody     = loopBody;

                for (int i = 0; i < threadsCount; i++)
                {
                    instance.threadIdle[i].Reset();
                    instance.jobAvailable[i].Set();
                }

                for (int i = 0; i < threadsCount; i++)
                {
                    instance.threadIdle[i].WaitOne();
                }
            }
        }