LAPACK Archives

[Lapack] Convention of BLAS inside of Lapack

Tony,
Fortran follows column major storage. By the same token, Fortran BLAS
follows
column major storage. CBLAS lets you specify if you want column major or row
major. Perhaps you specified row major in CBLAS, and assumed that BLAS does
the same, which is not the case. C=AxB in row major is equivalent to C=BxA
in
column major.
Jakub

On 8/21/07, scott@Domain.Removed <scott@Domain.Removed> wrote:

Dear Sirs,

I have the following quandery.  I have downloaded both CBLAS and CLAPACK
which
uses the f2c version of BLAS.  I cannot help but get the impression that
these
two different versions of BLAS follow a different convention.

For matrix multiplication, I looked at sgemm.

Using CBLAS, I could get C = A*B

However, to get an equivalent result, I had in effect to compute C^T =
A^T*B^T i.e. C = B*A
The code is shown below the =====

All the other settings are the same, as far as I can tell.

Are not the versions of BLAS, the same?

best wishes and thanks in advance for any feedback,

Tony Scott
RWTH-Aachen
Germany





================================

E.g. Using CBLAS with ATLAS and the following routine:


#include <stdio.h>
#include </users/tonys/BLAS/cblas.h>
     int
     main (void)
     {
        /*int lda = 3; float A[] = { 0.11, 0.12, 0.13, 0.21, 0.22, 0.23};*/
       int lda = 2;
       float A[] = { 0.11, 0.12, 0.13, 0.21 };
       printf ("[ %g, %g\n", A[0], A[1]);
       printf ("  %g, %g ]\n", A[2], A[3]);
       int ldb = 2;
       float B[] = { 1011, 1012, 1021, 1022, 1031, 1032 };
       printf ("[ %g, %g\n", B[0], B[1]);
       printf ("  %g, %g ]\n", B[2], B[3]);

       /*int ldc = 2; float C[] = { 0.00, 0.00, 0.00, 0.00 };  */
       int ldc = 2;
       float C[] = { 0.00, 0.00, 0.00, 0.00 };

       /* Compute C = A B */
       /* cblas_sgemm */
       /*sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, 2, 2, 3, 1.0, A,
lda, B, ldb, 0.0, C, ldc); */
       sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, 2, 2, 2, 1.0, A,
lda, B, ldb, 0.0, C, ldc);

       printf ("[ %g, %g\n", C[0], C[1]);
       printf ("  %g, %g ]\n", C[2], C[3]);

       return 0;
     }
~

I get:

[ 0.11, 0.12
  0.13, 0.21 ]
[ 1011, 1012
  1021, 1022 ]
[ 233.73, 233.96
  345.84, 346.18 ]

But when using CBLAS inside Lapack using:

#include <stdio.h>
#include </users/tonys/BLAS/clapack/CLAPACK/BLAS/WRAP/blaswrap.h>
#include </users/tonys/BLAS/clapack/CLAPACK/BLAS/WRAP/cblas.h>
#include </users/tonys/BLAS/clapack/CLAPACK/F2CLIBS/f2c.h>

/*  -- translated by f2c (version 19990503).
   You must link the resulting object file with the libraries:
        -lf2c -lm   (in that order)
*/
/* Main program */ MAIN__(void)
{
       extern /* Subroutine */ sgemm_( char *, char *, integer *, integer
*,
            integer *, real *, real *, integer *, real *, integer *,
            real *, real *, integer *);

       static char transa[1], transb[1];
       static real alpha;
       static real beta;
       static integer m,n,k;
       static integer lda,ldb,ldc;
       /*lda = 3; static real A[] = { 0.11, 0.12, 0.13, 0.21, 0.22, 0.23}; */
       lda = 2;
       static real A[] = { 0.11, 0.12, 0.13, 0.21};

       printf ("[ %g, %g\n", A[0], A[1]);
       printf ("  %g, %g ]\n", A[2], A[3]);



       alpha = 1.0;
       beta = 0.0;
       /*m=2; n=2; k=3; */
       m=2; n=2; k=2;

       /*ldb = 2; static real B[] = { 1011.0, 1012.0, 1021.0, 1022.0,
1031.0, 1032.0 }; */
       ldb = 2;
       static real B[] = { 1011.0, 1012.0, 1021.0, 1022.0};

       printf ("[ %g, %g\n", B[0], B[1]);
       printf ("  %g, %g ]\n", B[2], B[3]);

       ldc = 2;
       static real C[] = { 0.00, 0.00, 0.00, 0.00 };

       *(unsigned char *)transa = 'T';
       *(unsigned char *)transb = 'T';

       /* Compute C = A B */
       /* cblas_sgemm */
       /*sgemm_(CblasNoTrans, CblasNoTrans, 2, 2, 3, */
       sgemm_(transa, transb, &m, &n, &k, &alpha, &A[0], &lda, &B[0],
&ldb, &beta, &C[0], &ldc);


       printf ("[ %g, %g\n", C[0], C[1]);
       printf ("  %g, %g ]\n", C[2], C[3]);

       return 0;
} /* MAIN__

        Main program alias */ int testblas_ () { MAIN__ (); return 0; }


which produces:

[ 0.11, 0.12
  0.13, 0.21 ]
[ 1011, 1012
  1021, 1022 ]
[ 233.73, 345.84
  233.96, 346.18 ]

The resulting C matrix is the transpose of the earlier result


_______________________________________________
Lapack mailing list
Lapack@Domain.Removed
http://lists.cs.utk.edu/listinfo/lapack



-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://lists.cs.utk.edu/private/lapack/attachments/20070822/cf0a22a5/attachment.html
 

<Prev in Thread] Current Thread [Next in Thread>


For additional information you may use the LAPACK/ScaLAPACK Forum.
Or one of the mailing lists, or