Wednesday, August 19, 2009

LGPL Python binding for Qt backed by Nokia released

That’s right, just yesterday the first version of the PySide project was released.
The PySide project “provides LGPL-licensed Python bindings for the Qt cross-platform application and UI framework”.

As you may already know, some months ago Nokia acquired Trolltech, the makers of the Qt cross platform UI framework and made it
available under the LGPL license. That made a lot of people think of Qt again, and think about switching to it,
now that it comes with this liberal license.
One little problem remained, however (at least for the many people that use Python out there). The nice PyQt binding was still dual licensed with either a non free commercial license or a GPL one.
There were some people that asked the makers of the PyQt python bindings if they were going to provide an LGPL licensing option. Many people thought that it is natural that there will be an LGPL licensed Python binding for Qt sooner or later. And if that was not going to be PyQt then the community was going to make a new one. Even Nokia considered PyQt, but as described in the PySide FAQ “common agreement could not be found”.

Well, it seems that the guys at Nokia, like the Python community, thought that they need an LGPL licensed Python bindings for Qt. After doing some research, they “decided that building our own bindings was the best option”.

Currently the bindings are available only for Linux, but the project “aims to support all the platforms Qt does”. The PySide FAQ is an interesting read if you have questions about the project and Nokia’s involvement in it (as I’m sure you have).

Now we only need someone to make PySide available for Windows (and other platforms of course:)).

Will Qt become the standard for cross platform development of the open source world?

Monday, July 27, 2009

Returned home after a week at the EEC

IMG_0133 I know, I know that quite a long time has passed since my last post. But I have a reason.

Just a week ago I returned from a visit at the Microsoft EEC, where I had one of the most interesting experiences in my life. You may not remember, but in my opening post I wrote about me and my team winning the Imagine Cup 2008 competition. You can freely skip this post. There is actually not anything interesting in it except a link to the Lego Technic set I found in Paris. Oh and form Redmond I got another one. Ok, ok, I will cut to the point, we can talk about Lego later.

So the reason for all the silence on my blog lately is that I was busy working on my Imagine Cup project “EOS.NET” (sorry, no link here, hope to have one soon).

Shameless plug: EOS.NET is a modular system (of course MEF is used for the “modular” part) that can process satellite data from multiple satellites (currently NASA MODIS) and look for interesting events, like for example fires and deforestation (and in the future oil spill in the oceans, floods and what not). And yes it can send emails when such an event is discovered. It can also do many other interesting things but I will keep these as a surprise for now.

 

 

The main functionality that we had to work on was to make the thing run on a Microsoft Windows HPC cluster. We had to to that, so that when time comes to collect our prize and go the the Microsoft Enterprise Engineering Center (EEC) we are able to use this baby:

IMG_9292

This is a 32 compute node cluster, and even though it is not the biggest cluster on Earth (there is another much bigger cluster at the EEC, I hope that I will get to use it next time) it can help you process your data many times faster. Oh, and with the latest version of the Windows HPC stack you do not even have to write complex MPI applications. With the new SOA model, if you know WCF you will be able to relatively easy write scalable HPC applications that can run on powerful clusters.

Of course we had some issues with our system at the beginning – a completely normal thing given the fact that we were not able to test on a real cluster before. But after some work we had amazing results – the data processing was orders of magnitude faster compared to when the application processes the data locally. One can easily imagine how the system will easily process data for the whole world and from different satellites at the same time using a large enough cluster.DSC02784

After things settled a bit (although work continued with fast pace until the end of the week) and EOS.NET was able to run successfully on the cluster I even had a little time to play with the Microsoft Surface they had at the EEC. It’s really fun, you should try too:) I hope that soon these devices will be cheap enough so that everyone can afford them.

 

Generally the time that I spent at the EEC and at the Microsoft campus in Redmond was wonderful and I will remember it for many years.That was all for now. See you soon.

Friday, July 10, 2009

Silverlight 3 RTW available for download

The much awaited release of Silverlight 3 is now available for download at:

http://silverlight.net/GetStarted/

