1 //------------------------------------------------------------------------------
2 // GB_ek_slice_search: find the first and last vectors in a slice
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 #ifndef GB_EK_SLICE_SEARCH_H
11 #define GB_EK_SLICE_SEARCH_H
12 #include "GB_search_for_vector_template.c"
13 
14 //------------------------------------------------------------------------------
15 // GB_ek_slice_search: find the first and last vectors in a slice
16 //------------------------------------------------------------------------------
17 
GB_ek_slice_search(int taskid,int ntasks,const int64_t * restrict pstart_slice,const int64_t * restrict Ap,int64_t anvec,int64_t avlen,int64_t * restrict kfirst_slice,int64_t * restrict klast_slice)18 static inline void GB_ek_slice_search
19 (
20     // input:
21     int taskid,
22     int ntasks,
23     const int64_t *restrict pstart_slice,    // size ntasks+1
24     const int64_t *restrict Ap,              // size anvec
25     int64_t anvec,                              // # of vectors in A
26     int64_t avlen,                              // vector length of A
27     // output:
28     int64_t *restrict kfirst_slice,          // size ntasks
29     int64_t *restrict klast_slice            // size ntasks
30 )
31 {
32     int64_t pfirst = pstart_slice [taskid] ;
33     int64_t plast  = pstart_slice [taskid+1] - 1 ;
34     // ASSERT (pfirst <= plast) ;
35 
36     // find the first vector of the slice for task taskid: the
37     // vector that owns the entry Ai [pfirst] and Ax [pfirst].
38     int64_t kfirst ;
39     if (taskid == 0)
40     {
41         kfirst = 0 ;
42     }
43     else
44     {
45         kfirst = GB_search_for_vector (pfirst, Ap, 0, anvec, avlen) ;
46     }
47 
48     // find the last vector of the slice for task taskid: the
49     // vector that owns the entry Ai [plast] and Ax [plast].
50     int64_t klast ;
51     if (taskid == ntasks-1)
52     {
53         klast = anvec - 1 ;
54     }
55     else if (pfirst > plast)
56     {
57         // this task does no work
58         klast = kfirst ;
59     }
60     else
61     {
62         klast = GB_search_for_vector (plast, Ap, kfirst, anvec, avlen) ;
63     }
64     kfirst_slice [taskid] = kfirst ;
65     klast_slice  [taskid] = klast ;
66     // ASSERT (0 <= kfirst && kfirst <= klast && klast < anvec) ;
67 }
68 
69 #endif
70 
71