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
|
/*
-- MAGMA (version 2.9.0) --
Univ. of Tennessee, Knoxville
Univ. of California, Berkeley
Univ. of Colorado, Denver
@date January 2025
@generated from sparse/control/magma_zparilu_kernels.cpp, normal z -> s, Wed Jan 22 14:42:32 2025
@author Hartwig Anzt
*/
#include "magmasparse_internal.h"
#ifdef _OPENMP
#include <omp.h>
#endif
#define SWAP(a, b) { val_swap = a; a = b; b = val_swap; }
/***************************************************************************//**
Purpose
-------
This function does one asynchronous ParILU sweep.
Input and output array are identical.
Arguments
---------
@param[in]
A magma_s_matrix
System matrix in COO.
@param[in]
L magma_s_matrix*
Current approximation for the lower triangular factor
The format is sorted CSR.
@param[in]
U magma_s_matrix*
Current approximation for the upper triangular factor
The format is sorted CSC (U^T in CSR).
@param[in]
queue magma_queue_t
Queue to execute in.
@ingroup magmasparse_saux
*******************************************************************************/
extern "C" magma_int_t
magma_sparilu_sweep(
magma_s_matrix A,
magma_s_matrix *L,
magma_s_matrix *U,
magma_queue_t queue )
{
magma_int_t info = 0;
int i, j;
float zero = MAGMA_S_MAKE(0.0, 0.0);
int il, iu, jl, ju;
#pragma omp parallel for
for (int k=0; k < A.nnz; k++) {
i = A.rowidx[k];
j = A.col[k];
float s, sp;
s = A.val[k];
sp = zero;
il = L->row[i];
iu = U->row[j];
while (il < L->row[i+1] && iu < U->row[j+1])
{
sp = zero;
jl = L->col[il];
ju = U->col[iu];
// avoid branching
sp = ( jl == ju ) ? L->val[il] * U->val[iu] : sp;
s = ( jl == ju ) ? s-sp : s;
il = ( jl <= ju ) ? il+1 : il;
iu = ( jl >= ju ) ? iu+1 : iu;
}
// undo the last operation (it must be the last)
s += sp;
if ( i > j ) // modify l entry
L->val[il-1] = s / U->val[U->row[j+1]-1];
else { // modify u entry
U->val[iu-1] = s;
}
}
return info;
}
/***************************************************************************//**
Purpose
-------
This function does one synchronized ParILU sweep. Input and output are
different arrays.
Arguments
---------
@param[in]
A magma_s_matrix
System matrix in COO.
@param[in]
L magma_s_matrix*
Current approximation for the lower triangular factor
The format is sorted CSR.
@param[in]
U magma_s_matrix*
Current approximation for the upper triangular factor
The format is sorted CSC (U^T in CSR).
@param[in]
queue magma_queue_t
Queue to execute in.
@ingroup magmasparse_saux
*******************************************************************************/
extern "C" magma_int_t
magma_sparilu_sweep_sync(
magma_s_matrix A,
magma_s_matrix *L,
magma_s_matrix *U,
magma_queue_t queue )
{
magma_int_t info = 0;
int i, j;
float zero = MAGMA_S_MAKE(0.0, 0.0);
int il, iu, jl, ju;
float *L_new_val = NULL, *U_new_val = NULL, *val_swap = NULL;
CHECK( magma_smalloc_cpu( &L_new_val, L->nnz ));
CHECK( magma_smalloc_cpu( &U_new_val, U->nnz ));
// we need 1 on the main diagonal of L
#pragma omp parallel for
for (int k=0; k < L->num_rows; k++) {
L_new_val[L->row[k+1]-1] = MAGMA_S_ONE;
}
#pragma omp parallel for
for (int k=0; k < A.nnz; k++) {
i = A.rowidx[k];
j = A.col[k];
float s, sp;
s = A.val[k];
sp = zero;
il = L->row[i];
iu = U->row[j];
while (il < L->row[i+1] && iu < U->row[j+1])
{
sp = zero;
jl = L->col[il];
ju = U->col[iu];
// avoid branching
sp = ( jl == ju ) ? L->val[il] * U->val[iu] : sp;
s = ( jl == ju ) ? s-sp : s;
il = ( jl <= ju ) ? il+1 : il;
iu = ( jl >= ju ) ? iu+1 : iu;
}
// undo the last operation (it must be the last)
s += sp;
if ( i > j ) // modify l entry
L_new_val[il-1] = s / U->val[U->row[j+1]-1];
else { // modify u entry
U_new_val[iu-1] = s;
}
}
// swap old and new values
SWAP( L_new_val, L->val );
SWAP( U_new_val, U->val );
cleanup:
magma_free_cpu( L_new_val );
magma_free_cpu( U_new_val );
return info;
}
|