Compiling on Windows

Windows compilation instructions courtesy of David Myer:

The following build settings have been used under 64-bit Windows 7 and run successfully on an 8-core hyper-threaded laptop. This build has not been tested under Windows 8, but should work just fine since the libraries involved are not specific to the Windows version.

To Install and Build on a Single Multi-core Machine:

Install the following development software:

1) Microsoft Visual Studio version 2010 or later.

Note: You don't need all languages it supports, just C and the Integrated Development Environment (IDE).

2) Intel Visual Fortran version 2011 or later and the Intel Math Kernel Library.

Note: This must be installed *after* Visual Studio so that Visual Fortran can be integrated with the IDE. I used Intel Visual Fortran Composer XE 2011

3) OpenMPI v1.6.2

After version 1.6.2, OpenMPI stopped supporting direct builds of OpenMPI under Windows. So do not download any later version. Instead, go to and download the OpenMPI_v1.6.2-2_win64.exe.

IMPORTANT NOTE: The build settings for MARE2DEM expect OpenMPI to be installed on the same disk drive as MARE2DEM in a folder called \OpenMPI. If you install OpenMPI in a different location, then you will need to alter the build settings to change the library path to point to the new location.

You must make sure that the \OpenMPI\bin folder is in your system path. To do this, search control panel for "System Environment Variables" and click the link which is found. On the dialog that appears, click the "Environment Variables..." button. Find & highlight the Path variable in the System Variables list, then click "Edit...". ADD TO THE END of the list of existing values a semi-colon and \OpenMPI\bin


5) Windows build settings for MARE2DEM.

Download this zip file ( and unzip it in the MARE2DEM folder. The zip file contains a series of files in a folder structure which mirrors MARE2DEM. When you unzip the files, you must respect the folder structure. If all files are dumped together into one place, the build will not work.

Once the software is installed, open the MARE2DEM Visual Studio Solution file found in the MARE2DEM\Source folder. This should launch Visual Studio. If you have a version newer than 2010, it might ask to migrate the files to the new version. Let it do so.

Look at the build properties for the main MARE2DEM project and verify that...

... on the Fortran / Preprocessor page, the "Additional Include Directories" points to the "include" folder under your installation of OpenMPI. The default is \OpenMPI\include

... on the Linker / General page, the "Additional Library Directories" points to the "lib" folder under your installation of OpenMPI. The default is \OpenMPI\lib

Make sure the "x64 Release" configuration is selected and do a complete rebuild. You should end up with a MARE2DEM.exe in the MARE2DEM folder. Note that for certain versions of the compiler, you might need to build twice the very first time you try. If that is the case, run a complete REbuild first, then just a build (i.e. without cleaning the solution beforehand).

To distribute the compiled version to other machines:

There is no need to build MARE2DEM on every single machine you wish to run it on. However, it is not quite as simple as just copying the MARE2DEM.exe file. The runtime libraries for the various compilers need to be installed. These runtime libraries are free to distribute so there is no need to purchase a license for each machine. This right to re-distribute is included when you buy the Visual Studio and Visual Fortran compilers. The following runtimes need to be installed:

  • Visual Studio redistributable runtime
  • Intel Fortran redistributable runtime
  • Intel Math Kernel Library runtime
  • OpenMPI

Each of the first three runtimes is specific to the version of the compiler you have installed. Microsoft and Intel have simple installers available for the first two runtimes. Simply do a Google search for "Visual Studio redistributable 2010" (or whatever version of the compiler you are using).

For OpenMPI, use the 1.6.2 installer you used on the build machine. Make sure that \OpenMPI\bin is added to the system path.

The Math Kernel Library runtime, unfortunately, has no pre-built installer. However, it is not too difficult to put this on a new machine. You can find the MKL redistributables on the compiler machine in a folder similar to this: C:\Program Files (x86)\Intel\ComposerXE-2011\redist\intel64\mkl

Copy the entire folder to the target machine and make sure that it is added to the system path.

Running MARE2DEM

Being written by UNIX people, OpenMPI has one oddity which tends to confuse Windows people. When specifying the program to run, you *must* include the full path and the ".exe" extension in the name. So, for example, a typical launch on a single machine might look like this:

mpirun -np 9 \science\code\MARE2DEM\MARE2DEM.exe survey.0.resistivity

Run it in a command window, in the folder where your .resistivity file exists. All output will be written in the folder you start in. Note that OpenMPI will refuse to run if there is no network present. If you are running on a disconnected laptop, for example, then you must make sure that the networking is enabled, even if you don't connect to a network.

On some network setups, you may experience a complaint from OpenMPI about the network which keeps it from running properly. In that case, you have to include an extra parameter option to bypass the error:

mpirun -mca btl_tcp_if_exclude lo -np 9 \science\code\MARE2DEM\MARE2DEM.exe survey.0.resistivity

The "-np 9" argument after mpirun tells MPI to run using 9 processors. Customize this to your configuration. Note that MARE2DEM plays well with hyperthreading, so if you have a 4-core, hyper-threaded machine, MARE2DEM can efficiently use 8 cores. In this example, I use 9 threads to account for MARE2DEM's manager-worker multi-threading model in which a manager thread which is typically sitting idle while the worker threads are running and then is busy when the worker threads are idle.

Leave a Reply