1 //------------------------------------------------------------------------------
2 // GB_assign_zombie1: delete all entries in C(:,j) for GB_assign
3 //------------------------------------------------------------------------------
4 
5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6 // SPDX-License-Identifier: Apache-2.0
7 
8 //------------------------------------------------------------------------------
9 
10 // C(:,j)<!> = anything: GrB_Row_assign or GrB_Col_assign with an empty
11 // complemented mask requires all entries in the C(:,j) vector to be deleted.
12 // C must be sparse or hypersparse.
13 
14 #include "GB_assign.h"
15 #include "GB_assign_zombie.h"
16 
GB_assign_zombie1(GrB_Matrix C,const int64_t j,GB_Context Context)17 void GB_assign_zombie1
18 (
19     GrB_Matrix C,
20     const int64_t j,
21     GB_Context Context
22 )
23 {
24 
25     //--------------------------------------------------------------------------
26     // check inputs
27     //--------------------------------------------------------------------------
28 
29     ASSERT (!GB_IS_FULL (C)) ;
30     ASSERT (!GB_IS_BITMAP (C)) ;
31     ASSERT (GB_ZOMBIES_OK (C)) ;
32     ASSERT (GB_JUMBLED_OK (C)) ;
33     ASSERT (!GB_PENDING (C)) ;
34 
35     //--------------------------------------------------------------------------
36     // get C(:,j)
37     //--------------------------------------------------------------------------
38 
39     int64_t *restrict Ci = C->i ;
40     int64_t pC_start, pC_end, pleft = 0, pright = C->nvec-1 ;
41     GB_lookup (C->h != NULL, C->h, C->p, C->vlen, &pleft, pright, j,
42         &pC_start, &pC_end) ;
43     int64_t cjnz = pC_end - pC_start ;
44     int64_t nzombies = C->nzombies ;
45 
46     //--------------------------------------------------------------------------
47     // determine the number of threads to use
48     //--------------------------------------------------------------------------
49 
50     GB_GET_NTHREADS_MAX (nthreads_max, chunk, Context) ;
51     int nthreads = GB_nthreads (cjnz, chunk, nthreads_max) ;
52 
53     //--------------------------------------------------------------------------
54     // C(:,j) = empty
55     //--------------------------------------------------------------------------
56 
57     int64_t pC ;
58     #pragma omp parallel for num_threads(nthreads) schedule(static) \
59         reduction(+:nzombies)
60     for (pC = pC_start ; pC < pC_end ; pC++)
61     {
62         int64_t i = Ci [pC] ;
63         if (!GB_IS_ZOMBIE (i))
64         {
65             // delete C(i,j) by marking it as a zombie
66             nzombies++ ;
67             Ci [pC] = GB_FLIP (i) ;
68         }
69     }
70 
71     //--------------------------------------------------------------------------
72     // return result
73     //--------------------------------------------------------------------------
74 
75     C->nzombies = nzombies ;
76 }
77 
78