openMPI 1.6.4 Experimental Windows Build

So I was browsing the openMPI website the other day on the quest to download the latest version so that I could start off with some of my video tutorials. I was slightly (actually more than slightly) disappointed to see that they are dropping support for Windows entirely since they no longer have anyone to maintain a Windows build. If I had the time I would offer it.

Anyway – I thought I would take a crack at building a windows version of 1.6.4. It required a bit of tweaking – the odd change in the code – but long story short: I got it working. I have made it available for download.

Just a quick reminder: It is an unofficial build. I have not gotten around to figuring out how to run the openMPI tests against it yet. I have tested to see if basic openMPI programs work and there seems to be no problems there. There is also no CCP support in this build.

Depending on how much time I have – I shall release a 64 bit version soon as well.

Quick Tip: Visual Studio 2012 and DirectX

Just a quick tip for all those who may be migrating DirectX projects from Visual Studio 2010 to 2012 either on Windows 7 or by switching to Windows 8. You will get A LOT of compile-time warnings. I found out the reason and the fix here. In short, DirectX is now in the Windows SDK and a separate DirectX SDK conflicts a little. Solution to the warnings is (as given in the link above) to remove the DirectX SDK include, or (if you still using D3DX), to move the include to after the Windows SDK include. Happy Programming.

C++/CX: Not a simple love or hate

Standards are important. Standards makes it clear what to expect or what is expected of you. If you are still wondering what I am talking about, well then a bit of an explanation follows: I am talking about official standards as published by a Standard Organisation (such as ISO etc…). I want to quickly give my brief opinion C++/CX, a small deviation from the C++ standard, where, in my opinion, it is not quite clear cut whether the decision to deviate from the Standard was a good thing or a bad thing.

C++/CX, according to the Microsoft site (here), is a set of extensions to C++ that are targeted at Windows Store and Windows Runtime development. I came across C++/CX when I was reading some Windows 8 development tutorials and have not yet used it very much. My first thought was “why? oh why do you do this to us?”. Why not just make use of standard C++? First of all the applicability of a Standard in the context of Windows Runtime development isn’t as important since we are confined to that specific context. The applications developed are not aimed at being cross-platform, and developers are not likely to try and use a different compiler (although sometimes that might still be nice).

But there are other reasons that maybe we should stick to the Standard? How about the fact that a C++ developer has to now contend with and learn new language constructs that wouldn’t normally be seen in a C++ program? The other side of this argument is that experienced developers normally have no issue coming to terms with new programming languages (and since C++/CX introduces new syntactical elements is has to be defined as a altogether different language).

Maybe something can be found if the reasons for such a deviation can be inferred. This is trivial – the deviations have introduced new language features obviously intended so that developers do not have to cobble a lot of code together for elements that occur frequently in Windows Runtime programs. I have found some of these features to be interesting and potentially useful (interfaces, accessor methods etc.)

