程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> 並行計算--C#--求π並行實現

並行計算--C#--求π並行實現

編輯:C#入門知識

using System;
using System.Collections.Generic;

using System.Text;
using System.Diagnostics;
using System.Threading;


namespace Pi
{
    class Program
    {
        static void Main(string[] args)
        {
            double pi_wy, sum_wy = 0.0, seri_t_wy, para_t_wy;
            Stopwatch stopwatch = new Stopwatch();
            Pi_Thread ParallelOne = new Pi_Thread(1);
            ThreadStart StartOne = new ThreadStart(ParallelOne.Pi_paral);
            Thread newThreadOne = new Thread(StartOne);

            Pi_Thread threadTwo = new Pi_Thread(2);
            ThreadStart StartTwo = new ThreadStart(threadTwo.Pi_paral);
            Thread newThreadTwo = new Thread(StartTwo);

            stopwatch.Start();
            newThreadOne.Start();
            newThreadTwo.Start();
            newThreadOne.Join();
            newThreadTwo.Join();
            stopwatch.Stop();

            TimeSpan wy_timeSpan_paral = stopwatch.Elapsed;
            sum_wy = ParallelOne.sum + threadTwo.sum;
            pi_wy = ParallelOne.step * sum_wy;
            para_t_wy = wy_timeSpan_paral.TotalMilliseconds;
            Console.WriteLine("並行結果: " + pi_wy);
            Console.WriteLine("並行
並行
並行結果: 3.141592633590
並行
加速比: 1.94045561251595
						

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved