File: GB_emult_08_phase1.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 (121 lines) | stat: -rw-r--r-- 4,583 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//------------------------------------------------------------------------------
// GB_emult_08_phase1: # entries in C=A.*B or C<M or !M>=A.*B (C sparse/hyper)
//------------------------------------------------------------------------------

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

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

// GB_emult_08_phase1 counts the number of entries in each vector of C, for
// C=A.*B, C<M>=A.*B, or C<!M>=A.*B and then does a cumulative sum to find Cp.
// GB_emult_08_phase1 is preceded by GB_emult_08_phase0, which finds the
// non-empty vectors of C.  If the mask M is sparse, it is not complemented;
// only a bitmap or full M is complemented.

// C is sparse or hypersparse, as determined by GB_add_sparsity.  
// M, A, and B can have any sparsity structure, but only a specific set of
// cases will be used (see GB_emult_sparsity for details).

// Cp is either freed by GB_emult_08_phase2, or transplanted into C.

#include "emult/GB_emult.h"

GrB_Info GB_emult_08_phase1                 // count nnz in each C(:,j)
(
    // computed by phase1:
    void **Cp_handle,               // output of size Cnvec+1
    size_t *Cp_size_handle,
    int64_t *Cnvec_nonempty,        // # of non-empty vectors in C
    // tasks from phase1a:
    GB_task_struct *restrict TaskList,   // array of structs
    const int C_ntasks,             // # of tasks
    const int C_nthreads,           // # of threads to use
    // analysis from phase0:
    const int64_t Cnvec,
    const void *Ch,
    const int64_t *restrict C_to_M,
    const int64_t *restrict C_to_A,
    const int64_t *restrict C_to_B,
    const bool Cp_is_32,            // if true, Cp is 32-bit; else 64-bit
    const bool Cj_is_32,            // if true, Ch is 32-bit; else 64-bit
    // original input:
    const GrB_Matrix M,             // optional mask, may be NULL
    const bool Mask_struct,         // if true, use the only structure of M
    const bool Mask_comp,           // if true, use !M
    const GrB_Matrix A,
    const GrB_Matrix B,
    GB_Werk Werk
)
{

    //--------------------------------------------------------------------------
    // check inputs
    //--------------------------------------------------------------------------

    ASSERT (Cp_handle != NULL) ;
    ASSERT (Cp_size_handle != NULL) ;
    ASSERT (Cnvec_nonempty != NULL) ;

    ASSERT_MATRIX_OK_OR_NULL (M, "M for emult phase1", GB0) ;
    ASSERT (!GB_ZOMBIES (M)) ;
    ASSERT (!GB_JUMBLED (M)) ;
    ASSERT (!GB_PENDING (M)) ;

    ASSERT_MATRIX_OK (A, "A for emult phase1", GB0) ;
    ASSERT (!GB_ZOMBIES (A)) ;
    ASSERT (!GB_JUMBLED (A)) ;
    ASSERT (!GB_PENDING (A)) ;

    ASSERT_MATRIX_OK (B, "B for emult phase1", GB0) ;
    ASSERT (!GB_ZOMBIES (B)) ;
    ASSERT (!GB_JUMBLED (B)) ;
    ASSERT (!GB_PENDING (B)) ;

    ASSERT (A->vdim == B->vdim) ;

    if (M == NULL)
    { 
        ASSERT (GB_IS_SPARSE (A) || GB_IS_HYPERSPARSE (A)) ;
        ASSERT (GB_IS_SPARSE (B) || GB_IS_HYPERSPARSE (B)) ;
    }

    //--------------------------------------------------------------------------
    // allocate the result
    //--------------------------------------------------------------------------

    (*Cp_handle) = NULL ;
    GB_MDECL (Cp, , u) ; size_t Cp_size = 0 ;
    size_t cpsize = (Cp_is_32) ? sizeof (uint32_t) : sizeof (uint64_t) ;
    Cp = GB_CALLOC_MEMORY (GB_IMAX (2, Cnvec+1), cpsize, &Cp_size) ;
    if (Cp == NULL)
    { 
        // out of memory
        return (GrB_OUT_OF_MEMORY) ;
    }
    GB_IPTR (Cp, Cp_is_32) ;
    GB_IDECL (Ch, const, u) ; GB_IPTR (Ch, Cj_is_32) ;

    //--------------------------------------------------------------------------
    // count the entries in each vector of C
    //--------------------------------------------------------------------------

    #define GB_EMULT_08_PHASE 1
    #include "emult/template/GB_emult_08_template.c"

    //--------------------------------------------------------------------------
    // cumulative sum of Cp and fine tasks in TaskList
    //--------------------------------------------------------------------------

    GB_task_cumsum (Cp, Cp_is_32, Cnvec, Cnvec_nonempty, TaskList,
        C_ntasks, C_nthreads, Werk) ;

    //--------------------------------------------------------------------------
    // return the result
    //--------------------------------------------------------------------------

    (*Cp_handle) = Cp ;
    (*Cp_size_handle) = Cp_size ;
    return (GrB_SUCCESS) ;
}