File: GB_ek_slice_search_template.c

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (67 lines) | stat: -rw-r--r-- 2,140 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//------------------------------------------------------------------------------
// GB_ek_slice_search: find the first and last vectors in a slice
//------------------------------------------------------------------------------

// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2025, All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

//------------------------------------------------------------------------------

// In this templatized method, the _TYPE suffix becomes either _32 or _64.

//------------------------------------------------------------------------------
// GB_ek_slice_search_TYPE
//------------------------------------------------------------------------------

static inline void GB_ek_slice_search_TYPE
(
    // input:
    int taskid,
    int ntasks,
    const int64_t *restrict pstart_slice,   // size ntasks+1
    const void *Ap,                         // size anvec, 32 or 64 bit
    int64_t anvec,                          // # of vectors in A
    int64_t avlen,                          // vector length of A
    // output:
    int64_t *restrict kfirst_slice,         // size ntasks
    int64_t *restrict klast_slice           // size ntasks
)
{
    int64_t pfirst = pstart_slice [taskid] ;
    int64_t plast  = pstart_slice [taskid+1] - 1 ;

    // find the first vector of the slice for task taskid: the
    // vector that owns the entry Ai [pfirst] and Ax [pfirst].
    int64_t kfirst ;
    if (taskid == 0)
    { 
        kfirst = 0 ;
    }
    else
    { 
        kfirst = GB_search_for_vector_TYPE (Ap, pfirst, 0, anvec, avlen) ;
    }

    // find the last vector of the slice for task taskid: the
    // vector that owns the entry Ai [plast] and Ax [plast].
    int64_t klast ;
    if (taskid == ntasks-1)
    { 
        klast = anvec - 1 ;
    }
    else if (pfirst > plast)
    { 
        // this task does no work
        klast = kfirst ;
    }
    else
    { 
        klast = GB_search_for_vector_TYPE (Ap, plast, kfirst, anvec, avlen) ;
    }
    kfirst_slice [taskid] = kfirst ;
    klast_slice  [taskid] = klast ;
}

#undef GB_search_for_vector_TYPE
#undef GB_ek_slice_search_TYPE