示例#1
0
        static void ExperimentSimple()
        {
            int matrixSize = ExperimentMatrixSize;

            int processorCount = Environment.ProcessorCount;

            int thresold           = (int)Math.Pow(2, processorCount + 2);
            int currentThreadCount = 1;

            Matrix a = new Matrix(matrixSize, matrixSize);

            Matrix.GenerateRandom(a, 0, matrixSize * matrixSize);

            Matrix b = new Matrix(matrixSize, matrixSize);

            Matrix.GenerateRandom(b, 0, matrixSize * matrixSize);

            SimpleMultiplierParallel parallel = new SimpleMultiplierParallel();

            while (currentThreadCount <= thresold)
            {
                parallel.Process(currentThreadCount, a, b);
                WriteInfo(currentThreadCount, parallel.Ticks);
                currentThreadCount *= 2;
            }

            File.WriteAllLines("simple.txt", _logBuffer);
        }
示例#2
0
        static void TestSimpleParallel()
        {
            Matrix a = new Matrix(TestingMatrixSize, TestingMatrixSize);

            Matrix.GenerateRandom(a, 0, TestingMatrixSize * TestingMatrixSize);

            Matrix b = new Matrix(TestingMatrixSize, TestingMatrixSize);

            Matrix.GenerateRandom(b, 0, TestingMatrixSize * TestingMatrixSize);

            SimpleMultiplierParallel par = new SimpleMultiplierParallel();

            Console.WriteLine("TestSimpleParallel: Using " + Environment.ProcessorCount + " threads.");

            par.Process(Environment.ProcessorCount, a, b);

            bool ok = TestMultipication(a, b, par.Result);

            if (!ok)
            {
                Console.WriteLine("Calculations incorrect! \n" + par.Result.ToString());
            }
            else
            {
                Console.WriteLine("OK");
            }
        }