Saturday, February 28, 2015

The Parallel For (In Console)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TheParalleFor
{

    class Program
    {
        static void Main(string[] args)
        {
            //class Exercise # 1
        //Class Exercise For Tuesday,24,2015
        //Main method 

            //we use the method from last exercise
            Parallel.For(1, 5001, root =>//we use the lambda expression
                {
                    int j = root; //j is share from the root
                    double result = 0;
                    for (int i = 1; i < 1000; i++)
                    {
                        result += Math.Exp(Math.Log(i) / root);
                    }
                    Console.WriteLine("index:{0} TaskID:{1}  result:{2}", j.ToString().PadRight(4),Task.CurrentId, result);
                });
            Console.ReadKey();
        }
    }
}

No comments:

Post a Comment