Introduction
In the previous paper I have described how to compile TAUCS: Compiling and Using TAUCS under Microsoft Visual Studio.
The goal of this paper is to describe how one can compile TAUCS with -MD option. The problem here is that libraries supplied with TAUCS are compiled with -MT option and it is necessary to recompile them. First we consider what errors one sees when he/she tries to mix object files compiled under -MT and -MD options. After that we see how to recompile TAUCS under -MD, how to recompile METIS under -MD, and then different options for the optimized BLAS: ATLAS, AMD ACML and Intel MKL. By default TAUCS uses lowercase BLAS functions and it can be used with ATLAS without changes. Yet, both AMD ACML and Intel MKL assume that the BLAS functions are uppercase. To this end, some more efforts are required to force TAUCS to use uppercase BLAS functions.
Problem
Let us start by using libraries compiled previously – see Compiling and Using TAUCS under Microsoft Visual Studio – and then only compile the test file under -MD
$ cl -c -Isrc -Ibuild/win32 -EHsc -MD test_taucs.cpp
This should work. The problem starts during linking
$ cl -MD test_taucs.obj libtaucs.lib libmetis.lib liblapack.lib libf77blas.lib libcblas.lib libatlas.lib vcf2c.lib -link -LIBPATH:lib/win32 -LIBPATH:external/lib/win32
There are many linking errors like
LIBCMT.lib(_file.obj) : error LNK2005: ___iob_func ist bereits in MSVCRT.lib(MSVCR80.dll) definiert.
They happen because the libraries depend on the runtime library libcmt.lib
and the new object file on msvcrt.lib
. However these two runtime libraries cannot be used together. We can try to disable using of libcmt.lib
, as recommended at the end of the error list
$ cl -MD test_taucs.obj libtaucs.lib libmetis.lib liblapack.lib libf77blas.lib libcblas.lib libatlas.lib vcf2c.lib -link -LIBPATH:lib/win32 -LIBPATH:external/lib/win32 -NODEFAULTLIB:LIBCMT.lib
but then there are some missing symbols in vcf2c.lib
and metis.lib
, for example
$ vcf2c.lib(sig_die.obj) : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "__iob" in Funktion "_sig_die".
What happens is that the object files compiled under -MT contains links to some static symbols that are absent in the -MD model. The only solution now is to recompile libraries under -MD.
Please note that Microsoft Visual Studio writes in the object files the dependent system libraries. This could help to learn with what a runtime model they have been compiled. To this end, I use strings. For example
$ strings libmetis.lib | grep -i libcmt
shows us that METIS supplied with TAUCS depends on libcmt.lib.
Compiling TAUCS under -MD (lowercase BLAS functions)
It is relatively easy to compile TAUCS under -MD. If you have already compiled TAUCS under -MT, run
$ nmake clean
if not, then
$ configure.bat
Now edit the file config/win32.mk
and change /MT to /MD in the macros CFLAGS and LDFLAGS as follows
CFLAGS = /nologo /O2 /W3 /D "WIN32" /MD
LDFLAGS = /nologo /MD /F64000000
Strictly speaking this is not enough. We would need also to define correctly LIBBLAS, LIBLAPACK, LIBMETIS and LIBF77. Right now they point to the libraries compiled with -MT. Yet, we can ignore this for the moment. What we must do is to make sure that there is a file taucs_config_tests.h
in build/win32
. It might be there if you already compiled TAUCS under -MT. If not, just make this file. Its content should be as follows
/* Definition for BLAS functions */
#define TAUCS_BLAS_UNDERSCORE
TAUCS makes this file automatically but because the definitions of the LIB* variables is not correct, this will not happen. Without this file with the command
$ nmake
you receive an error
NMAKE : fatal error U1073: "build\\win32\\taucs_config_tests.h" konnte nicht erstellt werden
well, presumably in English or some other language. If you see something like this, just make this file manually as described above. This seems to be the easiest solution to trick TAUCS.
With the file taucs_config_tests.h
made manually
$ nmake
compiles TAUCS but not the examples, as once more the LIB* variables are wrong. Yet, the most important we should have libtaucs.lib
in lib/win32
.
Compiling TAUCS under -MD (uppercase BLAS functions)
If you plan to use TAUCS with either AMD AMCL or Intel MKL, it is necessary to force TAUCS to use uppercase BLAS function. To this end additionally to steps described in the previous section it is necessary to modify taucs.h. Please copy it from this link to src
directory.
Now make sure that taucs_config_tests.h
is in build/win32
. If it is not there just make an empty file with this name, for example
$ touch build/win32/taucs_config_tests.h
Then the command
$ nmake
should build TAUCS. Again the examples will not be compiled but we do not need them. Just check that you have libtaucs.lib
in lib/win32
.
Compiling METIS under -MD
This is described in
METIS – Fill-reducing Matrix Ordering
Let us assume that the library libmetis.lib
made along this way is in external/new
.
Using ATLAS as optimized BLAS
Here we need the TAUCS version that uses lowercase BLAS (default). As described in Section Using UMFPACK with Microsoft Visual Studio in Compiling UMFPACK the libraries compiled with gcc
are compatible with Microsoft Visual Studio. Use precompiled ATLAS at /files/bin/atlas-3.6-win.tar.gz. Rename the libraries and copy them to external/new
: liblapack.lib
, libf77blas.lib
, libcblas.lib
and libatlas.lib
. Additionally because of technical reasons you will need two libraries libg2c.a
and libgcc.a
from Cygwin. They are in /lib/gcc/i686-pc-mingw32/3.4.4
. It is also necessary to rename them as libg2c.lib
and libgcc.lib
.
Now provided that test_taucs.obj
has been already made with -MD, the command
$ cl -MD test_taucs.obj libtaucs.lib libmetis.lib liblapack.lib libf77blas.lib libcblas.lib libatlas.lib libg2c.lib libgcc.lib -link -LIBPATH:lib/win32 -LIBPATH:external/new
should link the object file with the libraries.
Using AMD ACML as optimized BLAS
AMD ACML is an optimized and precompiled BLAS from AMD. It is free but you have to register to download it
http://developer.amd.com/cpu/Libraries/acml/Pages/default.aspx
Note that it has been compiled with Intel Fortran compiler and to compile with static libraries you need to have Intel Fortran libraries. If you do not have then, then a solution is to use ACML dynamic libraries. They depend on Intel Fortran DLLs but they are supplied together with ACML. The version of the ACML library should match the version of the Visual Studio.
I assume that the library libacml_dll.lib
is in external/new. Then the command
$ cl -MD test_taucs.obj libtaucs.lib libmetis.lib libacml_dll.lib -link -LIBPATH:lib/win32 -LIBPATH:external/new
should link the object file. Note that it is also possible to use multithreaded ACML library. Please check the ACML manual.
Using Intel MKL as optimized BLAS
The situation is the same as in the previous section and the command should like as follows
$ cl -MD test_taucs.obj libtaucs.lib libmetis.lib mkl_intel_c.lib mkl_intel_thread.lib mkl_core.lib libiomp5md.lib -link -LIBPATH:lib/win32 -LIBPATH:external/new
Note that there are other options of using Intel MKL. Please check its manual.
Discussion
New to TAUCS, need to compile with Multi-threaded Debug DLL (/MDd) in VS .NET 2003
taucs with multithreaded debug dll option
RSS