1 //------------------------------------------------------------------------------
2 // GB_convert_sparse_to_bitmap_template: convert A from sparse to 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 {
11     ASSERT (GB_IS_SPARSE (A) || GB_IS_HYPERSPARSE (A)) ;
12 
13     const int64_t  *restrict Ap = A->p ;
14     const int64_t  *restrict Ah = A->h ;
15     const int64_t  *restrict Ai = A->i ;
16     const GB_ATYPE *restrict Ax = (GB_ATYPE *) A->x ;
17     const int64_t avlen = A->vlen ;
18     const int64_t nzombies = A->nzombies ;
19 
20     const int64_t *restrict kfirst_Aslice = A_ek_slicing ;
21     const int64_t *restrict klast_Aslice  = A_ek_slicing + A_ntasks ;
22     const int64_t *restrict pstart_Aslice = A_ek_slicing + A_ntasks * 2 ;
23 
24     int tid ;
25     #pragma omp parallel for num_threads(A_nthreads) schedule(dynamic,1)
26     for (tid = 0 ; tid < A_ntasks ; tid++)
27     {
28         int64_t kfirst = kfirst_Aslice [tid] ;
29         int64_t klast  = klast_Aslice  [tid] ;
30         for (int64_t k = kfirst ; k <= klast ; k++)
31         {
32 
33             //------------------------------------------------------------------
34             // find the part of A(:,j) to be operated on by this task
35             //------------------------------------------------------------------
36 
37             int64_t j = GBH (Ah, k) ;
38             int64_t pA_start, pA_end ;
39             GB_get_pA (&pA_start, &pA_end, tid, k,
40                 kfirst, klast, pstart_Aslice, Ap, avlen) ;
41 
42             // the start of A(:,j) in the new bitmap
43             int64_t pA_new = j * avlen ;
44 
45             //------------------------------------------------------------------
46             // convert A(:,j) from sparse to bitmap
47             //------------------------------------------------------------------
48 
49             if (nzombies == 0)
50             {
51                 for (int64_t p = pA_start ; p < pA_end ; p++)
52                 {
53                     // A(i,j) has index i, value Ax [p]
54                     int64_t i = Ai [p] ;
55                     int64_t pnew = i + pA_new ;
56                     // move A(i,j) to its new place in the bitmap
57                     // Ax_new [pnew] = Ax [p]
58                     GB_COPY_A_TO_C (Ax_new, pnew, Ax, p) ;
59                     Ab [pnew] = 1 ;
60                 }
61             }
62             else
63             {
64                 for (int64_t p = pA_start ; p < pA_end ; p++)
65                 {
66                     // A(i,j) has index i, value Ax [p]
67                     int64_t i = Ai [p] ;
68                     if (!GB_IS_ZOMBIE (i))
69                     {
70                         int64_t pnew = i + pA_new ;
71                         // move A(i,j) to its new place in the bitmap
72                         // Ax_new [pnew] = Ax [p]
73                         GB_COPY_A_TO_C (Ax_new, pnew, Ax, p) ;
74                         Ab [pnew] = 1 ;
75                     }
76                 }
77             }
78         }
79     }
80 }
81 
82