Compiling and Using TAUCS under Microsoft Visual Studio with -MD

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


Comments

21 responses to “Compiling and Using TAUCS under Microsoft Visual Studio with -MD”

Comments are now closed
  1. matt says:

    Hello,

    I have finished the step that generate libtaucs.lib and libmetis.lib.
    So, what am I suppose to do next?
    There is still LNK2005 error in VS.

    Thank you very much

    Matt

  2. matt says:

    Hello,

    After reading it again, I have got it working under MD,MDd option.
    Your site is such a great help.

    Thank you very much

    Matt

  3. I am glad to hear that. I would appreciate if you describe how the text could be improved to make it more understandable.

  4. tbeu says:

    Is it possible to get an update of the Atlas libs?

  5. I do not use ATLAS any more, so there no drive to compile the latest version.

    Yet, if you would like to try it, I would be glad to help you. I guess that with the latest gcc under cygwin this should be doable.

  6. Hong Wei says:

    Hi. I noticed that you didn’t mention anything about vcf2c.lib. Are we suppose to use the one given in taucs_full.zip or are we suppose compile a copy using the -MD flag from source? I found a website (http://gunkies.org/wiki/F2c) which supposedly provides the source to compile vcf2c.lib and the fortran translator f2c.exe and header file f2c.h. However I can’t seem to compile vcf2c.lib using the instructions provided. How did you guys resolve this problem?

    Lastly, to Evgenii, I have a very novice question. I read from one of the google group discussion where you mentioned that taucs is for positive definite matrices. I would like to know whether you meant 1) taucs is ONLY for positive definite matrices or 2) use taucs for positive definite matrices but implcitly, it could be used for non-symmetric matrices as well. The reason I’m asking this is because I’ve come across a project (http://leyvand.com/research/adv-graphics/ex1.htm) which uses taucs to solve a matrix which I’m quite sure is not symmetric and hence cannot be positive definite. The author apparently compiled his own copy of taucs but unfortunately it is compiled using -MT and I need mine to be -MD to work with my copy of OpenCV. Any ideas how this is done?

    Thanks and sorry for the long post.

  7. hw says:

    Hi. I managed to compile v2f2c.lib from the above website. If anyone is interested to know or have the same problem as me, you can solve it by searching for and remove removing “Notice” and “Readme” from a variable in the makefile.

    With that, it is possible compile a project in VS using MD flag and run test_taucs.cpp provided by Evgenii without any problem. However, it still crash when solving non-symmetric matrix even though I have set option to factorize using LU. The log file indicates that it crashed when it is permuting the matrix. I would appreciate it if anyone has a solution or could suggest an alternative sparse linear solver. Mumps is not an option as I do not have Intel fortran compiler and search online seems that the compiler is not free. Thanks in advance.

    – hw

  8. hw says:

    Hi I noticed that there was no mention of how to compile vcf2c.lib. I found a copy at http://gunkies.org/wiki/F2c. To compile it you have to search for and remove “Notice” and “Readme” from a variable in the makefile. With that, it is possible compile a project in VS using MD flag and run test_taucs.cpp provided by Dr Evgenii without any problem.

    However, it still crash when solving non-symmetric matrix even though I have set option to factorize using LU. The log file indicates that it crashed when it is permuting the matrix. I would appreciate it if anyone has a solution or could suggest an alternative sparse linear solver. Mumps is not an option as I do not have Intel fortran compiler and search online seems that the compiler is not free. Thanks in advance.

    – hw

  9. I will answer your question from three previous posts at once. Please note that the site is moderated (because of spam), so please be patient.

    1) vcf2c.lib

    libg2c.lib is its equivalent. So with libg2c.lib it is unnecessary.

    2) What matrices can TAUCS solve

    TAUCS can solve positive-definite, indefinite and unsymmetric matrices. However the last two solvers are pretty slow, so I do not have a lot of experience with them. Yet, when you compile TAUCS, you have them as well.

    3) test_taucs.cpp with unsymmetric matrices

    taucs_linsolve is buggy. Use test_taucs_lowlevel.cpp to run unsymmetric solver. With low-level functions it must work.

    4) MUMPS

    You can use gfortran under cygwin to compile MUMPS. Or if you would like to work with MS VC, you can use g95. Short note on this is here

    http://blog.rudnyi.ru/2010/05/compiling-mumps-with-g95-and-ms-visual-c.html

  10. hw says:

    Hi. Thank you very much for the information. Lastly I apologize for the “spam”. I initially did not realize the posts were being moderated and I thought the post did not get sent through which is why I sent again. Truly sorry for that.

  11. You do not have to apologize. You have made everything correct.

    Thank you for your interest to my site. You are welcome.

  12. kyewong says:

    Thanks very much Evgenii, I’ve done it successfully under your instruction!
    I just have one more point to supplement. When building libmetis.lib and libtaucs.lib, it is VERY important to change the link flags to /MDd and /MD respectively for the debug and release versions, and the program using taucs should also distinguish the debug/release version of the *.lib files used. Otherwise, only one of the debug or release version of the program will run normally and the other one may corrupt at some function (eg. taucs_ccs_factor_llt_mf)

  13. I am glad to hear that you have done it and thanks a lot for your feedback.

  14. Aung San Htoo says:

    Hello,

    I am now solving least square method by using Taucs Library but I don’t how to call function. is it suppport linear system to solve least square method? if you know , share me how to use with sample code. I am facing to solve this least square method equation (Ax = b).

  15. Taucs solves a system of linear equations Ax = b when A is square. To solve least squares with TAUCS, you have to form normal equations manually. See also

    http://groups.google.com/group/matrixprogramming/t/212c2652df38692e

  16. Aung San Htoo says:

    Thanks Evgenii Rudnyi

  17. bishuiliuyun says:

    Hello,
    I started to learn TAUCS about one week ago and I have finished the TAUCS library compiled after reading the document Compiling and Using TAUCS under Microsoft Visual Studio.But I must use it in MFC.So I need to recompile TAUCS under –MD.After reading it again and again, I still did not succeed in windows. I would greatly appreciate if you give me library compiled.
    Best Wishes.I am looking forward to your reply.

  18. bishuiliuyun says:

    Hello,
    I have successfully use TAUCS under Visual Studio 2008. Thanks for your website.

  19. vahid says:

    Hi,

    I successfully used TAUCS in MT and it works fine. But I could not use it in MD. I spend a few days to recompile the libraries in MD but I was not successful. Is there any way that you can compile and upload them on the website? It would be a great help to me

    Thanks!

  20. SuccessLove says:

    Hello,
    I have done as your present above and success to build test_taucs.cpp.
    But when I run the test_taucs.exe,it got to an error at ” int i = taucs_linsolve(&A, &F, 1, x, b, options, opt_arg);”
    Can you help me?Thank you very much.

  21. SuccessLove says:

    Hello,
    I have compile and run “test_taucs.cpp” successly in commond window.
    But when I compile it in Visual Studio 2008,it come to a runtime error!
    “R6034 An application has made an attempt to load the C runtime library incorrectly.”

    I have annother question,does The compile option “MD” and “MDd” matter?

    Thank you very much!