October, 2009

  • Wriju's BLOG

    Parallel Computing: The new “Task” API

    • 0 Comments

    Visual Studio 2010 has new API called ��Task”. This helps us to create small pieces of work and execute in distributed manner under multi core machine. Unlike thread it has flexibility to adopt the lower number of CPU without changing code. With improved CLR thread pool local processes are not confined in local thread pool rather it can leverage the available ppol in the memory. The below I am going to show how traditional Thread and Task works.

    Background

    We have utility function which helps us to iterate through a in memory tree.

    class Tree

    {

        public Tree Left = null;

        public Tree Right = null;

     

        public int Data = 0;

     

        //       1 

        //   2       2

        // 3   3   3   3

        //4 4 4 4 4 4 4 4

     

        internal static Tree CreateSomeTree(int depth, int start)

        {

            Tree root = new Tree();

            root.Data = start;

     

            if (depth > 0)

            {

                root.Left = CreateSomeTree(depth - 1, start + 1);

                root.Right = CreateSomeTree(depth - 1, start + 1);

            }

     

            return root;

        }

    }

     

    Normal Approach

    In 2 CPU machine it takes around 29 sec.

    static void Main(string[] args)

    {

        Tree tr = Tree.CreateSomeTree(9, 1); //Will create 1023 nodes

        Stopwatch sw = Stopwatch.StartNew();

     

        WalkTree(tr);

      

        Console.WriteLine("Elapsed = " + sw.ElapsedMilliseconds.ToString());

        Console.ReadLine();

    }

     

    static void WalkTree(Tree tr)

    {

        if (tr == null) return;

     

        WalkTree(tr.Left);

        WalkTree(tr.Right);

       

        ProcessItem(tr.Data);

    }

           

    static int ProcessItem(int treeData)

    {

        //Just for Demo purposes

        Thread.SpinWait(4000000);

     

        return treeData;

    }

     

    Thread Approach

    Now if we try to implement Thread in Walk tree it would take around 15 sec.

    static void WalkTree(Tree tr)

    {

        if (tr == null) return;

     

        Thread left = new Thread(() => WalkTree(tr.Left));

        left.Start();

     

        Thread right = new Thread(() => WalkTree(tr.Right));

        right.Start();

     

        left.Join();

        right.Join();

     

        ProcessItem(tr.Data);

    }

     

    Task Approach

    The same code using Task API would again take nothing more than 9 sec.

    static void WalkTree(Tree tr)

    {

        if (tr == null) return;

     

        Task left = new Task(() => WalkTree(tr.Left));

        left.Start();

     

        Task right = new Task(() => WalkTree(tr.Right));

        right.Start();

     

        left.Wait();

        right.Wait();

     

        ProcessItem(tr.Data);

    }

     

    The above time will vary based on CPU power and availability.

    Namoskar!!!

  • Wriju's BLOG

    Seven Things to Know about Windows 7

    • 0 Comments

    image

    1) Simple to Use. The Snap feature arranges windows side-by-side by dragging programs. You can then pin your favorite programs to the Windows Taskbar. Finding often-used programs and files is easier with Windows 7. The streamlined user interface includes a cleaner desktop and task bar. Using the Jump Lists feature, you can place the cursor over graphic thumbnails to see a preview of recently viewed files.

    2) Faster. PCs start up and shut down faster by reducing background services. PCs also sleep and resume more quickly. 64-bit editions of Windows 7 take full advantage of the increased RAM and multi-tasking capabilities of 64-bit PCs.

    3) More Reliable. Windows Vista applications or devices should run on Windows 7, and Windows Vista systems will run Windows 7 faster. Battery life also improves with trigger-start services.

    4) Better Compatibility. Windows 7 will considerably reduce compatibility issues seen in previous operating system releases. Built with compatibility issues in mind and through the great work of the Compatibility Assistance Support Team (CAST), existing applications will run on Windows 7.

    5) Easy Web Browsing. Keep track of important information without constantly returning to websites with the Web Slides feature. Bundled with Internet Explorer 8, Web search results will now include pictures and previews allowing for quicker page loads, the ability to view two pages side-by-side if desired, and better security to protect against cyberspace attacks.

    6) More Secure. User Account Controls alert you if an unknown program tries to run on your PC and, unlike Vista, most protection - which includes Windows Defender's anti-spyware software and Windows Firewall - takes place unobtrusively in the background. On a related note, Windows 7’s new backup program makes it easier and more intuitive for users to back up individual files and folders.

    7) The Hub of your Digital Life. Sharing data across all of your PCs and mobile devices will be a lot easier with faster and more reliable synchronization. Also, Windows 7 provides a smooth integration with Windows Live services. For personal, at-home use, the HomeGroup feature is easy to use and takes just found steps to set up a wireless home network.

    Namoskar!!!

  • Wriju's BLOG

    Visual Studio 2010 Beta 2

    • 0 Comments

    I have installed the Beta 2 of Visual Studio 2010. I love its splash screen

    image

    Go get it and enjoy!!!

    Find more information at http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx

    MSDN Subscribers: Download the Beta

    The Visual Studio 2010 and .NET Framework Beta 2 is available to MSDN subscribers on Monday, October 19th, with general availability on October 21st.

    How to Download and Install the Beta

    Are you excited to try Beta 2, but not excited about reading the installation documentation? This video will show you how to download and install Beta 2 of Visual Studio 2010, Team Foundation Server and .NET Framework 4. Start your downloads!

    Featured Overviews and Walkthroughs

    Check out this diverse collection of walkthroughs for Beta 2. They provide step-by-step instructions for common scenarios and are a good place to start learning about Visual Studio 2010 and .NET Framework 4.

    Namoskar!!!

  • Wriju's BLOG

    VB.NET 10 : Array Literals

    • 0 Comments

    VB.NET has another exiting feature which helps us to declare and initialize an array without explicitly specifying the type and dimension. This infers at compile time. Good for Lazy developer like me J

    Dim arrInt = {1, 2, 3, 4, 5, 6, 7} 'becomes Integer()

     

    Dim arrDouble = {1, 2, 3, 4, 5, 6, 7.9} 'becomes Double()

     

    Dim arrString = {1, 2, 3, 4, 5, "Six"} 'becomes String()

     

    Dim arrString2 = {"One", "Two", "Three"} 'becomes String()

     

    Dim arr2D = {{1, 2, 3}, {4, 5, 6}} 'becomes Integer(,)

    Namoskar!!!

  • Wriju's BLOG

    VB.NET 10 : Nullable Optional Parameter

    • 0 Comments

    You can create method with optional parameter and also make them Nullable.

    Optional with default value

    Sub Test(ByVal _name As String, ByVal _email As String, Optional ByVal _age As Integer = 30)

     

    Optional and Nullable

    Sub Test(ByVal _name As String, ByVal _email As String, Optional ByVal _age As Integer? = Nothing)

    Similarly you also may initialize the collection like Dictionary.

    Namoskar!!!

  • Wriju's BLOG

    VB.NET 10 : Collection Initializer

    • 1 Comments

    Another useful feature which was missing in VB.Net 9 is available in Visual Studio 2010. This provides option to declare and initialize with series of values with the keyword Form.

    Dim myList As New List(Of Integer) From {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

     

    For Each i In myList

        Console.WriteLine(i)

    Next

    Similarly you also may initialize the collection like Dictionary.

    Dim myDic As New Dictionary(Of Integer, String) From {{1, "One"}, {2, "Two"}}

    Namoskar!!!

Page 1 of 1 (6 items)