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
|
//------------------------------------------------------------------------------
// GB_dense_subassign_05d: C(:,:)<M> = scalar where C is as-if-full
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
// Method 05d: C(:,:)<M> = scalar ; no S, C is dense
// M: present
// Mask_comp: false
// C_replace: false
// accum: NULL
// A: scalar
// S: none
// C can have any sparsity structure, but it must be entirely dense with
// all entries present.
#include "GB_subassign_methods.h"
#include "GB_dense.h"
#include "GB_unused.h"
#ifndef GBCUDA_DEV
#include "GB_type__include.h"
#endif
#undef GB_FREE_WORKSPACE
#define GB_FREE_WORKSPACE \
{ \
GB_WERK_POP (M_ek_slicing, int64_t) ; \
}
#undef GB_FREE_ALL
#define GB_FREE_ALL GB_FREE_WORKSPACE
GrB_Info GB_dense_subassign_05d
(
GrB_Matrix C,
// input:
const GrB_Matrix M,
const bool Mask_struct,
const void *scalar,
const GrB_Type atype,
GB_Context Context
)
{
//--------------------------------------------------------------------------
// check inputs
//--------------------------------------------------------------------------
ASSERT (!GB_aliased (C, M)) ; // NO ALIAS of C==M
//--------------------------------------------------------------------------
// get inputs
//--------------------------------------------------------------------------
GrB_Info info ;
GB_WERK_DECLARE (M_ek_slicing, int64_t) ;
ASSERT_MATRIX_OK (C, "C for subassign method_05d", GB0) ;
ASSERT (!GB_ZOMBIES (C)) ;
ASSERT (!GB_JUMBLED (C)) ;
ASSERT (!GB_PENDING (C)) ;
ASSERT (GB_as_if_full (C)) ;
ASSERT_MATRIX_OK (M, "M for subassign method_05d", GB0) ;
ASSERT (!GB_ZOMBIES (M)) ;
ASSERT (GB_JUMBLED_OK (M)) ;
ASSERT (!GB_PENDING (M)) ;
GB_ENSURE_FULL (C) ; // convert C to full, if sparsity control allows it
if (C->iso)
{
// work has already been done by GB_assign_prep
return (GrB_SUCCESS) ;
}
const GB_Type_code ccode = C->type->code ;
const size_t csize = C->type->size ;
GB_GET_SCALAR ;
//--------------------------------------------------------------------------
// Method 05d: C(:,:)<M> = scalar ; no S; C is dense
//--------------------------------------------------------------------------
// Time: Optimal: the method must iterate over all entries in M,
// and the time is O(nnz(M)).
//--------------------------------------------------------------------------
// Parallel: slice M into equal-sized chunks
//--------------------------------------------------------------------------
GB_GET_NTHREADS_MAX (nthreads_max, chunk, Context) ;
//--------------------------------------------------------------------------
// slice the entries for each task
//--------------------------------------------------------------------------
int M_ntasks, M_nthreads ;
GB_SLICE_MATRIX (M, 8, chunk) ;
//--------------------------------------------------------------------------
// C<M> = x for built-in types
//--------------------------------------------------------------------------
bool done = false ;
#ifndef GBCUDA_DEV
//----------------------------------------------------------------------
// define the worker for the switch factory
//----------------------------------------------------------------------
#define GB_Cdense_05d(cname) GB (_Cdense_05d_ ## cname)
#define GB_WORKER(cname) \
{ \
info = GB_Cdense_05d(cname) (C, M, Mask_struct, cwork, \
M_ek_slicing, M_ntasks, M_nthreads) ; \
done = (info != GrB_NO_VALUE) ; \
} \
break ;
//----------------------------------------------------------------------
// launch the switch factory
//----------------------------------------------------------------------
// C<M> = x
switch (ccode)
{
case GB_BOOL_code : GB_WORKER (_bool )
case GB_INT8_code : GB_WORKER (_int8 )
case GB_INT16_code : GB_WORKER (_int16 )
case GB_INT32_code : GB_WORKER (_int32 )
case GB_INT64_code : GB_WORKER (_int64 )
case GB_UINT8_code : GB_WORKER (_uint8 )
case GB_UINT16_code : GB_WORKER (_uint16)
case GB_UINT32_code : GB_WORKER (_uint32)
case GB_UINT64_code : GB_WORKER (_uint64)
case GB_FP32_code : GB_WORKER (_fp32 )
case GB_FP64_code : GB_WORKER (_fp64 )
case GB_FC32_code : GB_WORKER (_fc32 )
case GB_FC64_code : GB_WORKER (_fc64 )
default: ;
}
#endif
//--------------------------------------------------------------------------
// C<M> = x for user-defined types
//--------------------------------------------------------------------------
if (!done)
{
//----------------------------------------------------------------------
// get operators, functions, workspace, contents of A and C
//----------------------------------------------------------------------
GB_BURBLE_MATRIX (M, "(generic C(:,:)<M>=x assign) ") ;
const size_t csize = C->type->size ;
// Cx [p] = scalar
#define GB_COPY_SCALAR_TO_C(p,x) \
memcpy (Cx + ((p)*csize), x, csize)
#define GB_CTYPE GB_void
// no vectorization
#define GB_PRAGMA_SIMD_VECTORIZE ;
#include "GB_dense_subassign_05d_template.c"
}
//--------------------------------------------------------------------------
// free workspace and return result
//--------------------------------------------------------------------------
GB_FREE_WORKSPACE ;
ASSERT_MATRIX_OK (C, "C output for subassign method_05d", GB0) ;
return (GrB_SUCCESS) ;
}
|