126cec326SBarry Smith /* 226cec326SBarry Smith used by SEQAIJ, BAIJ and SBAIJ to reduce code duplication 326cec326SBarry Smith 426cec326SBarry Smith define TYPE to AIJ BAIJ or SBAIJ 526cec326SBarry Smith TYPE_BS_ON for BAIJ and SBAIJ and bs > 1 626cec326SBarry Smith TYPE_SBAIJ for SBAIJ 726cec326SBarry Smith 826cec326SBarry Smith */ 926cec326SBarry Smith static PetscErrorCode PetscConcat(MatSetValues_Seq_Hash, TYPE_BS)(Mat A, PetscInt m, const PetscInt *rows, PetscInt n, const PetscInt *cols, const PetscScalar *values, InsertMode addv) 1026cec326SBarry Smith { 1126cec326SBarry Smith PetscConcat(Mat_Seq, TYPE) *a = (PetscConcat(Mat_Seq, TYPE) *)A->data; 1226cec326SBarry Smith #if defined(TYPE_BS_ON) 13*9680b7ceSStefano Zampini const PetscInt bs = A->rmap->bs; 1426cec326SBarry Smith #endif 15*9680b7ceSStefano Zampini const PetscBool ignorezeroentries = a->ignorezeroentries; 1626cec326SBarry Smith 1726cec326SBarry Smith PetscFunctionBegin; 1826cec326SBarry Smith for (PetscInt r = 0; r < m; ++r) { 1926cec326SBarry Smith PetscHashIJKey key; 2026cec326SBarry Smith PetscBool missing; 2126cec326SBarry Smith PetscScalar value; 2226cec326SBarry Smith #if defined(TYPE_BS_ON) 2326cec326SBarry Smith PetscHashIJKey bkey; 2426cec326SBarry Smith #endif 2526cec326SBarry Smith 2626cec326SBarry Smith key.i = rows[r]; 2726cec326SBarry Smith #if defined(TYPE_BS_ON) 2826cec326SBarry Smith bkey.i = key.i / bs; 2926cec326SBarry Smith #endif 3026cec326SBarry Smith if (key.i < 0) continue; 3126cec326SBarry Smith for (PetscInt c = 0; c < n; ++c) { 3226cec326SBarry Smith key.j = cols[c]; 3326cec326SBarry Smith #if defined(TYPE_BS_ON) 3426cec326SBarry Smith bkey.j = key.j / bs; 3526cec326SBarry Smith #if defined(TYPE_SBAIJ) 3626cec326SBarry Smith if (bkey.j < bkey.i) continue; 3726cec326SBarry Smith #else 3826cec326SBarry Smith if (key.j < 0) continue; 3926cec326SBarry Smith #endif 4026cec326SBarry Smith #else 4126cec326SBarry Smith #if defined(TYPE_SBAIJ) 4226cec326SBarry Smith if (key.j < key.i) continue; 4326cec326SBarry Smith #else 4426cec326SBarry Smith if (key.j < 0) continue; 4526cec326SBarry Smith #endif 4626cec326SBarry Smith #endif 47f4f49eeaSPierre Jolivet value = values ? (a->roworiented ? values[r * n + c] : values[r + m * c]) : 0; 48*9680b7ceSStefano Zampini if (ignorezeroentries && value == 0.0 && key.i != key.j) continue; 4926cec326SBarry Smith switch (addv) { 5026cec326SBarry Smith case INSERT_VALUES: 5126cec326SBarry Smith PetscCall(PetscHMapIJVQuerySet(a->ht, key, value, &missing)); 5226cec326SBarry Smith break; 5326cec326SBarry Smith case ADD_VALUES: 5426cec326SBarry Smith PetscCall(PetscHMapIJVQueryAdd(a->ht, key, value, &missing)); 5526cec326SBarry Smith break; 5626cec326SBarry Smith default: 5726cec326SBarry Smith SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "InsertMode not supported"); 5826cec326SBarry Smith } 5926cec326SBarry Smith if (missing) ++a->dnz[key.i]; 6026cec326SBarry Smith #if defined(TYPE_BS_ON) 6126cec326SBarry Smith PetscCall(PetscHSetIJQueryAdd(a->bht, bkey, &missing)); 6226cec326SBarry Smith if (missing) ++a->bdnz[bkey.i]; 6326cec326SBarry Smith #endif 6426cec326SBarry Smith } 6526cec326SBarry Smith } 6626cec326SBarry Smith PetscFunctionReturn(PETSC_SUCCESS); 6726cec326SBarry Smith } 68