1 //------------------------------------------------------------------------------
2 // GB_bitmap_M_scatter: scatter M into/from the C bitmap
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 #include "GB_bitmap_assign_methods.h"
11 
GB_bitmap_M_scatter(GrB_Matrix C,const GrB_Index * I,const int64_t nI,const int Ikind,const int64_t Icolon[3],const GrB_Index * J,const int64_t nJ,const int Jkind,const int64_t Jcolon[3],const GrB_Matrix M,const bool Mask_struct,const int assign_kind,const int operation,const int64_t * M_ek_slicing,const int M_ntasks,const int M_nthreads,GB_Context Context)12 void GB_bitmap_M_scatter        // scatter M into the C bitmap
13 (
14     // input/output:
15     GrB_Matrix C,
16     // inputs:
17     const GrB_Index *I,         // I index list
18     const int64_t nI,
19     const int Ikind,
20     const int64_t Icolon [3],
21     const GrB_Index *J,         // J index list
22     const int64_t nJ,
23     const int Jkind,
24     const int64_t Jcolon [3],
25     const GrB_Matrix M,         // mask to scatter into the C bitmap
26     const bool Mask_struct,     // true if M is structural, false if valued
27     const int assign_kind,      // row assign, col assign, assign, or subassign
28     const int operation,        // +=2, -=2, or %=2
29     const int64_t *M_ek_slicing,    // size 3*M_ntasks+1
30     const int M_ntasks,
31     const int M_nthreads,
32     GB_Context Context
33 )
34 {
35 
36     //--------------------------------------------------------------------------
37     // check inputs
38     //--------------------------------------------------------------------------
39 
40     ASSERT_MATRIX_OK (M, "M for bitmap scatter", GB0) ;
41     ASSERT (GB_IS_SPARSE (M) || GB_IS_HYPERSPARSE (M)) ;
42     ASSERT (M_ntasks > 0) ;
43     ASSERT (M_nthreads > 0) ;
44     ASSERT (M_ek_slicing != NULL) ;
45 
46     //--------------------------------------------------------------------------
47     // get C and M
48     //--------------------------------------------------------------------------
49 
50     GB_GET_M
51     int8_t *Cb = C->b ;
52     const int64_t cvlen = C->vlen ;
53     int64_t cnvals = 0 ;
54 
55     //--------------------------------------------------------------------------
56     // scatter M into the C bitmap
57     //--------------------------------------------------------------------------
58 
59     switch (operation)
60     {
61 
62         case GB_BITMAP_M_SCATTER_PLUS_2 :       // Cb (i,j) += 2
63 
64             #undef  GB_MASK_WORK
65             #define GB_MASK_WORK(pC) Cb [pC] += 2
66             #include "GB_bitmap_assign_M_template.c"
67             break ;
68 
69         case GB_BITMAP_M_SCATTER_MINUS_2 :      // Cb (i,j) -= 2
70 
71             #undef  GB_MASK_WORK
72             #define GB_MASK_WORK(pC) Cb [pC] -= 2
73             #include "GB_bitmap_assign_M_template.c"
74             break ;
75 
76         case GB_BITMAP_M_SCATTER_MOD_2 :        // Cb (i,j) %= 2
77 
78             #undef  GB_MASK_WORK
79             #define GB_MASK_WORK(pC) Cb [pC] %= 2
80             #include "GB_bitmap_assign_M_template.c"
81             break ;
82 
83         default: ;
84     }
85 }
86 
87