Friday, May 16, 2008

C++ matrix library

I just can't seem to find a matrix library that will do what I want.

Well, Matlab has one, but the also want $5000 dollars. Holy Cow! Batman! that's a lot of green for a math package.

Gotta keep looking.....

Google Docs

Google docs won’t handle docx. Ugggh, converting to a doc kills my pictures. Ok, so let’s try a pdf, nope. Time to punt.

White paper

I'm working on a white paper for work.

Image distortion correction and calibration calculations

Thursday, May 15, 2008

How to find the number of processors in a system.

Here is some useful code I wrote:

[Note: I included hyper-threaded cores as two processores (if enabled).]

int getNumberOfProcessors()
{
int rval = 1;
SYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer[maxCPUs];
DWORD len = sizeof(buffer);

BOOL success = GetLogicalProcessorInformation(buffer,&len);

if (success)
{
PSYSTEM_LOGICAL_PROCESSOR_INFORMATION ptr;

int processorCount = 0;
DWORD byteOffset = 0;
ptr = buffer;
while (byteOffset < len)
{
switch (ptr->Relationship)
{
case RelationNumaNode:
case RelationProcessorCore:
processorCount++;
break;
default:
break;
}
byteOffset += sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION);
ptr++;
}
rval = processorCount;
}
if (rval > maxCPUs)
rval = maxCPUs;

return rval;
}

Learning to program Alice



My son Jacob is learning to program in Alice. Way to go Jacob!

Tuesday, May 6, 2008

Link

I forgot the link on the previous post:

Link to the About.com programming challenge.

Monday, May 5, 2008

Fastest C++ in the West

I just won the about.com monthly competition. I wrote a program to play the game Set. (A game I don't do very well against the women folk in the family). The program plays the game 10,000 times. It ran 5x faster than the next guy, and his was pretty fast.

I wrote it to use multiple threads so if you have more than one processor it will go REALLY REALLY fast.

The code ain't pretty but it is so screamingly fast it burnt a hole in my hard disk.

My favorite part is the shuffle, to make it fast I interleave (much like a real shuffle) the cards just one time.


// shuffle
register unsigned int i = 0;
register unsigned int j = 80;

do
{
  if ((rbits & (1i64 << i)) != 0) // as we shuffle randomly swap cards
  {
    swapCards(deck[i],deck[j]); // interleave cards
    --j;
  }
} while (++i < 64);

chris' shared items

Twitter Updates

Official blog of Chris Lee Runyan

Fastest C++ in the west.