SG++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Windows (MinGW)

This page contains instructions for compiling and using SG++ with MinGW (64-bit) under Windows.

Overview

Caveats

  • Aligned memory allocation is buggy (leads to program crashes) and therefore turned off in the MinGW build.
  • Libraries compiled with different Windows compiler are in general not compatible with each other. So, using the compiled SG++ library from MSVC++ won't work or requires a large amount of work.

Dependencies

Required

The following software is required in order to build SG++:

  • MinGW-w64, which provides the compiler toolchain including g++
  • Python 2.7 (x64) as a prerequisite for SCons (Python 3.0 is not yet support by SCons). If you do not plan to compile the Python bindings (pysgpp), then the x86 version of Python is sufficient.
  • PyWin32 (x64) for parallel building and some tweaks in our SConstruct.
  • SCons (≥ 2.3) is required for building (build system).

Recommended

The following software is recommended for core functionality:

  • Boost.Test for compiling and running the unit tests. You can also skip the unit tests, but this is not recommended.
  • SWIG (≥ 3.0), if you want to use SG++ within Python, Java, or MATLAB. SWIG creates bindings from C/C++ functions in order to make them available as a Python module or prepare them to be called from Java code.
  • NumPy for Python 2.7 (x64) is needed, if you want to run the Python tests/examples.
  • Java Development Kit (JDK, x64), if you want to compile the Java bindings.
  • Doxygen is required to create and compile the documentation, which you are reading right now. It is also required to automatically annotate the Python bindings generated by SWIG with docstrings.

Optional

The following software can be installed for full functionality:

Installation

It is advisable to install the requirements in this order:

  1. First, please make sure that you install all dependencies to paths that do not contain any space (no Program Files or similar) or you might get trouble, i.e., the paths C:\PATH_TO_MINGW etc., where you install the software, should be free of spaces.
  2. MinGW:
    1. Download mingw-w64-install.exe from the MinGW-w64 SourceForge page.
    2. Run the installer and select the architecture x86_64.
    3. Prepend C:\PATH_TO_MINGW\bin to the PATH environment variable.
  3. Python:
    1. Download python-2.7.11.amd64.msi or similar from the Python page. Python 3.x is incompatible with SCons and the x86 version will not work with pysgpp.
    2. Run the installer.
    3. Prepend C:\PATH_TO_PYTHON and C:\PATH_TO_PYTHON\Scripts to the PATH environment variable (this can also be done by the installer).
  4. PyWin32:
    1. Download pywin32-219.win-amd64-py2.7.exe or similar from the PyWin32 SourceForge page (selecting a version for amd64 and Python 2.7 is important).
    2. Run the installer, selecting the Python version you installed earlier.
  5. SCons:
    1. Download scons-2.4.1-amd64-setup.exe or similar from the SCons SourceForge page (selecting a version for amd64 is important).
    2. Run the installer, selecting the Python version you installed earlier.
  6. Boost.Test:
    1. Download boost_1_59_0.7z or similar from the Boost page.
    2. Unpack the archive.
    3. Run the following in cmd.exe:
      cd C:\PATH_TO_BOOST
      bootstrap.bat gcc
      b2 --with-test ^
        toolset=gcc ^
        variant=release ^
        link=shared ^
        threading=multi ^
        runtime-link=shared
    4. Copy C:\PATH_TO_BOOST\stage\lib\libboost_unit_test_framework-mgw52-mt-1_59.dll or similar to C:\PATH_TO_BOOST\stage\lib\libboost_unit_test_framework.dll.
    5. Prepend C:\PATH_TO_BOOST\stage\lib to the PATH environment variable.
  7. SWIG:
    1. Download swigwin-3.0.7.zip or similar from the SWIG page. A special x64 version is not necessary.
    2. Extract the archive.
    3. Prepend C:\PATH_TO_SWIG to the PATH environment variable.
  8. NumPy:
    1. Download numpy‑1.9.3+mkl‑cp27‑none‑win_amd64.whl or similar from this third-party page (selecting a version for amd64 is important).
    2. Run pip install numpy‑1.9.3+mkl‑cp27‑none‑win_amd64.whl to install NumPy.
  9. JDK:
    1. Download jdk-8u66-windows-x64.exe or similar from the Java page (selecting a version for amd64 is important).
    2. Run the installer.
    3. Prepend C:\PATH_TO_JDK\bin to the PATH environment variable.
    4. If SCons does not seem to find the JDK in the right place, try checking the JAVA_HOME environment variable (either set it to the right path, e.g., C:\PATH_TO_JDK without bin, or unset it completely).
  10. Doxygen:
    1. Download doxygen-1.8.10-setup.exe or similar from the Doxygen page.
    2. Run the installer.
    3. Prepend C:\PATH_TO_DOXYGEN\bin to the PATH environment variable.
  11. Dot:
    1. Download graphviz-2.38.msi or similar from the Graphviz page.
    2. Run the installer.
    3. Prepend C:\PATH_TO_GRAPHVIZ\bin to the PATH environment variable.
  12. MATLAB:
    1. Install MATLAB with the installer.
    2. Prepend C:\PATH_TO_MATLAB\bin to the PATH environment variable.

