xref: /petsc/src/mat/impls/aij/seq/aijmkl/aijmkl.h (revision 7efe37a1cedd385a2f501b843d47cdf14dfb49ea)
1 /*
2   Wrappers for mkl_cspblas_ routines.
3   A more elegant way to do this would be to use an approach like that used in petsclbaslapack_mangle.h,
4   but since the MKL sparse BLAS routines are not going to be as widely used, and because
5   we don't have to worry about Fortran name mangling, this seems OK for now.
6 */
7 
8 /* Have to redefine MKL_Complex16 and MKL_Complex8 as PetscScalar for the complex number cases.
9  * This works fine with a C99 compiler -- still need to verify that this works with C89.
10  * Note: These definitions need to occur BEFORE including MKL headers. */
11 #define MKL_Complex16 PetscScalar
12 #define MKL_Complex8  PetscScalar
13 
14 #if !defined(PETSC_USE_COMPLEX)
15   #if defined(PETSC_USE_REAL_SINGLE)
16     #define mkl_cspblas_xcsrgemv(transa, m, a, ia, ja, x, y) mkl_cspblas_scsrgemv(transa, m, a, ia, ja, x, y)
17   #elif defined(PETSC_USE_REAL_DOUBLE)
18     #define mkl_cspblas_xcsrgemv(transa, m, a, ia, ja, x, y) mkl_cspblas_dcsrgemv(transa, m, a, ia, ja, x, y)
19   #endif
20 #else
21   #if defined(PETSC_USE_REAL_SINGLE)
22     #define mkl_cspblas_xcsrgemv(transa, m, a, ia, ja, x, y) mkl_cspblas_ccsrgemv(transa, m, a, ia, ja, x, y)
23   #elif defined(PETSC_USE_REAL_DOUBLE)
24     #define mkl_cspblas_xcsrgemv(transa, m, a, ia, ja, x, y) mkl_cspblas_zcsrgemv(transa, m, a, ia, ja, x, y)
25   #endif
26 #endif
27 
28 /* Note: MKL releases prior to the end of 2014 do not have a const-correct interface -> ugly casts necessary.
29          Does not apply to mkl_sparse_x_*()-routines, because these have been introduced later. */
30 #if !defined(PETSC_USE_COMPLEX)
31   #if defined(PETSC_USE_REAL_SINGLE)
32     #define mkl_xcsrmv(transa, m, k, alpha, matdescra, val, indx, pntrb, pntre, x, beta, y) mkl_scsrmv(transa, m, k, alpha, matdescra, (MatScalar *)val, (PetscInt *)indx, (PetscInt *)pntrb, (PetscInt *)pntre, (PetscScalar *)x, beta, y)
33   #elif defined(PETSC_USE_REAL_DOUBLE)
34     #define mkl_xcsrmv(transa, m, k, alpha, matdescra, val, indx, pntrb, pntre, x, beta, y) mkl_dcsrmv(transa, m, k, alpha, matdescra, (MatScalar *)val, (PetscInt *)indx, (PetscInt *)pntrb, (PetscInt *)pntre, (PetscScalar *)x, beta, y)
35   #endif
36 #else
37   #if defined(PETSC_USE_REAL_SINGLE)
38     #define mkl_xcsrmv(transa, m, k, alpha, matdescra, val, indx, pntrb, pntre, x, beta, y) mkl_ccsrmv(transa, m, k, alpha, matdescra, (MatScalar *)val, (PetscInt *)indx, (PetscInt *)pntrb, (PetscInt *)pntre, (PetscScalar *)x, beta, y)
39   #elif defined(PETSC_USE_REAL_DOUBLE)
40     #define mkl_xcsrmv(transa, m, k, alpha, matdescra, val, indx, pntrb, pntre, x, beta, y) mkl_zcsrmv(transa, m, k, alpha, matdescra, (MatScalar *)val, (PetscInt *)indx, (PetscInt *)pntrb, (PetscInt *)pntre, (PetscScalar *)x, beta, y)
41   #endif
42 #endif
43 
44 #if !defined(PETSC_USE_COMPLEX)
45   #if defined(PETSC_USE_REAL_SINGLE)
46     #define mkl_sparse_x_create_csr mkl_sparse_s_create_csr
47   #elif defined(PETSC_USE_REAL_DOUBLE)
48     #define mkl_sparse_x_create_csr mkl_sparse_d_create_csr
49   #endif
50 #else
51   #if defined(PETSC_USE_REAL_SINGLE)
52     #define mkl_sparse_x_create_csr mkl_sparse_c_create_csr
53   #elif defined(PETSC_USE_REAL_DOUBLE)
54     #define mkl_sparse_x_create_csr mkl_sparse_z_create_csr
55   #endif
56 #endif
57 
58 #if !defined(PETSC_USE_COMPLEX)
59   #if defined(PETSC_USE_REAL_SINGLE)
60     #define mkl_sparse_x_mv mkl_sparse_s_mv
61   #elif defined(PETSC_USE_REAL_DOUBLE)
62     #define mkl_sparse_x_mv mkl_sparse_d_mv
63   #endif
64 #else
65   #if defined(PETSC_USE_REAL_SINGLE)
66     #define mkl_sparse_x_mv mkl_sparse_c_mv
67   #elif defined(PETSC_USE_REAL_DOUBLE)
68     #define mkl_sparse_x_mv mkl_sparse_z_mv
69   #endif
70 #endif
71 
72 #if !defined(PETSC_USE_COMPLEX)
73   #if defined(PETSC_USE_REAL_SINGLE)
74     #define mkl_sparse_x_export_csr mkl_sparse_s_export_csr
75   #elif defined(PETSC_USE_REAL_DOUBLE)
76     #define mkl_sparse_x_export_csr mkl_sparse_d_export_csr
77   #endif
78 #else
79   #if defined(PETSC_USE_REAL_SINGLE)
80     #define mkl_sparse_x_export_csr mkl_sparse_c_export_csr
81   #elif defined(PETSC_USE_REAL_DOUBLE)
82     #define mkl_sparse_x_export_csr mkl_sparse_z_export_csr
83   #endif
84 #endif
85