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
|
//------------------------------------------------------------------------------
// GB_emult_02_template: C = A.*B when A is sparse/hyper and B is bitmap/full
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
// C is sparse, with the same sparsity structure as A. No mask is present, or
// M is bitmap/full. A is sparse/hyper, and B is bitmap/full. This method
// also handles the case when the original input A is bitmap/full and B is
// sparse/hyper, by computing B.*A with the operator flipped.
{
//--------------------------------------------------------------------------
// get A, B, and C
//--------------------------------------------------------------------------
const int64_t *restrict Ap = A->p ;
const int64_t *restrict Ah = A->h ;
const int64_t *restrict Ai = A->i ;
const int64_t vlen = A->vlen ;
const int8_t *restrict Bb = B->b ;
const int64_t *restrict kfirst_Aslice = A_ek_slicing ;
const int64_t *restrict klast_Aslice = A_ek_slicing + A_ntasks ;
const int64_t *restrict pstart_Aslice = A_ek_slicing + A_ntasks * 2 ;
const bool A_iso = A->iso ;
const bool B_iso = B->iso ;
#ifdef GB_ISO_EMULT
ASSERT (C->iso) ;
#else
ASSERT (!C->iso) ;
ASSERT (!(A_iso && B_iso)) ; // one of A or B can be iso, but not both
#if GB_FLIPPED
const GB_BTYPE *restrict Ax = (GB_BTYPE *) A->x ;
const GB_ATYPE *restrict Bx = (GB_ATYPE *) B->x ;
#else
const GB_ATYPE *restrict Ax = (GB_ATYPE *) A->x ;
const GB_BTYPE *restrict Bx = (GB_BTYPE *) B->x ;
#endif
GB_CTYPE *restrict Cx = (GB_CTYPE *) C->x ;
#endif
const int64_t *restrict Cp = C->p ;
int64_t *restrict Ci = C->i ;
//--------------------------------------------------------------------------
// C=A.*B or C<#M>=A.*B
//--------------------------------------------------------------------------
if (M == NULL)
{
//----------------------------------------------------------------------
// C = A.*B
//----------------------------------------------------------------------
if (GB_IS_BITMAP (B))
{
//------------------------------------------------------------------
// Method2(a): C=A.*B where A is sparse/hyper and B is bitmap
//------------------------------------------------------------------
int tid ;
#pragma omp parallel for num_threads(A_nthreads) schedule(dynamic,1)
for (tid = 0 ; tid < A_ntasks ; tid++)
{
int64_t kfirst = kfirst_Aslice [tid] ;
int64_t klast = klast_Aslice [tid] ;
for (int64_t k = kfirst ; k <= klast ; k++)
{
int64_t j = GBH (Ah, k) ;
int64_t pB_start = j * vlen ;
int64_t pA, pA_end, pC ;
GB_get_pA_and_pC (&pA, &pA_end, &pC, tid, k, kfirst, klast,
pstart_Aslice, Cp_kfirst, Cp, vlen, Ap, vlen) ;
for ( ; pA < pA_end ; pA++)
{
int64_t i = Ai [pA] ;
int64_t pB = pB_start + i ;
if (!Bb [pB]) continue ;
// C (i,j) = A (i,j) .* B (i,j)
Ci [pC] = i ;
#ifndef GB_ISO_EMULT
GB_GETA (aij, Ax, pA, A_iso) ;
GB_GETB (bij, Bx, pB, B_iso) ;
#if GB_FLIPPED
GB_BINOP (GB_CX (pC), bij, aij, i, j) ;
#else
GB_BINOP (GB_CX (pC), aij, bij, i, j) ;
#endif
#endif
pC++ ;
}
}
}
}
else
{
//------------------------------------------------------------------
// Method2(b): C=A.*B where A is sparse/hyper and B is full
//------------------------------------------------------------------
int tid ;
#pragma omp parallel for num_threads(A_nthreads) schedule(dynamic,1)
for (tid = 0 ; tid < A_ntasks ; tid++)
{
int64_t kfirst = kfirst_Aslice [tid] ;
int64_t klast = klast_Aslice [tid] ;
for (int64_t k = kfirst ; k <= klast ; k++)
{
int64_t j = GBH (Ah, k) ;
int64_t pB_start = j * vlen ;
int64_t pA, pA_end ;
GB_get_pA (&pA, &pA_end, tid, k, kfirst, klast,
pstart_Aslice, Ap, vlen) ;
for ( ; pA < pA_end ; pA++)
{
// C (i,j) = A (i,j) .* B (i,j)
int64_t i = Ai [pA] ;
int64_t pB = pB_start + i ;
// Ci [pA] = i ; already defined
#ifndef GB_ISO_EMULT
GB_GETA (aij, Ax, pA, A_iso) ;
GB_GETB (bij, Bx, pB, B_iso) ;
#if GB_FLIPPED
GB_BINOP (GB_CX (pA), bij, aij, i, j) ;
#else
GB_BINOP (GB_CX (pA), aij, bij, i, j) ;
#endif
#endif
}
}
}
}
}
else
{
//----------------------------------------------------------------------
// Method2(c): C<#M>=A.*B, A is sparse/hyper, M and B are bitmap/full
//----------------------------------------------------------------------
const int8_t *restrict Mb = M->b ;
const GB_void *restrict Mx = (Mask_struct) ? NULL : ((GB_void *) M->x) ;
const size_t msize = M->type->size ;
int tid ;
#pragma omp parallel for num_threads(A_nthreads) schedule(dynamic,1)
for (tid = 0 ; tid < A_ntasks ; tid++)
{
int64_t kfirst = kfirst_Aslice [tid] ;
int64_t klast = klast_Aslice [tid] ;
for (int64_t k = kfirst ; k <= klast ; k++)
{
int64_t j = GBH (Ah, k) ;
int64_t pB_start = j * vlen ;
int64_t pA, pA_end, pC ;
GB_get_pA_and_pC (&pA, &pA_end, &pC, tid, k, kfirst, klast,
pstart_Aslice, Cp_kfirst, Cp, vlen, Ap, vlen) ;
for ( ; pA < pA_end ; pA++)
{
int64_t i = Ai [pA] ;
int64_t pB = pB_start + i ;
if (!GBB (Bb, pB)) continue ;
bool mij = GBB (Mb, pB) && GB_mcast (Mx, pB, msize) ;
mij = mij ^ Mask_comp ;
if (!mij) continue ;
// C (i,j) = A (i,j) .* B (i,j)
Ci [pC] = i ;
#ifndef GB_ISO_EMULT
GB_GETA (aij, Ax, pA, A_iso) ;
GB_GETB (bij, Bx, pB, B_iso) ;
#if GB_FLIPPED
GB_BINOP (GB_CX (pC), bij, aij, i, j) ;
#else
GB_BINOP (GB_CX (pC), aij, bij, i, j) ;
#endif
#endif
pC++ ;
}
}
}
}
}
|