Compilation with SCons

When compiling with SCons, supply COMPILER=gnu to override the default of MSVC++. Don't forget to add the locations of the Boost include and library path.

scons -j 4 ^
  COMPILER=gnu ^
  BOOST_INCLUDE_PATH=C:\PATH_TO_BOOST ^
  BOOST_LIBRARY_PATH=C:\PATH_TO_BOOST\stage\lib

For additional remarks about building with SCons, please refer to the Linux page.

Using SG++

In this section, we show how SG++ can be used as a library in other programs. For C++, this includes compilation, linking, and execution of the program using SG++. We also show how to use SG++ from the other supported languages (Python, Java, and MATLAB). As an example application, we consider the tutorial.cpp (Start Here) example from the directory base\examples; however, the instructions can be analogously applied to other programs.

Note that all examples, including tutorial.cpp (Start Here), are automatically built after each SCons run. Therefore, the following steps are not necessary to compile the examples; rather, the intent is to show the steps to build an application using SG++.

In the following, the current directory is always base\examples and C:\PATH_TO_SGPP refers to the absolute path of the SG++ directory. We assume that SG++ or its bindings have been successfully built before.

C++

First, compile the program while supplying the include paths of the relevant modules:

g++ tutorial.cpp ^
  -c -std=c++11 -fopenmp ^
  -IC:\PATH_TO_SGPP\base\src ^
  -o tutorial.o

Then, link the program by indicating the SG++ library path and the modules you want to link against:

g++ tutorial.o -fopenmp ^
  -LC:\PATH_TO_SGPP\lib\sgpp ^
  -lsgppbase ^
  -o tutorial

To run the program, note that you have to set the PATH environment variable to include the SG++ library path:

set PATH=C:\PATH_TO_SGPP\lib\sgpp;%PATH%
tutorial

Python

The Python bindings pysgpp can be used by installing pysgpp in the local site-packages folder:

python setup.py install --user

To run your Python program, don't forget to update the PATH environment variable in any case:

set PATH=C:\PATH_TO_SGPP\lib\sgpp;%PATH%
python tutorial.py

Java

Java programs using the Java bindings jsgpp have to be compiled in this way:

javac -cp .;C:\PATH_TO_SGPP\lib\jsgpp\jsgpp.jar tutorial.java

Note the use of ; instead of : like on Linux. When running Java programs, you have to augment PATH not only by the SG++ library path, but also by a path specific for jsgpp:

set PATH=C:\PATH_TO_SGPP\lib\sgpp:C:\PATH_TO_SGPP\lib\jsgpp:%PATH%
java -cp .;C:\PATH_TO_SGPP\lib\jsgpp\jsgpp.jar tutorial

MATLAB

MATLAB can use SG++ in two ways.

