MAGMA  magma-1.4.0 Matrix Algebra on GPU and Multicore Architectures
dgetrs_gpu.cpp
Go to the documentation of this file.
1 /*
2  -- MAGMA (version 1.4.0) --
3  Univ. of Tennessee, Knoxville
4  Univ. of California, Berkeley
6  August 2013
7
8  @generated d Wed Aug 14 12:16:04 2013
9
10 */
11 #include "common_magma.h"
12
13 extern "C" magma_int_t
15  double *dA, magma_int_t ldda,
16  magma_int_t *ipiv,
17  double *dB, magma_int_t lddb,
18  magma_int_t *info)
19 {
20 /* -- MAGMA (version 1.4.0) --
21  Univ. of Tennessee, Knoxville
22  Univ. of California, Berkeley
24  August 2013
25
26  Purpose
27  =======
28  Solves a system of linear equations
29  A * X = B or A' * X = B
30  with a general N-by-N matrix A using the LU factorization computed by DGETRF_GPU.
31
32  Arguments
33  =========
34  TRANS (input) CHARACTER*1
35  Specifies the form of the system of equations:
36  = 'N': A * X = B (No transpose)
37  = 'T': A'* X = B (Transpose)
38  = 'C': A'* X = B (Conjugate transpose = Transpose)
39
40  N (input) INTEGER
41  The order of the matrix A. N >= 0.
42
43  NRHS (input) INTEGER
44  The number of right hand sides, i.e., the number of columns
45  of the matrix B. NRHS >= 0.
46
47  A (input) DOUBLE_PRECISION array on the GPU, dimension (LDA,N)
48  The factors L and U from the factorization A = P*L*U as computed
49  by DGETRF_GPU.
50
51  LDA (input) INTEGER
52  The leading dimension of the array A. LDA >= max(1,N).
53
54  IPIV (input) INTEGER array, dimension (N)
55  The pivot indices from DGETRF; for 1<=i<=N, row i of the
56  matrix was interchanged with row IPIV(i).
57
58  B (input/output) DOUBLE_PRECISION array on the GPU, dimension (LDB,NRHS)
59  On entry, the right hand side matrix B.
60  On exit, the solution matrix X.
61
62  LDB (input) INTEGER
63  The leading dimension of the array B. LDB >= max(1,N).
64
65  INFO (output) INTEGER
66  = 0: successful exit
67  < 0: if INFO = -i, the i-th argument had an illegal value
68
69  HWORK (workspace) DOUBLE_PRECISION array, dimension N*NRHS
70  ===================================================================== */
71
72
73  double c_one = MAGMA_D_ONE;
74  double *work = NULL;
75  char trans_[2] = {trans, 0};
76  int notran = lapackf77_lsame(trans_, "N");
77  magma_int_t i1, i2, inc;
78
79  *info = 0;
80  if ( (! notran) &&
81  (! lapackf77_lsame(trans_, "T")) &&
82  (! lapackf77_lsame(trans_, "C")) ) {
83  *info = -1;
84  } else if (n < 0) {
85  *info = -2;
86  } else if (nrhs < 0) {
87  *info = -3;
88  } else if (ldda < max(1,n)) {
89  *info = -5;
90  } else if (lddb < max(1,n)) {
91  *info = -8;
92  }
93  if (*info != 0) {
94  magma_xerbla( __func__, -(*info) );
95  return *info;
96  }
97
98  /* Quick return if possible */
99  if (n == 0 || nrhs == 0) {
100  return *info;
101  }
102
103  magma_dmalloc_cpu( &work, n * nrhs );
104  if ( work == NULL ) {
105  *info = MAGMA_ERR_HOST_ALLOC;
106  return *info;
107  }
108
109  i1 = 1;
110  i2 = n;
111  if (notran) {
112  inc = 1;
113
114  /* Solve A * X = B. */
115  magma_dgetmatrix( n, nrhs, dB, lddb, work, n );
116  lapackf77_dlaswp(&nrhs, work, &n, &i1, &i2, ipiv, &inc);
117  magma_dsetmatrix( n, nrhs, work, n, dB, lddb );
118
119  if ( nrhs == 1) {
120  magma_dtrsv(MagmaLower, MagmaNoTrans, MagmaUnit, n, dA, ldda, dB, 1 );
121  magma_dtrsv(MagmaUpper, MagmaNoTrans, MagmaNonUnit, n, dA, ldda, dB, 1 );
122  } else {
123  magma_dtrsm(MagmaLeft, MagmaLower, MagmaNoTrans, MagmaUnit, n, nrhs, c_one, dA, ldda, dB, lddb );
124  magma_dtrsm(MagmaLeft, MagmaUpper, MagmaNoTrans, MagmaNonUnit, n, nrhs, c_one, dA, ldda, dB, lddb );
125  }
126  } else {
127  inc = -1;
128
129  /* Solve A' * X = B. */
130  if ( nrhs == 1) {
131  magma_dtrsv(MagmaUpper, trans, MagmaNonUnit, n, dA, ldda, dB, 1 );
132  magma_dtrsv(MagmaLower, trans, MagmaUnit, n, dA, ldda, dB, 1 );
133  } else {
134  magma_dtrsm(MagmaLeft, MagmaUpper, trans, MagmaNonUnit, n, nrhs, c_one, dA, ldda, dB, lddb );
135  magma_dtrsm(MagmaLeft, MagmaLower, trans, MagmaUnit, n, nrhs, c_one, dA, ldda, dB, lddb );
136  }
137
138  magma_dgetmatrix( n, nrhs, dB, lddb, work, n );
139  lapackf77_dlaswp(&nrhs, work, &n, &i1, &i2, ipiv, &inc);
140  magma_dsetmatrix( n, nrhs, work, n, dB, lddb );
141  }
142  magma_free_cpu(work);
143
144  return *info;
145 }
146
#define MAGMA_D_ONE
Definition: magma.h:176
#define MagmaLeft
Definition: magma.h:68
#define __func__
Definition: common_magma.h:65
#define MagmaUpper
Definition: magma.h:61
magma_int_t ldda
void magma_dtrsm(magma_side_t side, magma_uplo_t uplo, magma_trans_t trans, magma_diag_t diag, magma_int_t m, magma_int_t n, double alpha, magmaDouble_const_ptr dA, magma_int_t ldda, magmaDouble_ptr dB, magma_int_t lddb)
void lapackf77_dlaswp(const magma_int_t *n, double *A, const magma_int_t *lda, const magma_int_t *k1, const magma_int_t *k2, magma_int_t *ipiv, const magma_int_t *incx)
int magma_int_t
Definition: magmablas.h:12
void magma_dtrsv(magma_uplo_t uplo, magma_trans_t trans, magma_diag_t diag, magma_int_t n, magmaDouble_const_ptr dA, magma_int_t ldda, magmaDouble_ptr dx, magma_int_t incx)
#define magma_dgetmatrix(m, n, dA_src, ldda, hB_dst, ldb)
Definition: magmablas_d.h:705
#define dB(dev, i, j)
#define MagmaLower
Definition: magma.h:62
void magma_xerbla(const char *srname, magma_int_t info)
Definition: xerbla.cpp:8
#define lapackf77_lsame
Definition: magma_lapack.h:23
static magma_err_t magma_dmalloc_cpu(double **ptrPtr, size_t n)
Definition: magma.h:84
magma_int_t magma_dgetrs_gpu(char trans, magma_int_t n, magma_int_t nrhs, double *dA, magma_int_t ldda, magma_int_t *ipiv, double *dB, magma_int_t lddb, magma_int_t *info)
Definition: dgetrs_gpu.cpp:14
#define MagmaNonUnit
Definition: magma.h:65
#define MagmaUnit
Definition: magma.h:66
#define MagmaNoTrans
Definition: magma.h:57
#define max(a, b)
Definition: common_magma.h:82
magma_err_t magma_free_cpu(void *ptr)
#define MAGMA_ERR_HOST_ALLOC
Definition: magma_types.h:275
#define dA(dev, i, j)
#define magma_dsetmatrix(m, n, hA_src, lda, dB_dst, lddb)
Definition: magmablas_d.h:702