1 //------------------------------------------------------------------------------
2 // GB_bitmap_assign_A_whole_template: traverse A for bitmap assignment into 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 // This template traverses over all the entries of the matrix A and operates on
11 // the corresponding entry in C(i,j), using the GB_AIJ_WORK macro.  A can be
12 // hypersparse or sparse, not bitmap or full.  It is not a scalar.
13 
14 {
15 
16     //--------------------------------------------------------------------------
17     // matrix assignment: slice the entries of A for each task
18     //--------------------------------------------------------------------------
19 
20     GB_WERK_DECLARE (A_ek_slicing, int64_t) ;
21     const int64_t avlen = A->vlen ;
22     int A_ntasks, A_nthreads ;
23     GB_SLICE_MATRIX (A, 8, chunk) ;
24 
25     //--------------------------------------------------------------------------
26     // traverse of the entries of the matrix A
27     //--------------------------------------------------------------------------
28 
29     int tid ;
30     #pragma omp parallel for num_threads(A_nthreads) schedule(dynamic,1) \
31         reduction(+:cnvals)
32     for (tid = 0 ; tid < A_ntasks ; tid++)
33     {
34 
35         // if kfirst > klast then task tid does no work at all
36         int64_t kfirst = kfirst_Aslice [tid] ;
37         int64_t klast  = klast_Aslice  [tid] ;
38         int64_t task_cnvals = 0 ;
39 
40         //----------------------------------------------------------------------
41         // traverse over A (:,kfirst:klast)
42         //----------------------------------------------------------------------
43 
44         for (int64_t k = kfirst ; k <= klast ; k++)
45         {
46 
47             //------------------------------------------------------------------
48             // find the part of A(:,k) for this task
49             //------------------------------------------------------------------
50 
51             int64_t j = GBH (Ah, k) ;
52             int64_t pA_start, pA_end ;
53             GB_get_pA (&pA_start, &pA_end, tid, k, kfirst,
54                 klast, pstart_Aslice, Ap, avlen) ;
55 
56             //------------------------------------------------------------------
57             // traverse over A(:,j), the kth vector of A
58             //------------------------------------------------------------------
59 
60             int64_t pC0 = j * cvlen ;      // first entry in C(:,j)
61 
62             for (int64_t pA = pA_start ; pA < pA_end ; pA++)
63             {
64                 int64_t i = Ai [pA] ;
65                 int64_t pC = i + pC0 ;
66                 // operate on C(i,j) at pC, and A(i,j) at pA.  The mask
67                 // can be accessed at pC if M is bitmap or full.  A has any
68                 // sparsity format so only A(i,j) can be accessed at pA.
69                 GB_AIJ_WORK (pC, pA) ;
70             }
71         }
72         cnvals += task_cnvals ;
73     }
74 
75     //--------------------------------------------------------------------------
76     // free workspace
77     //--------------------------------------------------------------------------
78 
79     GB_WERK_POP (A_ek_slicing, int64_t) ;
80 }
81 
82