1 //------------------------------------------------------------------------------
2 // GB_bitmap_assign_C_template: iterate over a bitmap matrix C
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 // The #include'ing file defines a GB_CIJ_WORK macro for the body of the loop,
11 // which operates on the entry C(iC,jC) at position Cx [pC] and Cb [pC].  The C
12 // matrix held in bitmap form.  If the mask matrix is also a bitmap matrix or
13 // full matrix, the GB_GET_MIJ macro can compute the effective value of the
14 // mask for the C(iC,jC) entry.
15 
16 // C must be bitmap or full.  If M is accessed, it must also be bitmap or full.
17 
18 #ifndef GB_GET_MIJ
19 #define GB_GET_MIJ(mij,pM) ;
20 #endif
21 
22 {
23     switch (assign_kind)
24     {
25 
26         //----------------------------------------------------------------------
27         // row assignment: C<M'>(iC,:), M is a column vector
28         //----------------------------------------------------------------------
29 
30         case GB_ROW_ASSIGN :
31         {
32             // iterate over all of C(iC,:)
33             const int64_t iC = I [0] ;
34             const int nthreads = GB_nthreads (cvdim, chunk, nthreads_max) ;
35             int tid ;
36             #pragma omp parallel for num_threads(nthreads) schedule(static) \
37                 reduction(+:cnvals)
38             for (tid = 0 ; tid < nthreads ; tid++)
39             {
40                 int64_t jC_start, jC_end, task_cnvals = 0 ;
41                 GB_PARTITION (jC_start, jC_end, cvdim, tid, nthreads) ;
42                 for (int64_t jC = jC_start ; jC < jC_end ; jC++)
43                 {
44                     int64_t pC = iC + jC * cvlen ;
45                     GB_GET_MIJ (mij, jC) ;          // mij = Mask (jC)
46                     GB_CIJ_WORK (pC) ;              // operate on C(iC,jC)
47                 }
48                 cnvals += task_cnvals ;
49             }
50         }
51         break ;
52 
53         //----------------------------------------------------------------------
54         // column assignment: C<M>(:,jC), M is a column vector
55         //----------------------------------------------------------------------
56 
57         case GB_COL_ASSIGN :
58         {
59             // iterate over all of C(:,jC)
60             const int64_t jC = J [0] ;
61             const int64_t pC0 = jC * cvlen ;
62             const int nthreads = GB_nthreads (cvlen, chunk, nthreads_max) ;
63             int tid ;
64             #pragma omp parallel for num_threads(nthreads) schedule(static) \
65                 reduction(+:cnvals)
66             for (tid = 0 ; tid < nthreads ; tid++)
67             {
68                 int64_t iC_start, iC_end, task_cnvals = 0 ;
69                 GB_PARTITION (iC_start, iC_end, cvlen, tid, nthreads) ;
70                 for (int64_t iC = iC_start ; iC < iC_end ; iC++)
71                 {
72                     int64_t pC = iC + pC0 ;
73                     GB_GET_MIJ (mij, iC) ;          // mij = Mask (iC)
74                     GB_CIJ_WORK (pC) ;              // operate on C(iC,jC)
75                 }
76                 cnvals += task_cnvals ;
77             }
78         }
79         break ;
80 
81         //----------------------------------------------------------------------
82         // GrB_assign: C<M>(I,J), M is a matrix the same size as C
83         //----------------------------------------------------------------------
84 
85         #ifndef GB_NO_ASSIGN_CASE
86         case GB_ASSIGN :
87         {
88             // iterate over all of C(:,:).
89             #include "GB_bitmap_assign_C_whole_template.c"
90         }
91         break ;
92         #endif
93 
94         //----------------------------------------------------------------------
95         // GxB_subassign: C(I,J)<M>, M is a matrix the same size as C(I,J)
96         //----------------------------------------------------------------------
97 
98         #ifndef GB_NO_SUBASSIGN_CASE
99         case GB_SUBASSIGN :
100         {
101             // iterate over all of C(I,J)
102             #undef  GB_IXJ_WORK
103             #define GB_IXJ_WORK(pC,pA)                                      \
104             {                                                               \
105                 GB_GET_MIJ (mij, pA) ;          /* mij = Mask (pA)      */  \
106                 GB_CIJ_WORK (pC) ;              /* operate on C(iC,jC)  */  \
107             }
108             #include "GB_bitmap_assign_IxJ_template.c"
109         }
110         break ;
111         #endif
112 
113         default: ;
114     }
115 }
116 
117 #undef GB_NO_ASSIGN_CASE
118 #undef GB_NO_SUBASSIGN_CASE
119