MAGMA  magma-1.4.0
Matrix Algebra on GPU and Multicore Architectures
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
cprint.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
5  Univ. of Colorado, Denver
6  August 2013
7 
8  @author Mark Gates
9  @generated c Tue Aug 13 16:43:32 2013
10 
11 */
12 #include "common_magma.h"
13 
14 #define PRECISION_c
15 
16 #define A(i,j) (A + i + j*lda)
17 
18 // -------------------------
19 // Prints a matrix that is on the CPU host.
20 extern "C"
21 void magma_cprint( magma_int_t m, magma_int_t n, const magmaFloatComplex *A, magma_int_t lda )
22 {
23  if ( magma_is_devptr( A ) == 1 ) {
24  fprintf( stderr, "ERROR: cprint called with device pointer.\n" );
25  exit(1);
26  }
27 
28  magmaFloatComplex c_zero = MAGMA_C_ZERO;
29 
30  if ( m == 1 ) {
31  printf( "[ " );
32  }
33  else {
34  printf( "[\n" );
35  }
36  for( int i = 0; i < m; ++i ) {
37  for( int j = 0; j < n; ++j ) {
38  if ( MAGMA_C_EQUAL( *A(i,j), c_zero )) {
39  printf( " 0. " );
40  }
41  else {
42 #if defined(PRECISION_z) || defined(PRECISION_c)
43  printf( " %8.4f+%8.4fi", MAGMA_C_REAL( *A(i,j) ), MAGMA_C_IMAG( *A(i,j) ));
44 #else
45  printf( " %8.4f", MAGMA_C_REAL( *A(i,j) ));
46 #endif
47  }
48  }
49  if ( m > 1 ) {
50  printf( "\n" );
51  }
52  else {
53  printf( " " );
54  }
55  }
56  printf( "];\n" );
57 }
58 
59 // -------------------------
60 // Prints a matrix that is on the GPU device.
61 // Internally allocates memory on host, copies it to the host, prints it,
62 // and de-allocates host memory.
63 extern "C"
64 void magma_cprint_gpu( magma_int_t m, magma_int_t n, const magmaFloatComplex *dA, magma_int_t ldda )
65 {
66  if ( magma_is_devptr( dA ) == 0 ) {
67  fprintf( stderr, "ERROR: cprint_gpu called with host pointer.\n" );
68  exit(1);
69  }
70 
71  magma_int_t lda = m;
72  magmaFloatComplex* A;
73  magma_cmalloc_cpu( &A, lda*n );
74  magma_cgetmatrix( m, n, dA, ldda, A, lda );
75  magma_cprint( m, n, A, lda );
76  magma_free_cpu( A );
77 }
#define MAGMA_C_EQUAL(u, v)
Definition: magma.h:139
#define MAGMA_C_IMAG(a)
Definition: magma.h:147
int magma_int_t
Definition: magmablas.h:12
#define magma_cgetmatrix(m, n, dA_src, ldda, hB_dst, ldb)
Definition: magmablas_c.h:705
#define A(i, j)
Definition: cprint.cpp:16
static magma_err_t magma_cmalloc_cpu(magmaFloatComplex **ptrPtr, size_t n)
Definition: magma.h:85
#define MAGMA_C_REAL(a)
Definition: magma.h:146
void magma_cprint(magma_int_t m, magma_int_t n, const magmaFloatComplex *A, magma_int_t lda)
Definition: cprint.cpp:21
void magma_cprint_gpu(magma_int_t m, magma_int_t n, const magmaFloatComplex *dA, magma_int_t ldda)
Definition: cprint.cpp:64
magma_err_t magma_free_cpu(void *ptr)
magma_int_t magma_is_devptr(const void *A)
Definition: auxiliary.cpp:47
#define MAGMA_C_ZERO
Definition: magma.h:153
#define dA(dev, i, j)