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
|
//------------------------------------------------------------------------------
// GB_assign_zombie3: delete entries in C(:,j) for C_replace_phase
//------------------------------------------------------------------------------
// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2022, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
//------------------------------------------------------------------------------
// For GrB_Row_assign or GrB_Col_assign, C(I,j)<#M,repl>=any must delete all
// entries C(i,j) outside of C(I,j), if the mask M(i,0) (or its complement) is
// zero. This step is not done for GxB_*_subassign, since that method does not
// modify anything outside IxJ.
// GB_assign_zombie3 and GB_assign_zombie4 are transposes of each other.
// C must be sparse or hypersparse.
// M can have any sparsity structure: hypersparse, sparse, bitmap, or full
// C->iso is not affected.
#include "GB_assign.h"
#include "GB_assign_zombie.h"
#include "GB_subassign_methods.h"
void GB_assign_zombie3
(
GrB_Matrix C, // the matrix C, or a copy
const GrB_Matrix M,
const bool Mask_comp,
const bool Mask_struct,
const int64_t j, // vector index with entries to delete
const GrB_Index *I,
const int64_t nI,
const int Ikind,
const int64_t Icolon [3],
GB_Context Context
)
{
//--------------------------------------------------------------------------
// check inputs
//--------------------------------------------------------------------------
ASSERT (!GB_IS_FULL (C)) ;
ASSERT (!GB_IS_BITMAP (C)) ;
ASSERT (GB_ZOMBIES_OK (C)) ;
ASSERT (GB_JUMBLED_OK (C)) ;
ASSERT (!GB_PENDING (C)) ;
ASSERT (!GB_ZOMBIES (M)) ;
ASSERT (!GB_JUMBLED (M)) ; // binary search on M
ASSERT (!GB_PENDING (M)) ;
ASSERT (!GB_aliased (C, M)) ; // NO ALIAS of C==M
//--------------------------------------------------------------------------
// get C (:,j)
//--------------------------------------------------------------------------
const int64_t *restrict Cp = C->p ;
int64_t *restrict Ci = C->i ;
int64_t pC_start, pC_end ;
if (C->h != NULL)
{
// C is hypersparse
GB_hyper_hash_lookup (Cp, C->Y->p, C->Y->i, C->Y->x, C->Y->vdim-1,
j, &pC_start, &pC_end) ;
}
else
{
// C is sparse
pC_start = Cp [j] ;
pC_end = Cp [j+1] ;
}
int64_t nzombies = C->nzombies ;
const int64_t zjnz = pC_end - pC_start ;
//--------------------------------------------------------------------------
// get M(:,0)
//--------------------------------------------------------------------------
const int64_t *restrict Mp = M->p ;
const int8_t *restrict Mb = M->b ;
const int64_t *restrict Mi = M->i ;
const GB_void *restrict Mx = (GB_void *) (Mask_struct ? NULL : (M->x)) ;
const size_t msize = M->type->size ;
const int64_t Mvlen = M->vlen ;
int64_t pM_start = 0 ; // Mp [0]
int64_t pM_end = GBP (Mp, 1, Mvlen) ;
const bool M_is_bitmap = GB_IS_BITMAP (M) ;
const bool mjdense = (pM_end - pM_start) == Mvlen ;
//--------------------------------------------------------------------------
// determine the number of threads to use
//--------------------------------------------------------------------------
GB_GET_NTHREADS_MAX (nthreads_max, chunk, Context) ;
int nthreads = GB_nthreads (zjnz, chunk, nthreads_max) ;
int ntasks = (nthreads == 1) ? 1 : (64 * nthreads) ;
//--------------------------------------------------------------------------
// delete entries from C(:,j) that are outside I, if the mask M allows it
//--------------------------------------------------------------------------
int taskid ;
#pragma omp parallel for num_threads(nthreads) schedule(dynamic,1) \
reduction(+:nzombies)
for (taskid = 0 ; taskid < ntasks ; taskid++)
{
int64_t p1, p2 ;
GB_PARTITION (p1, p2, zjnz, taskid, ntasks) ;
for (int64_t pC = pC_start + p1 ; pC < pC_start + p2 ; pC++)
{
//------------------------------------------------------------------
// get C(i,j)
//------------------------------------------------------------------
int64_t i = Ci [pC] ;
if (!GB_IS_ZOMBIE (i))
{
//--------------------------------------------------------------
// C(i,j) is outside C(I,j) if i is not in the list I
//--------------------------------------------------------------
bool i_outside = !GB_ij_is_in_list (I, nI, i, Ikind, Icolon) ;
if (i_outside)
{
//----------------------------------------------------------
// C(i,j) is a live entry not in the C(I,J) submatrix
//----------------------------------------------------------
// Check the mask M to see if it should be deleted.
GB_MIJ_BINARY_SEARCH_OR_DENSE_LOOKUP (i) ;
if (Mask_comp)
{
// negate the mask if Mask_comp is true
mij = !mij ;
}
if (!mij)
{
// delete C(i,j) by marking it as a zombie
nzombies++ ;
Ci [pC] = GB_FLIP (i) ;
}
}
}
}
}
//--------------------------------------------------------------------------
// return result
//--------------------------------------------------------------------------
C->nzombies = nzombies ;
}
|