If you haven’t already, you can learn more about the new features in this release in Tim’s guide here. There is also a overview which compares the different Silverlight versions.

So, go play with the new bits. And don’t forget to share which are your favorite features in this new release.

Sunday, March 29, 2009

Precode plugin for Live Writer now has support for SyntaxHighlighter 2.0

I wrote about the excellent Precode plugin for Windows Live Writer in this blog post. Until recently there was no support for Syntaxhighlighter 2.0 and after inserting a snippet with Precode I had to manually modify the generated HTML. Finally, support for Syntaxhighlighter 2.0 was added with the just released version 4.0.2 and this inconvenience is now gone.

This new release also includes a standalone desktop application that will allow you to paste formatted code in other applications:

precode_desktop

NOTE: This release of Precode only has support for Syntaxhighlighter 2.0.

Now, go get Precode.

Saturday, March 21, 2009

Using the Silverlight Charting control with WPF

You have probably already seen the great charting control that is part of the Silverlight Toolkit. I don’t know for you, but I have on many occasions looked at these beautiful charts with envy. And really, who doesn’t want to have impressive charts in his application these days. And I wondered if I could use these nice charts in my WPF applications. The first idea that occurred to me was that I could host a Silverlight application in my WPF application using the WebBrowser control. However, this approach seemed somewhat hacky to me so I started looking if I could build the Silverlight charting control against WPF. It seems, however that the guys from the Silverlight team had also thought of that and they even have their daily builds setup to build the Silverlight charting against WPF.

So here is Delay’s chart builder sample that you have already probably seen running on Silverlight, but this time running on my desktop with WPF:

ChartBuilder

The sample includes all assemblies necessary.

You should note that to use the Silverlight charting control with WPF you must have a reference not only to the DataVisualization assembly, but to the WPFToolkit assembly or you will get some strange errors. This is because the control uses the the Visual State Manager that is being ported to WPF.

Happy charting.

Thursday, February 19, 2009

Using SyntaxHighlighter with Live Writer

After trying some other Windows Live Writer plug-ins without much success (as you can see from my previous post) I finally found the SyntaxHighlighter which is really great. The new version has support for blogger through the bloggerMode setting and is also kindly hosted by Alex (the creator of SyntaxHighlighter) so that you do not need to host it yourself. An excellent blog post that explains how you can enable SyntaxHighlighter for your Blogger blog can be found here.

There is also a  plug-in for WLW named Precode that has excellent support for SyntaxHighlighter and also looks quite nice:

precode

EDIT: It seems that the Precode plug-in does not have support for the latest version of SyntaxHighlighter and I has to manually edit the generated HTML and add “brush: ” before c#  in the pre tag.

So I can finally have my snippets here beautifully formatted like this:

[TaskCapabilities(IsSpecial = true)]
[ExportMetadata("IsSpecial", true)]
[Export(typeof(ITask))]
public class AnotherTask : ITask
{
#region ITask Members

public bool Process(string input)
{
Console.WriteLine("Another task");
return true;
}

#endregion
}

May the syntax-highlighter be with you!

Wednesday, February 4, 2009

Virtual methods, interfaces and the strategy pattern

The other day while refactoring some code that was called quite often I thought “Oh, this looks like a candidate for a strategy”. Here is a simplified version of the code:

   1: int a = 0;
   2: for (int i = 0; i < count; i++)
   3: {
   4:     if (this.SomeBoolProperty)
   5:     {
   6:         a += 2;
   7:     }
   8:     else
   9:     {
  10:         a += 1;
  11:     }
  12:     //a += (this.SomeBoolProperty) ? 2 : 1;
  13: }


And what I wanted to do is something like:

   1: public virtual bool SomeBoolProperty
   2: {
   3:     get
   4:     {
   5:         return this.boolValue;
   6:     }
   7:     set
   8:     {
   9:         if (this.boolValue != value)
  10:         {
  11:             this.boolValue = value;
  12:             if (this.boolValue)
  13:             {
  14:                 this.calculatorVirtual = new TrueCalculator();
  15:             }
  16:             else
  17:             {
  18:                 this.calculatorVirtual = new FalseCalculator();
  19:             }
  20:         }
  21:     }
  22: }
   1: int a = 0;
   2: ParameterClass param = new ParameterClass();
   3: for (int i = 0; i < count; i++)
   4: {
   5:     a += this.calculatorVirtual.TestMethod(param);
   6: }