Via MEX Interface

One way is to use MATLAB's MEX interface to write a C++ program interacting with SG++ directly in C++ and converting input and output arguments from and to MATLAB's data structures. If MATLAB's mex function cannot find MinGW's g++ compiler, you can compile and link the MEX file by yourself with the following commands:

g++ your_mex_program.cpp ^
  -c -std=c++11 -fopenmp ^
  -Wall -Wextra ^
  -IC:\local\matlab_x64\R2015a\extern\include ^
  -IC:\SGpp\trunk\base\src ^
  -o your_mex_program.o && ^
g++ your_mex_program.o ^
  -shared -fopenmp ^
  -LC:\local\matlab_x64\R2015a\bin\win64 ^
  -LC:\SGpp\trunk\lib\sgpp ^
  -lmex ^
  -lsgppbase ^
  -o your_mex_program.mexw64

Of course, you have to add include paths and library switches for each module that your_mex_program uses. However, keep in mind that library files generated by different compilers are not compatible with each other: Refer to MATLAB's documentation page for troubleshooting with MinGW for more information.

Via jsgpp

However, the more direct way to use SG++ from within MATLAB is to use jsgpp, i.e., using the Java library of SG++ and import it to MATLAB. Before we can use these methods in MATLAB, we have to add C:\PATH_TO_SGPP\lib\jsgpp to the librarypath.txt file of MATLAB. (Hint: Typing matlabroot in MATLAB returns the path of your MATLAB installation.) Open the file C:\PATH_TO_MATLAB\toolbox\local\librarypath.txt in a text editor and add the line

C:\PATH_TO_SGPP\lib\jsgpp

at the end of the file.

When starting MATLAB, make sure that the Java version of MATLAB's internal Java Runtime Environment (check with version -java in MATLAB) is newer than that of the Java you built jsgpp with (check with java -version in cmd.exe). In general, you will have to force MATLAB to use your installed JDK by using the MATLAB_JAVA environment variable. You can get errors like this otherwise:

Undefined variable "sgpp" or class "sgpp.LoadJSGPPLib.loadJSGPPLib".

Keep in mind that, however, MATLAB seems not to be compatible with Java 8 yet. Also, set the PATH environment variable appropriately as before. Therefore, start MATLAB by typing the following:

set MATLAB_JAVA=C:\PATH_TO_JDK\jre
set PATH=C:\PATH_TO_SGPP\lib\sgpp:C:\PATH_TO_SGPP\lib\jsgpp:%PATH%
matlab

After starting MATLAB, we have to add the jsgpp.jar file to MATLAB's class path with the command

javaaddpath('C:\PATH_TO_SGPP\lib\jsgpp\jsgpp.jar');

The final step consists in loading the jsgpp library via

sgpp.LoadJSGPPLib.loadJSGPPLib();

You should now be able to use SG++ in MATLAB. For an example, change to the directory base/examples/ and run tutorial.m with

tutorial;

Hints

See the Linux page for hints on how to use SG++ within MATLAB.

Troubleshooting

  • In cmd.exe, type
    set
    to display the values of all environment variables.
  • If you get an error of this type during compilation
    OperationMultipleEvalSubspaceCombined.hpp:82:121: fatal error: ../../OperationMultipleEvalSubspace/combined/OperationMultipleEvalSubspaceCombined_calculateIndexCombined.hpp: No such file or directory
    then a developer didn't read the developer How-Tos and did not know that relative include paths are not supported under Windows using MinGW. To solve this issue you either find out who it was and burn his house down or fix it by yourself (preferable). If you are using an official release of SG++, please report the bug to the developers. Thanks!
  • If you are using an older computer (say < 2011) and the compilation seem to succeed but the unit tests fail, then you might have a problem with your architecture. By default SG++ is compiled with AVX support, which your processor may not support. Try to add the flag
    ARCH=SSE3
    to your build command, which replaces AVX by SSE3. SSE3 is supported by processors, which have been released after 2006.