Skip to content

How to run Valgrind on the C libraries

Saikat Banerjee edited this page Jul 18, 2018 · 3 revisions

The utilities for running Valgrind are provided in devtools/valgrind directory. The following commands are specific to Minion2.

Load the required modules

module load gcc/7.2.0
module load intel/mkl/64/2018/1.163
module load valgrind/3.13.0

The packages liblapack-dev, liblapacke-dev and libblas-dev were also installed using apt.

Try with simple addition

Let us first check if Valgrind works on this computer, and things are set up properly. A trial file addition.c has been written for this purpose. It uses the cblas_dasum function, which return the sum of the absolute values of the input vector array elements. See the reference in MKL and Netlib.

  1. Compile using BLAS
gcc addition.c -lm -lblas -o addition
valgrind --tool=memcheck --leak-check=full ./addition
  1. Compile using MKL
gcc -L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl -std=c99 -DMKL_ILP64 -m64 -I${MKLROOT}/include addition.c -o addition
valgrind --tool=memcheck --leak-check=full ./addition

Valgrind on the TEJAAS libraries

Once everything is set up, running Valgrind on the libraries are very easy.

  1. The file cjpa.c uses the library linear_regression.h. Copy it from ../../lib directory and compile.
cp ../../lib/linear_regression.c linear_regression.h
gcc cjpa.c -lm -g -o cjpa

For quick run, use

./valgrind_cjpa
  1. The file crevreg.c uses the libraries svd.h, utils.h and reverse_regression.h. For quick run, use:
./valgrind_crevreg {option} ## option can be MKL or BLAS

The above script copies the prerequisites in the present directory:

cp ../../lib/reverse_regression.c reverse_regression.h
cp ../../lib/svd.h svd.h
cp ../../lib/utils.h utils.h
cp -r ../../lib/dcdflib ./

The file can be compiled either using MKL:

gcc -L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl -std=c99 -DMKL_ILP64 -m64 -I${MKLROOT}/include crevreg.c -o crevreg

or LAPACKE:

gcc crevreg.c -lm -lblas -llapacke -o crevreg

Finally run valgrind:

valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose ./crevreg

and deletes the header files

rm -rf reverse_regression.h svd.h utils.h dcdflib crevreg