run_taucs matrix rhs
in the Matrix Market format and then writes the solution of the system of linear equations in file
rhs.solution also in the Matrix Market format.
The code is presented in run_taucs.cpp and is briefly explained below. It is assumed that you have already browsed the TAUCS documentation.
SparseMatrix mat is initialized from the file
matrix (first argument in the command line).
2a) The TAUCS matrix is created. TAUCS uses Compressed Column Storage (CCS), see for example http://netlib.org/linalg/html_templates/node92.html. If the matrix is symmetic, then no changes are required because in this case row storage chosen in
SparseMatrix can be treated as column storage. For a symmetric matrix it is after all just a matter of interpreting the indices. However, if the matrix is unsymmetric it is necessary first to transpose it, and only after that treat rows as columns.
SparseMatrix is iterated through all nonzero elements and they are copied into the TAUCS CCS matrix. Finally the memory to keep
SparseMatrix is freed up.
3) The right hand side is read in
Matrix rhs. Note that it can contain several vectors in the case when we need to solve the linear system several times with different right-hand sides.
4) Before starting solution we initialize the matrix to keep it with the same dimensions as
4a) We call
taucs_linsolve. Please not that it is buggy and if you need to try different options it is more reliably to use low-level TAUCS functions (see Section Working with TAUCS by using low-level functions at Compiling and Using TAUCS under Microsoft Visual Studio). The low-level TAUCS functions will be used later in the class
4b) We check if solution has been successful if and if yes we go to next step.
4c) The norm
| Ax - rhs | is computed and printed. After that the solution is saved into the file.
5) Clean up memory.
$ cl -I path_to_taucs_header -I LinearSolver -O2 -EHsc -MD -D_SECURE_SCL=0 -c run_taucs.cpp
Here it is necessary to specify the correct path to the TAUCS header. The second
-I gives the path to matrices.h and auxiliary.h that are in the subdirectory LinearSolver. After that we need to compile
matrices.cpp, as functions from
SparseMatrix should be compiled as well.
$ cl -I LinearSolver -O2 -EHsc -MD -D_SECURE_SCL=0 -c LinearSolver/matrices.cpp
Finally it is necessary to link object files with each other as well as with TAUCS, METIS and BLAS libraries (in the example below I use MKL as BLAS):
$ cl run_taucs.obj matrices.obj libtaucs.lib libmetis.lib mkl_intel_c.lib mkl_intel_thread.lib mkl_core.lib libiomp5md.lib -link -LIBPATH:path_to_libraries
Here it is important to put the path to the libraries that the linker can find them. Note that the MS linker also searches the path specified by the LIB environment variables.
The three steps above are written within the makefile run_taucs.make and the command
$ make -f run_taucs.make
takes necessary steps to compile
run_taucs provided that you have specified the paths to the headers and libraries in the makefile correctly.
$ ./run_taucs 3x3.mtx 3x1.mtx
should write solution (9.25 8.5 5.75) in the file
3x1.mtx.solution. The command
$ ./run_taucs 3x3.mtx 3x3.mtx
should produce the identity matrix as the solution to
AX = A.