1 //------------------------------------------------------------------------------ 2 // GB_dense_ewise3_noaccum_template: C = A+B where all 3 matrices are dense 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 #include "GB_unused.h" 11 12 { 13 14 //-------------------------------------------------------------------------- 15 // get A, B, and C 16 //-------------------------------------------------------------------------- 17 18 // any matrix may be aliased to any other (C==A, C==B, and/or A==B) 19 GB_ATYPE *Ax = (GB_ATYPE *) A->x ; 20 GB_BTYPE *Bx = (GB_BTYPE *) B->x ; 21 GB_CTYPE *Cx = (GB_CTYPE *) C->x ; 22 const int64_t cnz = GB_NNZ (C) ; 23 ASSERT (GB_is_dense (A)) ; 24 ASSERT (GB_is_dense (B)) ; 25 ASSERT (GB_is_dense (C)) ; 26 int64_t p ; 27 28 //-------------------------------------------------------------------------- 29 // C = A+B where all 3 matrices are dense 30 //-------------------------------------------------------------------------- 31 32 #if GB_CTYPE_IS_BTYPE 33 34 if (C == B) 35 { 36 37 //---------------------------------------------------------------------- 38 // C = A+C where A and C are dense 39 //---------------------------------------------------------------------- 40 41 // C and B cannot be aliased if their types differ 42 #pragma omp parallel for num_threads(nthreads) schedule(static) 43 for (p = 0 ; p < cnz ; p++) 44 { 45 GB_GETA (aij, Ax, p) ; // aij = Ax [p] 46 // Cx [p] = aij + Cx [p] 47 GB_BINOP (GB_CX (p), aij, GB_CX (p), 0, 0) ; 48 } 49 50 } 51 else 52 #endif 53 54 #if GB_CTYPE_IS_ATYPE 55 56 if (C == A) 57 { 58 59 //---------------------------------------------------------------------- 60 // C = C+B where B and C are dense 61 //---------------------------------------------------------------------- 62 63 #pragma omp parallel for num_threads(nthreads) schedule(static) 64 for (p = 0 ; p < cnz ; p++) 65 { 66 GB_GETB (bij, Bx, p) ; // bij = Bx [p] 67 GB_BINOP (GB_CX (p), GB_CX (p), bij, 0, 0) ; // Cx [p] += bij 68 } 69 70 } 71 else 72 #endif 73 74 { 75 76 //---------------------------------------------------------------------- 77 // C = A+B where all 3 matrices are dense 78 //---------------------------------------------------------------------- 79 80 // note that A and B may still be aliased to each other 81 #pragma omp parallel for num_threads(nthreads) schedule(static) 82 for (p = 0 ; p < cnz ; p++) 83 { 84 GB_GETA (aij, Ax, p) ; // aij = Ax [p] 85 GB_GETB (bij, Bx, p) ; // bij = Bx [p] 86 GB_BINOP (GB_CX (p), aij, bij, 0, 0) ; // Cx [p] = aij + bij 87 } 88 } 89 } 90 91