Windows + 64bit Cygwin 環境の上で OpenBLAS をビルドしたときの記録.単に make とすると失敗したが,コンパイラセットに MinGW-w64 を指定すると上手くいった.
OpenBLAS のダウンロード
OpenBLAS Homepage
OpenBLAS は上記公式サイトの右上にあるアイコンのものをダウンロード.今回は tar 版を選択.Windows 向けのバイナリ版も公開されているが,以前試したときは動作に必要な外部 DLL が欠けていて使えなかったので,今回は敬遠.
$ wget http://github.com/xianyi/OpenBLAS/tarball/v0.2.8 $ mv v0.2.8 OpenBLAS-0.2.8 $ cd OpenBLAS-0.2.8
とりあえず make – 失敗
インストールガイドを読んで,とりあえず一番簡単なビルド方法を試す.
$ make BINARY=64 2&>1 | tee make.log ... blas_server_win32.c: In function 'blas_thread_server': blas_server_win32.c:277:5: warning: passing argument 1 of 'EnterCriticalSection' from incompatible pointer type [enabled by default] EnterCriticalSection(&queue->lock); ^ In file included from /usr/include/w32api/winbase.h:35:0, from /usr/include/w32api/windows.h:70, from ../../common.h:101, from blas_server_win32.c:41: /usr/include/w32api/synchapi.h:43:26: note: expected 'LPCRITICAL_SECTION' but argument is of type 'struct __pthread_mutex_t **' WINBASEAPI VOID WINAPI EnterCriticalSection (LPCRITICAL_SECTION lpCriticalSection); ^ ... blas_server_win32.c:283:19: error: 'blas_queue_t' has no member named 'finish' SetEvent(queue->finish); ^ ... Makefile:101: recipe for target 'blas_server.o' failed make[1]: *** [blas_server.o] Error 1 make[1]: *** Waiting for unfinished jobs.... make[1]: Leaving directory '/cygdrive/c/Users/haru/work/OpenBLAS-0.2.8-cyg64/driver/others' Makefile:134: recipe for target 'libs' failed make: *** [libs] Error 1
失敗.
MinGW-w64 を使ってビルド
ログを見てみると,エラーや警告が多発しているのはスレッド周りで,Win32 スレッドの API に pthread のハンドラを渡そうとしたりしている.Win32 API を使うなら MinGW の方が問題が少ないのでは?と思い,コンパイラセットに MinGW-w64 を指定してリトライした.
$ make clean $ make BINARY=64 \ CC=/usr/bin/x86_64-w64-mingw32-gcc \ FC=/usr/bin/x86_64-w64-mingw32-gfortran \ 2>&1 | tee make-mingw64.log ... OpenBLAS build complete. OS ... WINNT Architecture ... x86_64 BINARY ... 64bit C compiler ... GCC (command line : /usr/bin/x86_64-w64-mingw32-gcc) Fortran compiler ... GFORTRAN (command line : /usr/bin/x86_64-w64-mingw32-gfortran) Library Name ... libopenblas_nehalemp-r0.2.8.a (Multi threaded; Max num-threads is 8) To install the library, you can run "make PREFIX=/path/to/your/installation install".
あっさり上手くいってしまった.
成果物
特にオプションを指定せずビルドすると,static ライブラリとして libopenblas.a(libopenblas_<arch>-<version>.a のエイリアス)が,DLL として libopenblas.dll が生成された.ライブラリのサイズは DLL で 10.6MB,static では 16.6MB もあり,BLAS ライブラリとしてはかなり大きい.