OpenMP and GCC Optimization

So I encountered and interesting little affect while compiling some C code in OpenMP using GCC. Seems that my code ran fine without any automatic optimization flags (-O2, -O3), but when I turned them on, went haywire. The sequential version wasn’t affected.

I tracked down the problem and found that it was actually do to my use of the private variable in the OpenMP directive. Here is a sample of the problem.

 

#pragma omp parallel
{
	#pragma omp for private(i, j, new_j, skip_next)                      	for(i = 0; i < n; i++)
        	{                                                                    	// Set each thread on one row of the loop
                	skip_next = 0;
                	for(j = 0; j < n; j++)                                       	{
				....

The problem actually occured because I did not have ’skip_next=0′ on line 5 of this code. This didn’t seem to matter when optimization was disabled but did cause incorrect semantics when I turned it on. Seems like OpenMP says you must assume that all privates are uninitialized when you start a new directive block. If you want them to be private but start with some default value, do what I did above or add the variable to the firstprivate() attribute instead of the private attribute:

 

#pragma omp for firstprivate(skip_next) private(i, j, new_j)

HF100 + ImageMixer Fix For Startup Freeze

So I just got a new camcorder thanks to now qualifying for the US stimulus package from back in April. I was looking around for something to help stimulate the economy and decided that I should get a camcorder while prices are low and money is high. Anyway, the HF100 is flash based and really nice. It records in full HD 1080p with pretty decent picture quality, though I have yet to record in full light setting (outside). So far I only have sort of dim shots indoors of my roommate’s cats and my ferret.

Anyway in my commitment to making a post with something useful every week, I’ve decided to share a tip with the world. Seems as though when I installed my ImageMixer 3 SE software, it would just freeze upon startup. Normally I wouldn’t mind the issue with crap proprietary software, but there is no easy way to edit .MTS/M2TS files without converting and losing quality. Since I prefer to keep the originals as well as edit them so that extra footage is chopped off, I needed to figure out what was wrong. After some digging I found the solution to my problem.

If this occurs for you, you need to install all third party codec packs you installed. I had the CCCP (Community Codec Pak), which is useful for watching MKVs. Unfortunately, that was messing up something, so I had to uninstall it. I found numerous posts talking about uninstalling codec packs, so that’s probably the way to go.

Unfortunately, that eliminates the ability to play back MKV’s in WMV. I don’t have a solution for this but I suggest installing VLC. It is wonderful and plays everything.

My first video, the high definition is better if you go straight to youtube:

 

Timing Programs in C (Update)

So I’ve decided to try and do at least one useful post a week to hopefully help a random searcher out. Here is the the updated version of how to get millisecond precise wall clock time in C.

#include <sys\time.h>

gettimeofday(&tstart, NULL);

double t1=tstart.tv_sec+(tstart.tv_usec/1000000.0);

Timing Programs in C (Why I hate clock())

So in working on a parallel programming assignment for a grad class I needed to time two algorithms, a sequential approach and a parallel approach. In doing so I did something like this:

 

clock_t start, finish;

start = clock();

// do something finish = clock();

printf("Time Elapsed: %f", ((double) finish - start) / CLOCKS_PER_SEC);

However this code will give you the wrong time if you are trying to compare the runtime between these two types of programs.

On a sequential algorithm it should produce a good approximation of the wall-clock time, or the amount of time that would expire if you timed it using a clock on the wall (or stopwatch). But in a parallel algorithm we find that it actually gives you a larger time difference.

This is because in a multi-threaded program you are engaging multiple processors (if you have them). Since the clock() gets the number of clock ticks for the program, we get back almost 2x as many (on a two-core machine).

Unfortunately I have yet to find a decent way of getting the milliseconds for a C program accurately. You can use regular old time() to get the seconds, or if you are running on UNIX you can use the time command.

New Theme

Let’s hope there are no major issues. I’ve had some problems with iFrames before and because I’m too lazy to fix it myself I just look for a new one. So far though, this one seems pretty spiffy.

New Caching, Dedicated Memory

I have just enabled page caching on here and soon hope to have dedicated memory from dreamhost, so I should be able to speed up page loads significantly without decimating my wallet.

Vacation

I now have some time to myself and will be uploading some new projects I’ve been working on for the past for days. Specifically I’ll upload a game I plan to make open source that runs on VPython and a C# program (not open source) which i’ve been using to help manage my media collection. Expect them in that order. Until then I’m enjoying my break.

Almost perfect theme

Just when you think you have the perfect wordpress theme, you find something completely disfunctional. I just found out that if I try and use the MORE tag it pushes all my sidebar widgets down to the bottom of the page. Normally I’d try and figure this out and correct it myself, but I am suddenly starting to see a million and one different design choices in this theme that I don’t like and have already begun looking for a new one. Now I’d like something simple that also works perfectly with widgets. Let’s see what I can find.

 

[EDIT]

Actually, I’m tired and I think I’ll keep this theme for a while.

Finally! Sync iPhone with Google Calendar — Seemlessly!

Ok, so I’ve been looking for a way to do this for a long time. I won’t spend time talking about it but rather I’ll just give you details on how to do it.

After doing this you will be able to:

  • Update Google Calendar from the Calendar app on iPhone
  • Have new events appear in your main Calendar on gCal
  • See newly added events on gCal and your iPhone
  • Get your updated Calendar WITHOUT syncing, this is all over the air

Read more

NES ROM Editing

So I did a presentation a couple years ago on NES Rom editting and I learned a lot about how to do some simple rom hacking and how old school cheat tools like game genie and game shark worked. Anyway I’ve decided to share the presentation I gave as well as all the resources I used. Everything is totally open. Everything I used to make the presentation below is included in the zip file and I even wrote up a quick little tool in .NET to translate text to dragon warrior tile entries. Anyway feel free to edit it as much as you’d like, but if you do anything cool with it I’d like to know so just shoot me an e-mail or leave some info in the comments.

Click here to download resources

 

 

Return top