Featured Post

2005… Looking Back…

Should I say this was quite a eventful year! I don’t know… !! But, A Year Where I’ve met so many new faces across the world, from the sweetest of all to the scariest of all to the charismatic of all… A Year filled with travel, almost every weekend or alternate I was traveling… A...

Read More

Parallel Programming in C# 4.0 using Visual Studio 2010

Posted by Logu Krishnan | Posted in C#, Parallel Programming | Posted on 09-06-2009

Tags: ,

1

Downloaded Visual Studio 2010 Beta 1 yesterday and as I was glancing through it strike to me that this version is stuffed, unless the previous two predecessors VS2005 & VS2008.
Framework has been more enhanced and visual studio IDE itself have got overhauled a bit. Well, I’m not going to give you a list of ALL features – it’s been blogged already around the world. Better Google it or Bing it with “VS2010+Features”

However, few notable features that caught my eyes are “Parallel Programming”, “F# - Functional Programming”, “Velocity – Distributed Caching”, “Azure Tools” and more important of all the evolving Team system.

But I first wanted to dirt my hand with Parallel Computing, because if you are a computer science student – well, you would be more excited about this than others.
Remember the big pillow sized books that we used to read to make this work? Well, things have changed and world have shrunk already. Though I cannot explain all the nitty gritty of parallel programming I will try this to explain in LAY MAN Terms.

Well, during the Stone Age [!] - Most of the computers in the world had only ONE Processors, except those big beasty servers which are always locked up in rooms with high security (well, usually *nix or Solaris servers) – these beasty servers used to manage most of the corporations. These servers had multiple processors and it took huge efforts to write software’s and manage them.

Welcome to the modern world – Every household and every laptop being sold these days at least have two or more processors.

Now – that has posed us a BIG Question? Hardwares have evolved, but has our software evolved to execute on multiple processors? – The answer is NO. At least not in the mainstream programming world – let’s say for example what would happen

  1. If we execute a simple FOR Loop
  2. That would call a service (that takes a longer time)
  3. … and execute sequentially for N Times

On a single processor this is acceptable and we might use threads to increase the efficiency.

Is this still acceptable on a multiple processors? The answer is no. Fine, but how do we get efficiency without the hurdles of running and managing too many threads? Shouldn’t there be an easier way out for this?

Alrighty, without much ado, let me show you how easy(!) this is and a little insight on what happens behind the scenes. Let’s churn out a quick code here based on the same questions we have. Let us say a real long process (Well it could be about counting the stars in the UniverseJ, huh) and let us say you want to do this N times.

