Monday 15 March 2010

c - Intel MKL SpareBlas mm CSR one-based indexing not working -



c - Intel MKL SpareBlas mm CSR one-based indexing not working -

i testing functions of intel mkl in c test-program , found can't create spareblas: mkl_scsrmm function csr one-based indexing work. using csr val, columns, pntrb , pntre variation. original examples placed in:

"...mkl\examples\examples_core_c\spblasc\source\cspblas_scsr.c"

this first code zero-based indexing:

example #1 #include <stdio.h> #include "mkl_types.h" #include "mkl_spblas.h" int main() { #define m 2 #define nnz 4 mkl_int m = m, nnz = nnz; float values[nnz] = {2.0,4.0,4.0,2.0}; mkl_int columns[nnz] = {1,2,1,2}; mkl_int rowindex[m+1] = {1,3,5}; #define n 2 mkl_int n = n; float b[m][n] = {2.0, 1.0, 5.0, 2.0}; float c[m][n] = {0.0, 0.0, 0.0, 0.0}; float alpha = 1.0, beta = 0.0; char transa, uplo, nonunit; char matdescra[6]; mkl_int i, j, is; transa = 'n'; matdescra[0] = 's'; matdescra[1] = 'l'; matdescra[2] = 'n'; matdescra[3] = 'f'; mkl_scsrmm(&transa, &m, &n, &m, &alpha, matdescra, values, columns, rowindex, &(rowindex[1]), &(b[0][0]), &n, &beta, &(c[0][0]), &n); printf(" \n"); printf(" output info mkl_scsrmm\n"); (i = 0; < m; i++) { (j = 0; j < n; j++) { printf("%7.1f", c[i][j]); }; printf("\n"); }; homecoming 0; }

the results this:

zero-based indexing(the right one):

24.0 10.0

18.0 8.0

one-based indexing:

8.0 10.0

18.0 24.0

though seems changes diagonal elements position, with 3x3 matrix solution completly different right one. suspected might input format of matrix b. think there's lack of clarity on description of array b function mkl_scsrmm placed in mkl reference manual. changed b format, in illustration , worked (i placed elements position in order: `{2.0, 5.0, 1.0, 2.0}) did same 3x3 illustration coded , didn't work think may coincidence. don't know problem, understand happens here.

references:

csr format

https://software.intel.com/en-us/node/471374

spare blas mkl_scsrmm function

https://software.intel.com/sites/products/documentation/doclib/iss/2013/mkl/mklman/hh_goto.htm#guid-78c55d9b-86ff-4a9f-b5d5-d2f61b9314fc.htm

spare blas interface considerations

https://software.intel.com/sites/products/documentation/doclib/iss/2013/mkl/mklman/hh_goto.htm#guid-34c8db79-0139-46e0-8b53-99f3bee7b2d4.htm

and here example, 3x3 one:

example #2 // matrix // // 2 4 3 // 4 2 1 // 3 1 6 // // matrix b // // 2 1 3 // 4 5 6 // 7 8 9 // // zero-based indexing // // = {2 4 3 4 2 1 3 1 6} // columns= {0 1 2 0 1 2 0 1 2} // idexrow = {0 3 6 9} // // b = {2 1 3 4 5 6 7 8 9} (row order array) // // print array in row-major order // // one-based indexing // // = {2 4 3 4 2 1 3 1 6} // columns={1 2 3 1 2 3 1 2 3} // indexrow = {0 3 6 9} // // b = {2 4 7 1 5 8 3 6 9} (column order array) // // print array in column-major order (because resoult in column major order, ie transposed) // // // #include <stdio.h> #include "mkl_types.h" #include "mkl_spblas.h" int main() { #define m 3 #define nnz 9 #define n 3 mkl_int m = m, nnz = nnz, n=n; float a[nnz] = {2.0,4.0,3.0,4.0,2.0,1.0,3.0,1.0,6.0}; mkl_int columns[nnz] = {0,1,2,0,1,2,0,1,2}; mkl_int rowindex[m+1] = {0,3,6,9}; float b[m][n] = {2.0, 1.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; float c[m][n] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; float alpha = 1.0, beta = 0.0; mkl_int i, j; char transa; char matdescra[6]; float a1[nnz] = {2.0,4.0,3.0,4.0,2.0,1.0,3.0,1.0,6.0}; mkl_int columns1[nnz] = {1,2,3,1,2,3,1,2,3}; mkl_int rowindex1[m+1] = {1,4,7,10}; float b1[m][n] = {2.0, 4.0, 7.0, 1.0, 5.0, 8.0, 3.0, 6.0, 9.0}; float c1[m][n] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; //******************************** //zero-based indexing //******************************** transa = 'n'; matdescra[0] = 's'; matdescra[1] = 'l'; matdescra[2] = 'n'; matdescra[3] = 'c'; mkl_scsrmm(&transa, &m, &n, &m, &alpha, matdescra, a, columns, rowindex, &(rowindex[1]), &(b[0][0]), &n, &beta, &(c[0][0]), &n); printf(" \n"); printf(" right solution: zero-based: c \n"); (i = 0; < m; i++) { (j = 0; j < n; j++) { printf("%7.1f", c[i][j]); }; printf("\n"); }; printf(" \n"); printf(" zero-based: c' \n"); (i = 0; < m; i++) { (j = 0; j < n; j++) { printf("%7.1f", c[j][i]); }; printf("\n"); }; //******************************** //one-based indexing //******************************** matdescra[3] = 'f'; mkl_scsrmm(&transa, &m, &n, &m, &alpha, matdescra, a1, columns1, rowindex1, &(rowindex1[1]), &(b1[0][0]), &n, &beta, &(c1[0][0]), &n); printf(" \n"); printf(" one-based: c \n"); (i = 0; < m; i++) { (j = 0; j < n; j++) { printf("%7.1f", c1[i][j]); }; printf("\n"); }; printf(" \n"); printf(" one-based: c' \n"); (i = 0; < m; i++) { (j = 0; j < n; j++) { printf("%7.1f", c1[j][i]); }; printf("\n"); }; homecoming 0; }

i asked same question @ intel's forum , got help there , solution of problem. deal when calling routine c interface zero-based indexing can send matrix stored in array next row-major order (native c array storage), , when phone call routine one-based indexing have store matrix in column-major order. changes way matrix b , c need stored, , way result stored. matrix changes indexing (from 0 1). intel's documentation may think c interface accepts row-major ordering both types of indexing.

notice in general, column-major ordering is not same storing transposed matrix in row-major ordering (it same if matrices square).

c blas csr intel-mkl

No comments:

Post a Comment