1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
/*
-- MAGMA (version 2.9.0) --
Univ. of Tennessee, Knoxville
Univ. of California, Berkeley
Univ. of Colorado, Denver
@date January 2025
@precisions normal z -> s d c
@author Hartwig Anzt
*/
#include "magmasparse_internal.h"
//#include <stdlib.h>
/**
Purpose
-------
Allocates memory for magma_z_matrix and initializes it
with the passed value.
Arguments
---------
@param[out]
x magma_z_matrix*
vector to initialize
@param[in]
mem_loc magma_location_t
memory for vector
@param[in]
num_rows magma_int_t
desired length of vector
@param[in]
num_cols magma_int_t
desired width of vector-block (columns of dense matrix)
@param[in]
values magmaDoubleComplex
entries in vector
@param[in]
queue magma_queue_t
Queue to execute in.
@ingroup magmasparse_zaux
********************************************************************/
extern "C" magma_int_t
magma_zvinit(
magma_z_matrix *x,
magma_location_t mem_loc,
magma_int_t num_rows,
magma_int_t num_cols,
magmaDoubleComplex values,
magma_queue_t queue )
{
magma_int_t info = 0;
// make sure the target structure is empty
magma_zmfree( x, queue );
x->ownership = MagmaTrue;
x->val = NULL;
x->diag = NULL;
x->row = NULL;
x->rowidx = NULL;
x->col = NULL;
x->list = NULL;
x->blockinfo = NULL;
x->dval = NULL;
x->ddiag = NULL;
x->drow = NULL;
x->drowidx = NULL;
x->dcol = NULL;
x->dlist = NULL;
x->storage_type = Magma_DENSE;
x->memory_location = mem_loc;
x->sym = Magma_GENERAL;
x->diagorder_type = Magma_VALUE;
x->fill_mode = MagmaFull;
x->num_rows = num_rows;
x->num_cols = num_cols;
x->nnz = num_rows*num_cols;
x->max_nnz_row = num_cols;
x->diameter = 0;
x->blocksize = 1;
x->numblocks = 1;
x->alignment = 1;
x->major = MagmaColMajor;
x->ld = num_rows;
if ( mem_loc == Magma_CPU ) {
CHECK( magma_zmalloc_cpu( &x->val, x->nnz ));
for( magma_int_t i=0; i<x->nnz; i++) {
x->val[i] = values;
}
}
else if ( mem_loc == Magma_DEV ) {
CHECK( magma_zmalloc( &x->val, x->nnz ));
magmablas_zlaset( MagmaFull, x->num_rows, x->num_cols, values, values, x->val, x->num_rows, queue );
}
cleanup:
return info;
}
/**
Purpose
-------
Allocates memory for magma_z_matrix and initializes it
with random values.
Arguments
---------
@param[out]
x magma_z_matrix*
vector to initialize
@param[in]
mem_loc magma_location_t
memory for vector
@param[in]
num_rows magma_int_t
desired length of vector
@param[in]
num_cols magma_int_t
desired width of vector-block (columns of dense matrix)
@param[in]
queue magma_queue_t
Queue to execute in.
@ingroup magmasparse_zaux
********************************************************************/
extern "C" magma_int_t
magma_zvinit_rand(
magma_z_matrix *x,
magma_location_t mem_loc,
magma_int_t num_rows,
magma_int_t num_cols,
magma_queue_t queue )
{
magma_int_t info = 0;
// make sure the target structure is empty
magma_zmfree( x, queue );
x->ownership = MagmaTrue;
magma_z_matrix x_h = {Magma_CSR};
x->val = NULL;
x->diag = NULL;
x->row = NULL;
x->rowidx = NULL;
x->col = NULL;
x->list = NULL;
x->blockinfo = NULL;
x->dval = NULL;
x->ddiag = NULL;
x->drow = NULL;
x->drowidx = NULL;
x->dcol = NULL;
x->dlist = NULL;
x->storage_type = Magma_DENSE;
x->memory_location = mem_loc;
x->sym = Magma_GENERAL;
x->diagorder_type = Magma_VALUE;
x->fill_mode = MagmaFull;
x->num_rows = num_rows;
x->num_cols = num_cols;
x->nnz = num_rows*num_cols;
x->max_nnz_row = num_cols;
x->diameter = 0;
x->blocksize = 1;
x->numblocks = 1;
x->alignment = 1;
x->major = MagmaColMajor;
x->ld = num_rows;
if ( mem_loc == Magma_CPU ) {
/* Intializes random number generator */
srand((unsigned) 1);
CHECK( magma_zmalloc_cpu( &x->val, x->nnz ));
for( magma_int_t i=0; i<x->nnz; i++) {
x->val[i] = MAGMA_Z_MAKE( ((double)(2*rand()))/ RAND_MAX - 1., ((double)(2*rand()))/ RAND_MAX - 1. );
}
}
else if ( mem_loc == Magma_DEV ) {
CHECK( magma_zvinit_rand( &x_h, Magma_CPU, num_rows, num_cols, queue ));
CHECK( magma_zmtransfer( x_h, x, Magma_CPU, Magma_DEV, queue ) );
}
cleanup:
magma_zmfree( &x_h, queue );
return info;
}
|