Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Intel Community
- Software
- Software Development SDKs and Libraries
- Intel® oneAPI Math Kernel Library
- LU factorization problem in C/C++

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

mpbl

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-03-2012
03:28 AM

141 Views

LU factorization problem in C/C++

I messed around for a while now and I can't find the solution to a strange bug that I have.

I use the 10.1.1 version of the mkl and the 11.0 version of icc. I wrote a mock-up for LU factorization (?gttrf / ? gttrs).

When compiling with the "-O0" option, all works fine.

But when compiling without optimization indication or with "-O1", "-O2", or "-O3"

I've attached the code below.

Thanks,

Matt.

[cpp]#include#include #include #include #include "mkl_types.h" #include "mkl_lapack.h" int main(int argc, char **argv) { MKL_INT n = 5; double *dl = new double[4]; double *d = new double[5]; double *du = new double[4]; double *du2 = new double[3]; MKL_INT *ipiv = new MKL_INT[5]; double *t = new double[5]; double tmin, tmax; double alpha = 1.e-6f; double dt = 0.001f; double dx = 1.0e-2f; double lambda = dt/(dx*dx); for (int i = 0; i < 4; ++i) { dl = -alpha*lambda; du= -alpha*lambda; } for (int i = 0; i < 5; ++i) { d= 1.f + 2*alpha*lambda; } for (int i = 0; i < 5; ++i) { t= 1.f; } MKL_INT info; MKL_INT ldb = 5; char trans='N'; MKL_INT nrhs = 5; double error = 1.f; // LU factorization of a tridiagonal matrix dgttrf(&n, dl, d, du, du2, ipiv, &info); if (info != 0) { std::cerr << "Error in the LU factorization." << std::endl; return -1; } for (int i = 0; i < 5; ++i) { std::cout << t<< " "; } std::cout << std::endl; // Solve the tridiag LU system dgttrs(&trans, &n, &nrhs, dl, d, du, du2, ipiv, t, &ldb, &info); if (info != 0) { std::cerr << "Error in the LU solver." << std::endl; return -1; } for (int i = 0; i < 5; ++i) { std::cout << t<< " "; } std::cout << std::endl; std::cout << std::endl; delete [] dl; delete [] d; delete [] du; delete [] du2; delete [] ipiv; delete [] t; return 0; } [/cpp]

1 Solution

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-03-2012
10:29 AM

141 Views

MKL_INTnrhs=5;

When you make the call to dgttrs, the library routine will try to use 5 X 5 matrices for X and B in

A X = B

instead of, as you probably intended, 5 X 1 vectors x and b such that

A x = b

Change the value of

Link Copied

6 Replies

Gennady_F_Intel

Moderator

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-03-2012
04:29 AM

141 Views

I cannot seelibmkl_core linked with these examples. Please check with Linker Adviser how to select recommended libraries for linking with mkl 10.1.

--Gennady

mpbl

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-03-2012
04:45 AM

141 Views

As you suggest I modified the command line as :

but the problem remain the same. It segfaults when not using "

Matt.

TimP

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-03-2012
07:40 AM

141 Views

mpbl

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-03-2012
08:10 AM

141 Views

The stack size looks ok.

stack size (kbytes, -s) unlimited

$ versionquery/_results/intel_lp64_parallel_em64t_so/getversionstring_c.out

Intel Math Kernel Library Version 10.1.1 Product Build 082212.12 for Intel 64 architecture applications

That's the version I found in: /opt/intel/Compiler/11.0/083/mkl

I changed it for the version in /opt/intel/mkl/10.1.2.024/lib/em64t, but it gives the same error.

I tried to use valgrind memcheck on the output. For this, i changed the mkl to sequential:

when the following line is commented (only dgttrf is executed) (line 54)

valgrind says there is 0 errors.

when using

where the dgttrs occures.

Is this observation relevant ?

Matt

mecej4

Black Belt

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-03-2012
10:29 AM

142 Views

MKL_INTnrhs=5;

When you make the call to dgttrs, the library routine will try to use 5 X 5 matrices for X and B in

A X = B

instead of, as you probably intended, 5 X 1 vectors x and b such that

A x = b

Change the value of

mpbl

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-05-2012
02:33 AM

141 Views

Thanks mecej4,

It works and I am going to buy a 1st grade reading book.

Matt.

It works and I am going to buy a 1st grade reading book.

Matt.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

For more complete information about compiler optimizations, see our Optimization Notice.