Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Guillaume_A_
New Contributor I
101 Views

Question about mkl_?omatadd

Jump to solution

Hi,

The description of mkl_?omatadd function in the manual is a bit confusing:

- parameter m is described as "The number of matrix rows". Which one ? (A, B or C ?) What if I want to transpose A or B ?

- same question about parameter n.

- Why is ldc an output parameter ??

I wanna do this kind of operation "C = alpha*A + beta*B^t".

Thanks in advance for your help,

Guix

 

0 Kudos
1 Solution
Evarist_F_Intel
Employee
101 Views

Hi Guix,

Yes, you are right, omatadd documentation is slightly confusing.
Thank you for the question. Let me try to clarify.

Parameters m and n stand for rows and columns of matrix C (the only matrix to which op() is not applied). Since you specify the m and n, the matrices op(A) and op(B) should have the same sizes.

lda, ldb and ldc are leading dimensions for original matrices (i.e. with-out any op operations). Of course ldc is not 'out' parameter, but 'in'. This is a typo.

A small examples that performs

C <-- alpha*A + beta*B^T
#include <stdio.h>
#include "mkl.h"

static inline printA(double *x, int rows, int cols, int lda) {
    for (int i = 0; i < rows; ++i) {
        for (int j = 0; j < cols; ++j) {
            printf("%8.0f", x[i*lda + j]);
        }
        printf("\n");
    }
    printf("\n");
}

int main() {
    double a[] = {
        100, 200, 300,
        400, 500, 600,
        700, 800, 900,
          0,   0,   0  };
    double b[] = {
        1, 2, 3, 0, 0,
        4, 5, 6, 0, 0,
        7, 8, 9, 0, 0,
        0, 0, 0, 0, 0  };
    double c[12] = {
        0, 0, 0,
        0, 0, 0,
        0, 0, 0  };

    char transa, transb;
    double alpha = 1., beta = 1.;
    size_t m, n;
    size_t lda = 3, ldb = 5, ldc = 3;

    transa = 'N'; transb = 'T';
    m = 2; n = 3;
    mkl_domatadd('R', transa, transb, m, n, alpha, a, lda, beta, b, ldb, c, ldc);
    printA(c, 2, 3, ldc);

    return 0;
}

Here we get matrix C of form 2x3 with ldc = 3 using block 2x3 from matrix A and 3x2 from matrix B.

The result is:

101     204     307
402     505     608

 

View solution in original post

2 Replies
Evarist_F_Intel
Employee
102 Views

Hi Guix,

Yes, you are right, omatadd documentation is slightly confusing.
Thank you for the question. Let me try to clarify.

Parameters m and n stand for rows and columns of matrix C (the only matrix to which op() is not applied). Since you specify the m and n, the matrices op(A) and op(B) should have the same sizes.

lda, ldb and ldc are leading dimensions for original matrices (i.e. with-out any op operations). Of course ldc is not 'out' parameter, but 'in'. This is a typo.

A small examples that performs

C <-- alpha*A + beta*B^T
#include <stdio.h>
#include "mkl.h"

static inline printA(double *x, int rows, int cols, int lda) {
    for (int i = 0; i < rows; ++i) {
        for (int j = 0; j < cols; ++j) {
            printf("%8.0f", x[i*lda + j]);
        }
        printf("\n");
    }
    printf("\n");
}

int main() {
    double a[] = {
        100, 200, 300,
        400, 500, 600,
        700, 800, 900,
          0,   0,   0  };
    double b[] = {
        1, 2, 3, 0, 0,
        4, 5, 6, 0, 0,
        7, 8, 9, 0, 0,
        0, 0, 0, 0, 0  };
    double c[12] = {
        0, 0, 0,
        0, 0, 0,
        0, 0, 0  };

    char transa, transb;
    double alpha = 1., beta = 1.;
    size_t m, n;
    size_t lda = 3, ldb = 5, ldc = 3;

    transa = 'N'; transb = 'T';
    m = 2; n = 3;
    mkl_domatadd('R', transa, transb, m, n, alpha, a, lda, beta, b, ldb, c, ldc);
    printA(c, 2, 3, ldc);

    return 0;
}

Here we get matrix C of form 2x3 with ldc = 3 using block 2x3 from matrix A and 3x2 from matrix B.

The result is:

101     204     307
402     505     608

 

View solution in original post

Guillaume_A_
New Contributor I
101 Views

Thank you for your explanation Evarist, it makes sense now !

Reply