How to Compile GridDyn: MSYS2

This post contains instructions for compiling GridDyn on a Windows OS computer using MSYS2 as the compiler. Topics covered include downloading the GridDyn source file, installing the SUNDIALS solver library, building GridDyn, and running an example on GridDyn.

The alternative to Visual Studio for compiling GridDyn on Windows is to use MSYS2. I do this on a regular basis to test different compilers and ensure that everything compiles correctly.

The MYSYS2 software is an independent rewrite of MSYS, based on Cygwin (POSIX compatibility layer) and MinGW-w64, with the goal of better interoperability with native Windows software. MSYS2 provides a Unix-like environment to build Windows applications. It uses Arch Linux’s pacman package manager. The SourceForge MSYS2 web page contains the installation instructions for both the 32-bit and 64-bit versions.

I use the 64-bit version and typically install it directly on the drive (in this case C:/msys64). Administrative privileges are not required to perform the installation.

Once pacman is installed, you should be able to open a command window from the installed start-menu shortcut.
The following is the first command:

$pacman -Syuu.

If you have a new version of the software, updates are not required; if not, there may be some updates required, in which case follow the on-screen instructions.

Compiler Tools
Next you need to install the tools that will be used to compile GridDyn. Type the following command:
$ pacman –S mingw64/mingw-w64-x86_64-gcc

There are several options for compilers. The latest version is gcc 6.2; any compiler that is version 4.9 or newer should work.

Other packages to install include the following:


Getting the GridDyn Repository
The last part of the following command can be whatever you want it to be; it is the directory from which to download the source file.
$git clone gridDyn-public

Installing SUNDIALS
Before you build GridDyn you will need to download SUNDIALS.

          1. Create a SUNDIALS directory and enter it using the following commands:
            $ mkdir sundials

            $ cd sundials
          2. Use the following command to download SUNDIALS:
            $ wget
          3. Extract the file.
            $tar xvfz sundials-2.6.2.tar.gz
          4. Create the following install and build directories and enter the build directory:
            $ mkdir sundials-2.6.2-build

            $ mkdir sundials-2.6.2-install
            $ cd sundials-2.6.2-build
          5. As in the previous blog post, this version of SUNDIALS has some problems finding KLU on a Windows system, be it for Visual Studio or for MSYS2. You will need to help it by using the following findKLU command from GridDyn.  The experimental branch of the public repo fixes some of this but more improvements are expected in the future.
            $ cp ~/gridDyn-public/config/FindKLU.cmake ../sundials-2.6.2/config/FindKLU.cmake
          6. Start up CMake.
            $cmake-gui ../sundials-2.6.2
            The following window is displayed.sshot1
          7. Select the “Configure” button. A dialog box is displayed (see the following screenshot). Scroll down the list of generators to “MSYS Makefiles”, then select the “Finish” button.sshot2
          8. After selecting “Finish”, some variables will show up; a few need to be changed. Deselect BUILD_SHARED_LIBS.
          9. Change the CMAKE_INSTALL_PREFIX to the created install directory.
          10. Set CMAKE_BUILD_TYPE to Release otherwise it may default to debug though you are free to set it to whatever you so choose (Release, Debug, RelWithDebInfo, MinSizeRel).
          11. Deselect EXAMPLES_ENABLE and EXAMPLES_INSTALL.
          12. Select KLU_ENABLE.
          13. Select OPENMP_ENABLE (optional). If everything worked properly and there were no errors, a “Configuring done” message is displayed.
          14. Select “Generate.”
          15. Close the window.
          16. In the command prompt, type $make, followed by $make install. This will copy the appropriate file to the Install directory.

Building GridDyn

        1. Enter the GridDyn Directory:$ cd ~/gridDyn-public
        2. Create a build directory by typing the following: $mkdir build, 
$ cd build, and 
$cmake-gui ...
        3. The following are recommended modifications to the CMake build.
          • Select LOAD_ARKODE and LOAD_CVODE.
          • Select OPENMP_ENABLE.
          • Specify the SUNDIALS_INSTALL_DIR to the install directory specified in the previous step.
          • Change CMAKE_BUILD_TYPE to Release.
        4. The final options screen for GridDyn (shown in the following screenshot) is displayed. Note: If any options are changed a final configure must be run.
        5. Select the “Generate” button.
        6. Exit the CMake GUI.
        7. At the command line type $ make -j 8. The -j 8 character specifies the number of jobs to run in parallel. Select some number appropriate for your computer.
        8. If an install directory was specified, type $ make install in the command line. To copy the files to the installation directory (for example gridDyn-public/bin), enter $ cd ../bin.


In the directory created by typing the following lines, the main executables are gridDynMain and test.

$ ./griddynMain ../examples/two_bus_example.xml -o res.txt
area count =0 buses=2 links= 1 gens= 1
(PRESTART)[sim]::GridDyn version 0.5.0 2016-08-20
Simulation gridDynSim_103 executed in 0.0099999 seconds
simulation final Power flow statesize= 4, 10 non zero elements in Jacobian

$ less res.txt
gridDynSim_103 basepower=100.000000
Simulation 2 buses 1 lines

This prints out a formatted file of the results of a simple two-bus case.


Congratulations! You have now compiled and run an Example on GridDyn.