Tuesday, March 17, 2009

.NET Parallel Computation Made Easy : System.Threading.Parallel

I had conduct a simple experiment for some time ago. It's about the performance of .NET program running on a multi-core processor versus the same program running on the single-core one. The result from my experiment shows that if you have a normal .NET program implemented without multi-threading, there will be no significant performance difference between running it on multi-core and single-core system.

I found it hard to create a multi-thread version of my classic old "Prime Generator" program. The hardest part is I don't know the appropiate number of thread to create since I had no information about the system the program is runnning on. And the threading code just looks ugly .. developers with no multi-threading background will find it hard to understand and maintain. Take my old code for example.


The Rescue
This is where Microsoft Parallel Extensions to .NET Framework 3.5 comes in handy. It simplify the process of constructing the multithread code yourself. There are many useful stuffs under System.Threading.Parallel. But I find System.Threading.Parallel.For is the easiest to understand and utilize :)


Here is the plotting between the data set size and time used in millisecond on my machine with Intel(R) Core(TM)2 Duo CPU E6750 @ 2.66GHz. The System.Thread.Parallel.For actually takes extra computation time on the first call which makes me wonder why an ordinary for-loop outperforms parallel version at very first version of my benchmark. However, after the first call, the parallel version outperforms ordinary for-loop as expected.

I believe the results will be different on a quad core machine too :)


Hope this helps.

Tuesday, February 10, 2009

C# Lambda Expression on MonoDevelop and Ubuntu

I always wanted to try out coding C# application on Ubuntu Linux. The most popular IDE of choices for this would be MonoDevelop by Mono Project. I installed MonoDevelop through Synaptic the same way I did with other applications.

It was a surprise to me to found out that Mono even supports some new features from of C# such as Lambda Expression and Object Initializer!


The only problem is their IDE, MonoDevelop, still not support autocompletion (a.k.a. Intellisense) of Lambda Expressions and Object Initializers. Moreover, it marks the code as error by underlining them in red.

In conclusion, Mono looks promising. And I just can't wait to see more Linux people coding new apps in C#!

Sunday, January 18, 2009

Netbeans and Nimbus Theme on Windows Vista



Actually I should name this topic "Netbeans and Nimbus Look & Feel (L&F)" but that would eliminate many search terms that use word "theme" instead :)

To set your Netbeans, in my case it's 6.5, to use the new Nimbus theme, just look under your Netbeans installation folder/etc/netbeans.conf file. It is usually located at C:\Program Files\NetBeans 6.5\etc\netbeans.conf. Then just append --laf Nimbus to netbeans_default_options.

So it looks like this:

...
# command line switches:

netbeans_default_options="-J-Dorg.glassfish.v3.installRoot=\"C:\Program Files\glassfish-v3-prelude\" -J-Dcom.sun.aas.installRoot=\"C:\Program Files\glassfish-v2ur2\" -J-client -J-Xverify:none -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Dapple.laf.useScreenMenuBar=true -J-Dsun.java2d.noddraw=true --laf Nimbus"
# Note that a default -Xmx is selected for you automatically.
...
Then save the file and restart your Netbeans, and proud of your new Netbeans Nimbus theme!

Note:
  • To edit the netbeans.conf file under Windows, you may need editor that capable of editing unix text file. I recommend using Netbeans itself to edit this file instead of Notepad.
  • If you want to change the theme back to default then you can just remove the added options from netbeans.conf file. I recommend you to bookmark this page so you will not forget where to set this option :P
Hope this helps!