Quick-Tip: Eclipse bookmarks

Here is a nifty little feature in Eclipse. You can bookmark any line of code you deem important by placing your cursor on that line of code and then selecting Edit->Add Bookmark. Nice if you have large source files that takes time to navigate through using the Outline or source files of an unrecognized type that Eclipse gives no help to you at all.

Source

Eclipse_BookMark_Feature

Adding programs to your PATH in Windows

Adding items to your PATH system variable is one of those routine programmer activities – especially in Windows where many program installers don’t usually do this for you. So here is a quick tutorial on adding items to your PATH.

1. What is the PATH Variable?

The PATH variable is a list of directories which is searched through when a command is executed with no explicitly given location. So if you are in a random directory and you type the command “java”, then the operating system will search the current directory for a program of that name. If none is found, it will then search through all the directories in the PATH variable for the program.

2. Where is PATH set?

In Windows, the PATH variable is set in the advanced system settings. These settings can be found by right-clicking on computer, selecting “properties” and then selecting “Advanced system settings”

Step 1

 

Then on the “Advanced” tab, click on the “Environmental Variable” button. A window will pop up and the global system PATH variable will be in the System Variables list.

Step 2

 

Select “Path” from the list and click edit. At THE END of the text given in “Variable Value”, add a directory to include in the path – such as where Java is installed. Do not remove anything else from the path variable unless you know exactly what you are removing from it. Also ensure you add a semi-colon “;” character between the last directory and the one you are adding. Click OK and you are done. If your command terminal was already open, then close it and open it again for the changes to take effect.

Step 3

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.

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

/out:main.exe
"/LIBPATH:C:Program FilesOpenMPI_v1.6/lib"
libmpi_cxx.lib
libmpi.lib
libopen-pal.lib
libopen-rte.lib
advapi32.lib
Ws2_32.lib
shlwapi.lib
main.obj

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

That’s it. Happy distributed programming.