-
Notifications
You must be signed in to change notification settings - Fork 105
Installation
The installation steps here work for the newest GHC, and I hope others can improve this installation tutorial, esp. for windows os.
sudo apt-get install libgsl0-dev liblapack-dev libatlas-base-dev
stack install hmatrix-tests (OR cabal install hmatrix-tests)
In the shell, the above commands whill install hmatrix and hmatrix-gsl.
sudo dnf install blas-devel
sudo dnf install lapack-devel
sudo dnf install gsl-devel
cabal install hmatrix-tests
In the shell, after running the above command, hmatrix and hmatrix-gsl are installed.
On windows OS, according to the original installation help, OpenBLAS is recommended. So the first step is to install openblas. In the installation help, it tells to download the compiled openblas from http://www.openblas.net/. However, if you install hmatrix according to that tutorial, hmatrix can be installed, but an error telling that the libopenblas.dll can't be accessed will be shown when you implement some code in GHCi. So you need to compile and install openblas from the source manully. As for compiling openblas, please refer to the OpenBLAS wiki. Since there are more information on the OpenBLAS wiki, I'll give the simple steps that work for compiling openblas and installing hmatrix.
- Install MinGW (GCC) compiler suite, either either 32-bit (http://www.mingw.org/) or 64-bit (http://mingw-w64.sourceforge.net/), and install msys with MinGW. Note: there are some problems if you use mingw-w64 through msys2 to compile
openblas. For details, please see issue 1503. So make sure you install MinGW and msys from http://mingw-w64.sourceforge.net/, which is important. - Download the
openblassource either bygit cloneor by zip-file. - Open
msysterminal, in whichcdto theopenblasfolder, and compile the souce bymakecommand
cd ~/OpenBLAS
make
- Install the library to a certain location.
make PREFIX=/your/installation/path install
- Copy
- the compiled
libopenblas.dll---> C:\Users{yourname}\AppData\Local\Programs\stack\x86_64-windows\msys2-20161025\mingw64\bin, - files in include ---> C:\Users{yourname}\AppData\Local\Programs\stack\x86_64-windows\msys2-20161025\mingw64\include,
- files in lib ---> C:\Users{yourname}\AppData\Local\Programs\stack\x86_64-windows\msys2-20161025\mingw64\lib,
- or any locations that are in the search path.
- Install
hmatrix.
stack install hmatrix --flag hmatrix:openblas
Or you can use cabal to install it.
After that, if the installation succeeds, it will work in GHCi without any errors.
On windows, when you install hmatrix with stack install hmatrix --flag hmatrix:openblas with the openblas as a backend, hmatrix is always installed as a global-project, not into a specific stack snapshot. In order to install hmatrix into a stack snapshot, you need first to install blas and lapack packages. So the first step is to install blas and lapack. Although there are some prebuilt libraries and .dll here for blas and lapack, I have never installed hmatrix successfully with those prebuilt libraries. So I decided to compile those two libraries from sources manually. The following compiling steps are from Lapack for Windows:
- Download the lapack.tgz from the netlib website and unzip.
- Download CMAKE and install it on your machine. Make sure you are using CMAKE 2.8.13 or above.
- Download MinGW 32 bits or MinGW-w64 and install it on your machine. Please note: you should install MinGW and msys from http://mingw-w64.sourceforge.net/ as suggested in the Install with OpenBLAS.
- Put the GNU runtime directory (that is your mingw-w64 ) in your PATH, for me I added C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin (MinGW 64 bits) in my PATH (right click on your computer icon, go to properties, advanced system settings, Environment Variables, look for the PATH variable and put 'C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin;' in front of its current value).
- Open CMAKE
- Point to your lapack-3.8.0 folder as the source code folder in the Where is the source code
- Point to a new folder where you want the build to be (not the same is better) in the Where to build the binaries
- Click configure, check the install path if you want to have the libraries and includes in a particular location
- Choose MinGW Makefiles.
- Click "Specify native compilers" and indicate the path to the Mingw compilers.
- For Win32, on my machine, the Fortran Compiler is "C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gfortran.exe", the C compiler is "C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe", and C++ compiler is "C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe".
- For x64, on my machine, the Fortran compiler is "C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/x86_64-w64-mingw32-gfortran.exe", the C compiler is "C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/x86_64-w64-mingw32-gcc.exe", and the C++ copiler is "C:/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/x86_64-w64-mingw32-g++.exe"
- Set the 'BUILD_SHARED_LIBS' option to ON
- Set the 'CMAKE_GNUtoMS' option to ON.
- If you want to build the LAPACKE library, set the 'LAPACKE' option to ON.
- Click again configure until everything becomes white
- Click generate, that will create the mingw build
- Close CMAKE
- Open a cmd prompt or powershell
- Go to your build folder using the cd command, that is, the folder you have set in Where to build the binaries
- Type
mingw32-makeand wait for the compilation to finish - Type
mingw32-make testif you want to run LAPACK testings to make sure everything is ok. (However, I met the No tests were found!!!, and I don't know how to figure it) - Your libs are in the lib folder, the dlls are in the bin folder, and the header files are in the include folder. The resulting build will provide both GNU-format and MS-format import libraries for the DLLs.
- Copy the files in the lib, include, and bin folders into the corresponding folders in the
stack's msys2/mingw64 directories.
At last, you can install hmatrix into the stack snapshot by running:
stack install hmatrix
NOTE:
When you run mingw32-make in the step 8 to compile the lapack, there may be an error, telling that:
This problem may be caused by overloading of symbols according to this blog. All you need to do is to edit the next file created by Cmake in the build folder:
{Your build folder}\SRC\CMakeFiles\lapack.dir\link.txt
And add the following sentence as an option of x86_64-w64-mingw32-gfortran.exe
-Wl,--allow-multiple-definition
The corresponding line of link.txt is edited as follows:
C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\gfortran.exe -O2 -DNDEBUG -O2 -shared -o ..\bin\liblapack.dll -Wl,--allow-multiple-definition -Wl,--out-implib,..\lib\liblapack.dll.a -Wl,--major-image-version,3,--minor-image-version,8 -Wl,--whole-archive CMakeFiles\lapack.dir/objects.a -Wl,--no-whole-archive @CMakeFiles\lapack.dir\linklibs.rsp
Now if you run mingw32-make, lapack.dll should be created. Good luck!