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:
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.
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 https://github.com/LLNL/GridDyn.git gridDyn-public
Before you build GridDyn you will need to download SUNDIALS.
- Create a SUNDIALS directory and enter it using the following commands:
$ mkdir sundials
$ cd sundials
- Use the following command to download SUNDIALS:
$ wget http://computation.llnl.gov/projects/sundials/download/sundials-2.6.2.tar.gz
- Extract the file.
$tar xvfz sundials-2.6.2.tar.gz
- 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
- 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
- Start up CMake.
The following window is displayed.
- 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.
- After selecting “Finish”, some variables will show up; a few need to be changed. Deselect BUILD_SHARED_LIBS.
- Change the CMAKE_INSTALL_PREFIX to the created install directory.
- 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).
- Deselect EXAMPLES_ENABLE and EXAMPLES_INSTALL.
- Select KLU_ENABLE.
- Select OPENMP_ENABLE (optional). If everything worked properly and there were no errors, a “Configuring done” message is displayed.
- Select “Generate.”
- Close the window.
- In the command prompt, type
$make, followed by
$make install. This will copy the appropriate file to the Install directory.
- Enter the GridDyn Directory:
$ cd ~/gridDyn-public
- Create a build directory by typing the following:
$ cd build, and
- 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.
- 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.
- Select the “Generate” button.
- Exit the CMake GUI.
- 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.
- If an install directory was specified, type
$ make installin 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
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.