I was just about to start refactoring that piece of code into a couple of little strategy classes when my inner voice asked: “Wait, will it really be more effective?”. Why is this you ask. Because virtual method calls can be expensive, and if statements are supposed to be cheap.

But I didn’t stop there, I wanted to know just how much each option would cost me. And I prepared a simple program to test the two options. I even added a third option. I thought “If virtual method are so expensive, let’s not use them, we’ll use interfaces and the problem will be gone.” Interfaces don’t need virtual methods to work and so there won’t be any virtual tables involved, right? It turned out that I couldn't be more wrong.

The results speak for themselves:

PerformanceTest

It turns out that just adding the virtual keyword before a method or a property makes it’s call about three times more expensive. The other interesting thing is that interface method calls are about 1,5 times more expensive than virtual method calls. Even though the IL code that is generated is the same. I wonder what is the reason for this.

Here is the code that starts the tests, in each test method there is code similar to the code above, count = 100 000 000:

   1: private TestClass testClass = new TestClass();
   2:  
   3: private void btnTestIf_Click(object sender, EventArgs e)
   4: {
   5:     this.RunTest(new Action(this.testClass.RunIfTest), this.lblTimeIf);
   6: }
   7:  
   8: private void btnTestVirtualIf_Click(object sender, EventArgs e)
   9: {
  10:     this.RunTest(new Action(this.testClass.RunVirtualIfTest), this.lblTimeVirtualIf);
  11: }
  12:  
  13: private void btnTestVirtual_Click(object sender, EventArgs e)
  14: {
  15:     this.RunTest(new Action(this.testClass.RunVirtualTest), this.lblTimeVirtual);
  16: }
  17:  
  18: private void btnTestInterface_Click(object sender, EventArgs e)
  19: {
  20:     this.RunTest(new Action(this.testClass.RunInterfaceTest), this.lblTimeInterface);
  21: }
  22:  
  23: public void RunTest(Action testMethod, Label label)
  24: {
  25:     int start = Environment.TickCount;
  26:     testMethod();
  27:     int end = Environment.TickCount;
  28:  
  29:     label.Text = string.Format("{0} ms", (end - start).ToString());
  30: }

Finally, here are my key take aways:

  1. Use the virtual keyword wisely. Only when you need it.
  2. Use base classes with virtual methods. Especially if you have some common logic that you can put in the base class.
  3. In most cases replacing a sequence of if statements that is used in many places with a strategy / template method is worth it because it makes the code much more cleaner, easier to understand and change.

That was all for now, see you next time

Yordan, the curious

Sunday, January 11, 2009

Application models for Windows HPC Server 2008

There are two application models that you could use to write parallel programs that run on a Window HPC Server 2008 cluster.The first is the more classical MPI model. This model has been used for quite some time not only on the Windows platform but also on various other platforms like Linux and flavors of BSD. However in the 2008 version of Windows HPC Server some nice improvements were made that allow for 30% increase in effectiveness compared to the previous version (which I think was named Windows Compute Cluster 2003) which is very impressive.

If you want to know more about the MPI application model I recommend that you take a look at the Windows HPC Server 2008 - Using MS-MPI white paper and also watch that video on channel 9.

There is also the newly introduced WCF based, SOA application model which allows you to write your parallel applications using your favorite managed language (like for example C#) and WCF in Visual Studio.

Again, if you want to know more you can take a look at the Overview of Service-Oriented Architecture Programming Model and Runtime System for Windows HPC Server 2008 white paper and watch this video at channel 9.

There are also other white papers and more videos.

But how to decide which of the two models to use? Besides, of course your preference of C# over C, or WCF over MPI. Well, if your parallel algorithms are such that the worker processes need to communicate with one another you will most probably need to use the MPI model. However, if they are of the embarrassingly parallel kind you could take advantage of the new SOA model.