So where does this leave the issue? I think it leaves it in a fairly grey area. Deviations or extensions in this manner add a bit of diversity – as such, some of the features might be considered for the actual standard (just as many of the constructs in Boost have been added into the Standard C++ library). I don’t think we should fault developers for augmenting the tools available so as to have the tools they need. Yes, it can be frustrating sometimes if it is (basically) forced upon us by a big corporate giant. However in this case you have a choice (C#, Javascript, C++). The inclusion of Javascript deserves sidetracking from the main topic, and so I shall finish with it. Javascript’s inclusion tells me that Microsoft seems to be taking note of global trends these days instead of trying to beat the trends into submission and set their own. There are more and more examples of this including but not limited to the inclusion of Node.js into the Azure platform and more recently the integration of git into Visual Studio and Team Foundation. I kind of like the initiative, whether it is an elaborate marketing ploy to lure in new developers or not – time will tell.

Configuring Open MPI in Windows

This tutorial covers the setup of Open MPI and the compiling and running of MPI programs in the Microsoft Windows environment.

Open MPI and Windows

Open MPI is an implementation of the MPI standard. It is cross platform and makes use of your installed C++ or Fortran compiler. Getting everything working in a Linux environment is fairly easy provided gcc is installed. However when it comes to Windows there seems to be fairly few resources available on the internet that details the procedures to get everything up and running. After some playing around I eventual got everything working nicely.

My environment:

  • Windows 7 Ultimate x64
  • Open MPI 1.6.1 x64
  • Microsoft Visual Studio 2012 Professional x86 (only needed for cl.exe)

This tutorial does not make direct use of Visual Studio. Any version of Visual Studio should do, all we really need is the Microsoft C++ compiler and related tools that Open MPI uses.


Step 1: Installation

Download and install the latest version of Open MPI. Note that I downloaded the 64 bit version. I also changed the installation path to “Program Files” instead of the default “Program Files (x86)”. The Open MPI website states that this a temporary issue with their installer that should be fixed in time. If the installer asks to setup PATH variables then do so for all users. If the installer reports a failure when trying to do so, then don’t worry, we can do it manually as well.


Step 2: Open MPI PATH setup

For me the installer failed to setup any PATH variables, stating that my PATH was too long (not true). In this case we shall set it up manually. Simply add the bin directory of Open MPI to the global PATH variable. Thus in my case I added “C:\Program Files\OpenMPI_v1.6\bin” without the quotes to my PATH.


Step 3: cl.exe PATH setup

Open MPI for Windows is pre-configured to use the Microsoft C/C++ Compiler. It thus needs access to cl.exe, which controls the Microsoft Compiler and Linker. It is important here to add the correct directory to your PATH depending on the architecture (32 bit or 64 bit) of the Open MPI that you downloaded or else you will get linker errors. Since I downloaded the x64 version, I added the following directory to my global PATH: “C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\amd64” If you installed the x86 version of Open MPI then you can use the base bin directory (without the amd64 on the end).


Step 4: VCVARS

cl.exe won’t work out the box in any command prompt. It is required that the Visual Studio environmental variables are set up. The good news is that Microsoft provides bat files to do this for you. The bad news is that these settings are lost when you restart your computer. Thus here you have a choice, either simply run the bat file before you wish to compile MPI programs (not that much hassle since the bat file is in the same directory as cl.exe and thus in your PATH now), or you can add the file to your task scheduler to run at system startup. The name of the file is either vcvars32.bat or vcvars64.bat for x86 and x64 architectures respectfully. I just simply type vcvars64 into my command prompt before compiling the first time. At this point everything should be setup.


Compiling a simple MPI program:

I tested the setup with a simple program that has each process print out a greeting and exit. To compile: “mpic++ main.cpp” If everything is setup correctly then you should see output like this:

Microsoft (R) C/C++ Optimizing Compiler Version 17.00.50727.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

Microsoft (R) Incremental Linker Version 11.00.50727.1
Copyright (C) Microsoft Corporation.  All rights reserved.

"/LIBPATH:C:Program FilesOpenMPI_v1.6/lib"

Then to run the program with 10 processes: “mpirun -np 10 main.exe”

That’s it. Happy distributed programming.

Perlin Noise – The Simplicity, the genius

So after my rant about how the internet lies about what Perlin Noise is and what it isn’t, I decided to implement it myself (well actually my final graphics assignment specification decided for me). After staring at my code for two whole days trying to figure out why I was getting repeating patterns (and no, you may not ask me what the bug was due to shear embarrassment), I achieved the very embodiment of coherent randomness. Now this is still the original implementation with the speed improvement as given by Perlin himself – now to implement it with his improvements.

Original Perlin Noise

Perlin Noise

Perlin Noise: The Internet Lies

Perlin Noise

Perlin Noise

A while back I started experimenting with some procedural techniques, more precisely I wanted to create a procedural terrain using Perlin Noise. I had never implemented Perlin Noise before so Google to the rescue. The first decent article I came across was this tutorial. Without going into too much detail, it explained how I should combine noise functions with different frequencies and amplitudes to produce “Perlin Noise”.

My first attempt failed, producing complete random noise. After confirming that I followed the tutorial accurately I set out to find more tutorials. Everything that I found seemed to be similar: combine noise at different frequencies and amplitudes. In the end I did indeed get some working “Perlin Noise”…or so I thought.

It was about a year later and I am in my Honours Graphics class at University one Friday night when my lecturer begins explaining the process that one follows to implement Perlin Noise. At first I thought I could sit back and relax, then I started to realise that I had no idea what my lecturer was talking about. The process was entirely different to what I had learnt! There was no talk of the octaves, frequencies and amplitudes and the methods of combining the noise like I had learnt – needless to say, I was completely confused. At this point I decided that I would take a detailed look into Ken Perlin’s online notes which is where my lecturer got all of his sources from. After wrapping my mind around the algorithm, I continue with Ken’s notes on different methods of applying the noise. One of the strategies that Ken Perlin mentions he calls Fractal Noise – this being the process of recombining the noise produced by the Perlin Noise function in different frequencies and amplitudes – just like I have read before!!

So!! – what many many people on the internet are calling Perlin Noise – is actually not Perlin Noise at all. It is instead the fractal recombination of noise. Furthurmore the noise function that everyone seems to be using is either some small custom random number function or just the programming language’s built-in random number function – meaning that once again that NONE OF IT can in any way be called Perlin Noise.

It seems that some of these tutorials and explanations have been on the internet so l

ong that it has actually convinced a large amount of the population that this fractal combination of noise is what Perlin Noise is – and thus more and more of these tutorials are appearing.

This blunder, this blatant lie is a dishonour to Ken Perlin and his work. The word needs to spread – so share this with everyone you know!!

The Whitted Scene

At last! My recent graphics practical has had me doing work in the realms of elementary ray tracing (ie: Whitted Ray Tracing). It is the first time I have ever worked with ray tracing concepts and I must admit that they are quite simple.

Recursively bouncing rays around a mathematically described scene is far simpler than the endless transformations and steps that one has to worry about with rasterisation…and the results complete with perfect reflections and refractions speak for themselves:

The Whitted Scene

The Whitted Scene

When this algorithm was developed some 30 odd years ago, it took the technology of the time 74 minutes to produce the above image. Today it takes less than a second 🙂

Cellular Automata and Swarm Intelligence

I have been playing around with HxCAS a little bit today in preparation for a demonstration the team and myself are giving tomorrow. For a while I have been wanting to write a small CA program that demonstrates some very simple swarm intelligence. Today I finally got it working 🙂

The program is quite simple. The goal of the swarm agents are to locate a beacon. So the agents will randomly roam about looking for any beacon. If they find a beacon or another agent which has reportedly found a beacon then they will stop and report the found beacon. (Thus they can tell any other agents in the vicinity that they found a beacon) While the agents roam about they have the potential to crash into each other (which will result in one of the agents being lost)

I have added the world (complete with rules and colour settings) to the newly created Downloads page. Feel free to play around with it. Note that you will need the latest version of HxCAS to run the compile the rules as I had to add a function the the standard library to get it all working nicely.