Monday, November 23, 2009

Parallel computing on Windows

With the advent of the multicore world the need for parallelism increased a lot. Until now one way to improve the application performance was to increasing the CPU clock speed. Because of some hardware limitation is very hard for hardware vendors to increase the CPU clock speed but instead they can add more and more cores to CPUs. At this moment most of the laptops and desktop computers have CPUs with 2 cores at least.

A trivial e.g. of code that can be executed on more CPUs:

1. c -> a and b
2. if (c is bigger than 0)
3. foreach( i to c)
Compute(module(i))

Let's say that we have a computer with a CPU that has 256 cores. If we can use all the cores and execute Compute(module(i)) on each core at any given moment you will have a major performance improvement. Having a CPU with 256 cores can sound a bit ridiculous but let’s look at the history. In 1995 the fastest computer was an IBM machine with 512 CPUs and weights a few tons also the power consumption was very high. At this moment a high-end GPU has the same computation power like that IBM machine and this happen only in 16 years.

In the new version of .NET Framework Microsoft added new classes to have support for multicore called Task Parallel Library. This TPL exposes parallel constructs For and ForEach loops using the regular methods and delegates. Writing multithread application is quite a challenging task; the most notorious problem is the deadlock when 2 threads wait each other to release a resource.

Prior to Windows Server 2008 and Windows 7 at the OS level only 64 cores are supported and that mainly because of a "hot" lock called Dispatcher Lock. What is this lock and why is "hot"? In order for a thread to be executed by the CPU it needs to acquire this lock. When you have a relative small number of cores the CPU contention is not very high. If the number of core grows then you will have a lot of cores that they will try to acquire this lock.

If the lock is not acquired the core will spin and do nothing. The NT kernel was design by David Cutler and when the kernel was design having more the 16 cores on a CPU were more like Sci-Fi. Arun Kishan, a kernel developer, took this issue as a side project and manages to remove this lock and he replaces it with a much finer synchronization primitives and now Windows Server 2008 and Windows 7 can scale up to 256 core. This is a very good news for everyone that creates threads.

There are some cases when having multiple threads on a machine with just one core can be a good thing. Why is that? Because in some cases you can have a thread doing some IO operation that can take long if your harddrive is fragmented (there is a lot of seeking) and all this time the CPU will spin and do nothing. As a rule of thumb when you have a case like in my small e.g. with the Compute(module(i)) try to use ThreadPool or TPL. ThreadPool is able to reuse threads inside the pool, TPL is more advanced and it will be part of .NET 4.0. It has concepts like work stealing, worker thread local pool, scheduling groups of actions.


The material prepared by Stefan Tabaranu

Bookmark and Share

Tuesday, November 3, 2009

Weekly Wrap-up. Windows 7's usage jumps by 40%, but overall Microsoft's share continue to drop

According to Web measurement company Net Applications the share of new Microsoft OS has jumped by 40% in the week following its release.


While overall Windows OS's share continue to decline, dropping 0.23 of a percentage point in October, Windows 7 share jumped by more than 39% and averaged 2.66% for week after its release. The highest rate Windows 7 reached on Saturday, October 31 averaging 3.48% that represented even larger 82% increase. However, for the whole month the system ended up with a market share of 2.15%, which is 41% more than 1.52% of September figures. According to Net Applications one in every 44 PCs run Windows 7 last month.

But, such a rapid increase might be due to excess usage of spurious copies in Russia and Eastern Europe countries, Net Applications said. Of the top 25 countries by usage, 17 are in Eastern Europe. Slovenia in the lead with 7.8% of all computers ran Windows 7 last month, number 3 is Lithuania with 6.5% following by Romania with 6% of all computers used Windows 7.

According to the Business Software Alliance, an industry-backed anti-piracy organization the piracy rate in Central and Eastern Europe was the highest in global perspective in 2008. The percentage of all properly licensed software used in Slovenia averaged 47% last year, which is more than double the rate in the U.S. Lithuania, Romania, Latvia and Russia with 54%, 66%, 56% and 68% respectively.

Although, Microsoft Corp places great hopes on Windows 7, which already gained some reputation, the overall Windows share continue to drop. Microsoft's most popular OS ever lost 0.64% on average during past year, failing to 70.6% while its another product a widely-criticized Vista lost market share in September for the first time in almost two years. The main recipient of former Microsoft users is Apple. Its Mac OS X operating system share climbed by 0.15% at the end of October averaging 5.27% setting a new record for Apple.