Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9204761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:47:11+00:00 2026-06-17T23:47:11+00:00

I’m having a problem with ATLAS ‘ method clapack_sgesv (corresponding FORTRAN method: sgesv.f )

  • 0

I’m having a problem with ATLAS‘ method clapack_sgesv (corresponding FORTRAN method: sgesv.f) when I try to use it with matrices stored in row-major storage order.

I use Eigen3 for most linear algebra tasks in my application but have recently started to replace some internal Eigen routines with calls to ATLAS’ cblas and clapack methods. My application must support switching the matrix storage order to row-major by defining Eigen’s EIGEN_DEFAULT_TO_ROW_MAJOR flag. This of course works out of the box with Eigen’s methods, but requires different code paths for the clapack_ calls. I’ve run into a problem when replacing Eigen’s .partialPivLu().solve() call with ATLAS’ clapack_sgesv method. Here is a minimal code example that illustrates the problem:

#include <iostream>
#define EIGEN_DEFAULT_TO_ROW_MAJOR
#include <eigen3/Eigen/Eigen>
extern "C" {
#include <clapack.h>
}
using namespace std;

int main()
{
  Eigen::MatrixXf A( 4, 4 );
  A <<  0.680375 ,  0.823295 , -0.444451  , -0.270431  ,
       -0.211234 , -0.604897 ,  0.10794   ,  0.0268018 ,
        0.566198 , -0.329554 , -0.0452059 ,  0.904459  ,
        0.59688  ,  0.536459 ,  0.257742  ,  0.83239   ;

  Eigen::MatrixXf B( 4, 4 );
  B <<  0.271423 , -0.967399 , -0.686642  ,  0.997849  ,
        0.434594 , -0.514226 , -0.198111  , -0.563486  ,
       -0.716795 , -0.725537 , -0.740419  ,  0.0258648 ,
        0.213938 ,  0.608353 , -0.782382  ,  0.678224  ;

  cout << "----- Eigen" << endl;

  cout << "A = " << endl << A << endl;
  cout << "B = " << endl << B << endl;
  Eigen::MatrixXf X = A.partialPivLu().solve( B );
  cout << "X = " << endl << X << endl;
  cout << "AX = " << endl << A * X << endl;

  cout << "----- ATLAS" << endl;

  Eigen::VectorXi ipiv( 4 );

  clapack_sgesv(
#ifdef EIGEN_DEFAULT_TO_ROW_MAJOR
    CblasRowMajor,
#else
    CblasColMajor,
#endif
    A.rows(),
    B.cols(),
    A.data(),
#ifdef EIGEN_DEFAULT_TO_ROW_MAJOR
    A.cols(),
#else
    A.rows(),
#endif
    ipiv.data(),
    B.data(),
#ifdef EIGEN_DEFAULT_TO_ROW_MAJOR
    B.cols()
#else
    B.rows()
#endif
  );

  cout << "piv = " << ipiv.transpose() << endl;
  cout << "LU = " << endl << A << endl;
  cout << "X =" << endl << B << endl;

  return 0;
}

I compile this with g++ -std=c++11 -Wall -Wextra -g -llapack -lcblas -latlas. The above clapack_sgesv call gives the same results as Eigen’s solver as long as EIGEN_DEFAULT_TO_ROW_MAJOR is not defined.

----- Eigen
A = 
  0.680375   0.823295  -0.444451   -0.270431
 -0.211234  -0.604897   0.10794     0.0268018
  0.566198  -0.329554  -0.0452059   0.904459
   0.59688   0.536459   0.257742    0.83239
B = 
 0.271423 -0.967399 -0.686642  0.997849
 0.434594 -0.514226 -0.198111 -0.563486
-0.716795 -0.725537 -0.740419  0.0258648
 0.213938  0.608353 -0.782382  0.678224
X = 
  4.29176  -3.45693   -3.46864   0.547927
 -1.3688    2.04333    1.13806   0.735351
  5.6716   -0.593909  -2.65158  -0.0154493
 -3.69446   2.07672    1.6349   -0.0472447
AX = 
 0.271423  -0.967399  -0.686642   0.997849
 0.434594  -0.514226  -0.198111  -0.563486
-0.716796  -0.725537  -0.740419   0.0258648
 0.213938   0.608353  -0.782382   0.678224
----- ATLAS
piv = 0 2 3 3
LU = 
 0.680375   0.823295  -0.444451  -0.270431
 0.832185  -1.01469    0.32466    1.12951
 0.877281   0.183112   0.588201   0.862807
-0.310467   0.344235  -0.241085  -0.237964
X =
  4.29176   -3.45694   -3.46864    0.547927
 -1.3688     2.04333    1.13806    0.735351
  5.6716    -0.593909   -2.65158  -0.0154493
 -3.69446    2.07672    1.6349    -0.0472447

If I define it, the ATLAS’ results are wrong.

----- Eigen
[... same as above ...]
----- ATLAS
piv = 1 1 3 3
LU = 
 0.823295  0.826405  -0.328474  -0.539844
-0.604897  0.288656  -0.595488  -0.757338
-0.329554  0.838543   1.29555    0.31797
 0.536459  0.153548   1.10004    0.313854
X =
 -2.21567   2.33841  -0.554441  1.45218
 -2.60368   1.14776  -3.83383   1.63747
 -5.05167   2.4991   -3.36881   3.08596
  6.03571  -1.84576   8.32067  -4.90008

My first suspicion was of course that I had messed something up with the clapack_sgesv() call. But other than setting the storage order and switching the leading dimensions from the number of rows to the number of cols there seems nothing to be necessary.

Another really confusing thing I’ve noticed is the following: When I try to solve only for a single right-hand-side, the clapack_sgesv() call fails with Parameter 8 to routine clapack_sgesv was incorrect, ldb must be >= MAX(N,1): ldb=1 N=4. This does not make any sense mathematically.

I suspect that my error must be kind of obvious, but I don’t see it.

What is wrong with my clapack_sgesv() call that causes it to fail in row-major storage order?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:47:12+00:00Added an answer on June 17, 2026 at 11:47 pm

    I’ve found my mistake. As explained in the ATLAS FAQ the right hand side is not treated like a matrix, but a collection of column-vectors that are adjacent in memory. This does not make a difference if the storage order is column-major, but it does for row-major storage order, because the elements of a column vector are no longer adjacent in memory. It works if one always stores RHS and solution “matrix” in column-major format.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am confused How to use looping for Json response Array in another Array.
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I've tracked down a weird MySQL problem to the two different ways I was
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have been unable to fix a problem with Java Unicode and encoding. The
I'm having trouble keeping the paragraph square between the quote marks. In firefox the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.