In our quest to count all the stars in the universe, let’s first create a data structure for the star and add to the universe, and let us use the good ol` mother of all loops the “FOR” Loop, and see how much inefficient this loop has become these modern days!!

 

“The Sequential execution took almost 30 seconds in my Dual Core Computer.”

And here is the Parallel Computing version of the same method. Yes, the for loop has been replaced with Parallel.For a new entry in System.Threading namespace.
How simpler can this get to?

VOILA! The Parallel execution took Just 3 Seconds in my Dual Core Computer.

Well, That’s a significant performance improvement without Hardware Scale-out or Scale-up, all we are doing is using the existing hardware resource efficiently. So much to a FOR Loop J, Huh. 30 Seconds of execution have become 3 seconds instantly. Look closer to the screenshot – the stars are not counted sequentially, instead it allocates the task to the available CPU in parallel.

Because the loop is run in parallel, each iteration is scheduled and run individually on whatever core is available. This means that the list is not necessarily processed in order, which can drastically impact your code. You should design your code so that each iteration of the loop is completely independent from the others. Any single iteration should not rely on another in order to complete correctly.

Let us catch up more on the insights soon on next part of the same series…

  • Share/Save/Bookmark

PERFORMANCE Code Killer – Unaligned Memory - C# Structs

Posted by Logu Krishnan | Posted in C#, Performance | Posted on 24-02-2009

Tags: ,

0

Recently I was analyzing a .NET Application for performance which had lots of structs defined in it, and happened to hit a strange reality. Unaligned Memory problem!
I was running a profiler, and found that the memory allocated for few structs are huge than it should normally allocate (based on my own math of counting the bytes). When I probed further, there was an interesting discovery. Read on…

Alright here is a little head spinner… What is the difference between the following structures?

struct BadStructure
{
char c1;
int i;
char c2;
}

struct GoodStructure
{
int i;
char c1;
char c2;
}

Nothing much, except the jumbled type declarations… Huh?

Fine, Now let’s look at the size of these structures,

The size of BadStructure Structure in:
.NET Framework 3.5 : Managed sizeof= 12 Bytes, Marshal.Sizeof = 12 Bytes

The size of GoodStructure Structure in:
.NET Framework 3.5 : Managed sizeof= 8 Bytes, Marshal.Sizeof = 8 Bytes

[Note: Size of int=4, char=2]

The Reason behind these differences is “BYTE ALIGNMENT”, As with the default packing in unmanaged C++, integers are laid out on four-byte boundaries, so while the first
character uses two bytes (a char in managed code is a Unicode character, thus occupying two bytes), the integer moves up to the next 4-byte boundary, and the second character uses the subsequent 2 bytes. The resulting structure is 12 bytes when measured with Marshal.SizeOf.

32 bit microprocessors typically organize memory as shown below.


        Byte0  Byte1  Byte2 Byte3

0×1000

0×1004   A0     A1     A2     A3

0×1008

0×100C          B0     B1     B2

0×1010  B3

Most of the processer architectures cannot read data from odd addresses.
Processor Architectures are inefficient in reading the data if it starts at an address not divisible by four.
Memory is accessed by performing 32 bit bus cycles. 32 bit bus cycles can however be performed at addresses that are divisible by 4. So for efficiency purposes, compilers add the so-called pad bytes. The reasons for not permitting misaligned long word reads and writes are not difficult to see. For example, an aligned long word A would be written as A0, A1, A2 and A3.

Thus the microprocessor can read the complete long word in a single bus cycle. If the same microprocessor now attempts to access a long word at address 0×100D, it will have to read bytes B0, B1, B2 and B3. Notice that this read cannot be performed in a single 32 bit bus cycle. The microprocessor will have to issue two different reads at address 0×100C and 0×1010 to read the complete long word. Thus it takes twice the time to read a misaligned long word.

The following byte padding rules will generally work with most 32 bit processor.
a. single byte numbers can be aligned at any address
b. Two byte numbers should be aligned to a two byte boundary
c. Four byte numbers should be aligned to a four byte boundary

This is the cause of the difference.
Fine…. How do we fix this ?

the .NET compilers all apply a StructLayoutAttribute to structures, specifying a Sequential layout. This means that the fields are laid out in the type according to their order in the source file.

Here is the IL.

.class nested private sequential ansi sealed beforefieldinit BadValueType

extends [mscorlib]System.ValueType
{
.field public char c1
.field public char c2
.field public int32 i
}
In the .NET Framework 3.5, the JIT does enforce a Sequential layout (if specified) for the managed layout of value types,
We can use the System.Runtime.InteropServices namespace and the StructLayoutAttribute class to control the physical layout of the data fields in the Microsoft .NET Framework 3.5.
Fix = specify [StructLayout(LayoutKind.Sequential, Pack = 1)] for the struct.

Watchout for structures when you create them next time, and think about playing around with ‘m’ structures with ‘n’ size…. m x n = !!!

  • Share/Save/Bookmark

Session on WPF for Chennai .NET UG

Posted by Logu Krishnan | Posted in MVP, Microsoft | Posted on 16-07-2007

Tags: , ,

0

I’m planning to do a new session on Windows Presentation Foundation [WPF] this weekend.

If you are interested register @ http://groups.msn.com/chennainetusergroup/july21stsessionregistration.msnw

 

Madhu [Solutions Architect from Polaris Labs] is doing session on Windows Communication Foundation [WCF] on the same day.

  • Share/Save/Bookmark

THERE IS ONLY ONE OF US :: Space - Time Continuum

Posted by Logu Krishnan | Posted in Ramblings | Posted on 11-03-2007

0

 

But… if everything has already happened, then it follows that I am Powerless to change my future. Is this predestination ?

No! Don’t buy into that! That is not true. In fact, this “Set Up” should serve you, not disserve you!

You are always at a place of free will and total choice. Being able to see into the “future” (or get others to do it for you) should enhance your ability to live the life you want, not limit it…

But how can I avoid that which has already happened ?

 It has not happened to you - yet! You are at a place in the Space-Time Continuum where you are not consciously aware of the occurrence. You do not “know” it has “happened”. You have not “remembered” your future! (This forgetfulness is the secret of all time. It is what makes it possible for you to “play” the great game of life! I’ll explain later!)

 What you do not “know” is not “so” Since “you” do not “remember” your future, it has not “happened” to “you” yet! A thing “happens” only when it is “experienced”. A thing is “experienced” only when it is “known”.

 

Now let’s say you’ve been blessed with a brief glimpse, a split-second “knowing” of your “future”. What’s happened is that  your spirit - the nonphysical part of you-has simply sped to another place on the Space-Time Continuum and brought back some residual energy-some images or impressions-of that moment or event.

These you can “feel” or “see” these images and energies that are swirling about you.

 

If you don’t like what you “sense” about your “future”, step away from that! Just step away from it! In that instant you can change your experience-and every one of you breathes a sigh of relief!

Wait a minute! Whoa—?

You must know-you are now ready to be told-that you exist at every level of the Space-Time Continuum simultaneously.

 

That is, your soul Always was, Always Is, and Always Will Be - World without end - Amen..

 …
 …

 

It is all contained in a single truth:

THERE IS ONLY ONE OF US.

 

– excerpt from “Conversations With God” by Neale Donald Walsch

  • Share/Save/Bookmark

Paradoxical human lives…

Posted by Logu Krishnan | Posted in Personal, Ramblings | Posted on 12-08-2006

0

Early Today I was sipping my Morning juice and hopping at all the blogs after a long time and heard a knock on the door, when I opened the door there was a very old man with a file accompanied by a guy who looked bit young. The old man wished me[!] “Sir…” and introduced that he works for some temple in west mambalam and that’s his son.

I saw him with a “So what?” look… He opened the file and showed the 12th grade mark sheets of his son and some identification proofs, and this guy has scored 1150/1200 and the man continued that now he needs to pay Rs.11,500 but couldn’t afford the amount!!!

For a moment I thought this is yet another phony trick, but when I looked deep into this guy… for some reason I happened to see myself few years back… during my B.Tech days at coimbatore … standing in front of my CC’s office for a default of 750 rupees for a monthly 1500 fee! That’s when life had twisted me up side down and pushed me to the edges and happened to see all the faces of humans… I was very young and immature those days.

That month I had to pick up a 2nd part time job on the same month, where the 1st job gave me just 750 bucks!! Though these days I earn x times more than that, even a single rupee was very valuable those days… and that’s when I learnt how a one rupee can make a lot of difference. I also learnt that dinner could be finished in 1 rupee… And that’s when life teached me money definitely matters than human values!! And that’s the same time I started to disrespect money!!

Now I see someone in front of me in a similar state!!!! I didn’t think much about fraud and gave them some money and immediately the old man asked “do you…… have any…… old clothes……?” by then, I could see some tears and his eyes filled with inability as a father!!! I gave them that I could give…

Finally the old man blessed and went to the next flat.

Hmm… I dunno why… but I see lots of different people these days with entirely different perceptions towards life…these days…

Yep, I’ve to admin I was disturbed a bit… 

 

Paradox! Paradox! Paradox… world…

 

“I, for one, will never believe

 That god plays dice with the universe…”

“Come on, what could happen? So you die a little…”

  • Share/Save/Bookmark

Real…Unreal…!!

Posted by Logu Krishnan | Posted in Personal, Ramblings | Posted on 27-07-2006

Tags: ,

0

“that Sentence

Whose horrid image doth unfix my hair

Against the use of nature.”

 

This view is confirmed by the fact that we only feel images to be “unreal” when we already

know them to be images. Images cannot be defined by the feeling of unreality, because when we falsely believe an image to be a sensation, as in the case of dreams, it feels just as real as if it were a sensation. Our feeling of unreality results from our having already realized that we are dealing with an image. As soon as an image begins to deceive us as to its status, it also deceives us as to its correlations, which are what we mean by its “reality”.

 

Stout  (loc. Cit., p.127) cites: “One characteristic mark of what we agree in calling sensation is its mode of production. It is caused by what we call a stimulus. A stimulus is always some condition external to the nervous system itself and operating upon it.”

 

“Most of our judgments of perception involve correlations, as when we judge that a certain noise is that of a passing cart. Such judgments are all obviously liable to error, since there is no correlation of which we have a right to be certain that it is invariable.”

 

Excerpt from “Sensations and Images”

“The Analysis of Mind” by Bertrand Russell

  • Share/Save/Bookmark

End of Hibernation… Spring Blossoms…

Posted by Logu Krishnan | Posted in Personal, Ramblings | Posted on 30-05-2006

Tags: ,

0

End of all shrugging coats and ghostly looking trees and a hibernated life… finally the spring is here and already the early bloomer Tulip has filled up the house… and flowers peek out even before the leaves start to grow and finally I see sun after some time…

 

Life is getting better these days, living in a small beautiful American town with no hypes. The day I came here, everything was like a haunted ghostly snowy town, as the spring sprung… somebody has swished the magic wand… the whole place became beautiful in a week… somehow felt that I always don’t look the beauty that’s around me…

 

People here are good, professionals and lives life without any hypocrisy. They speak straight… The team i’m working with likes the indian food a lot, but for some reason i always hesitate to go to a indian restaurant, because i don’t want to forget the indian taste. May be these restaurants should be renames as Indo-American restaurants, as the food here is cooked for americans and sadly not for indians. We cannot blame them when pizza hut in india sells tandoori pizzas and desi pizzas…

once when i felt bored with indian food, madhuri cooked  good indian food and reminded me of the indian taste.

 

Also met prabha after a long time… one good soul i wanted to meet in US of A. we planned for the tulip show at holand, but missed the trip due to rain.

 

Slowly mingling with the American crowd… learning poker, mountain biking, golf during weekends… there are amazing trails in short drive… also learning to cook fudges, American, Thai cuisine and of course slowly honing my amateur photographic skills…

 

Some Photographs of Michigan at http://www.logukrishnan.net/photos/michigan

 

Michigan

  • Share/Save/Bookmark

CNUG Community Launch… Oversubscribed

Posted by Logu Krishnan | Posted in .NET User Groups, MVP, Microsoft | Posted on 10-01-2006

Tags: , ,

0

CNUG Community Launch was oversubscribed yesterday, We had around 300 confirmed participants but as the event was on Sunday and Chennai was drizzling in the early dawn so I thought the count might be around 200-250, but during the break while I was speaking to JD he said “we have around 400+ registrations”, WOW! That was a great count and the interesting fact was that the participants count composed of 70% Software Professionals and 30% Students. Which I think is a healthy composition compared to the last year.After the keynote, I started with my “C# 2.0 Unleashed” Session, My objective was not just to speak about the language enhancements but to cross cut at different technologies, and as the crowd is a mixture of Students, Professionals, Enthusiasts I did not wanted to get into the in-depth technologies. So, apart from Language Enhancements, I touched upon different technologies like DirectX, AI, Devices, GPS, C# Evolution et al… There was Awe’s & wow’s when I showed the Live GPS Demo using my GPS Receiver and ZBuffer’s 3D Engine… In the end it was very fulfilling session with many interesting questions…and many congratulations…

 

One observation I had was that, Many people know WHAT but didn’t know WHY and HOW !!! i.e. people know what generics is, but didn’t know WHY Generics and didn’t know HOW to use generics…not many people knew the performance gain offered by the Generics… Also, not many people know that we can do Games in C#, and have never heard of System.IO.Ports et al…


But, I Should say the crowd was quite alive & Responsive, and questions came out without hesitations… That was really good to see…


My session was followed by Ravi ’s SQL Notification and after lunch was
Anand M’s VB.NET Secrets session… which got a good applause when he showed all the gimmicks the VB refactoring could do! And when he tried to pull the legs of C#, there was immediate response from the crowd favouring and fighting for C#…  that was an interesting conversation. Later Sankar Spoke about AJAX and Dhamayanthi finished up the event with her VSTS Sessions…

 

And we had Ask the Experts… and on the expert zone I had to answer some interesting questions like, “Should I Use Threadpool?”, “Why is that Microsoft has not released a software to kill Tally ?” , “Can C# do Robotics” ?  et al…

A Special kudos should go to Mahalaxmi and her team for organizing the whole event.

My Camera’s battery dried up and couldn’t take much of the photos, however you can find some photos at http://photos.logukrishnan.net/CNUGCommunityLaunch/

 

 

 

 

All in all it was very ful-filling day … Thanks everyone for participating in the event… You guys made my day… Thanks…

 

 

Link: For those of you interested, here is the link to the PPT I used in the Event http://www.logukrishnan.net/CNUGCommunityLaunch/CSharp2.0Unleashed.zip

 

  • Share/Save/Bookmark

Chennai .NET UG Community Launch

Posted by Logu Krishnan | Posted in .NET User Groups, MVP | Posted on 02-01-2006

Tags: ,

0

Chennai .NET User Group [ http://www.cnug.net ] is getting rejuvenated, and has announced the community launch of the Visual Studio 2005, SQL Server 2005 and Biztalk Server 2006. This event is 1 Full day stuffed with Technical Sessions + Fun on 8th Jan 2006 at “Tidel Park Auditorium”, Chennai

I’m speaking on this event on the title “C# 2.0 - Unleashed”, Interesting Topic to discuss :-) and also opportunity to meet lotsa people…

Interested ? Do Signup for the event at

http://groups.msn.com/chennainetusergroup/communitylaunchsignup1.msnw

Here is the Event Invitation with the detailed Agenda.

CNUG Launch

 

For more details check http://www.cnug.net

Let’s Rock Guyz ! See You There…

  • Share/Save/Bookmark

2005… Looking Back…

Posted by Logu Krishnan | Posted in Uncategorized | Posted on 01-01-2006

0

Should I say this was quite a eventful year! I don’t know… !!

But,

A Year Where I’ve met so many new faces across the world, from the sweetest of all to the scariest of all to the charismatic of all…

A Year filled with travel, almost every weekend or alternate I was traveling…

A Year where I’ve made more number of flop shows and more flunks…

A Year filled with new experiences, some of which, I Didn’t know how to play…

Some of which, I Never wanted to repeat, if it repeats, Now I Know How to play the game!

A Year which changed perceptions towards life…

 

A Year Where I learned Amateur Photography…

 

[I've compiled a list of photos at http://photos.logukrishnan.net/Shots2005 ]

Favourite Shots 2005

.

.

.

 

Welcome 2006…

  • Share/Save/Bookmark