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) 1326cec326SBarry Smith PetscInt bs; 1426cec326SBarry Smith #endif 1526cec326SBarry Smith 1626cec326SBarry Smith PetscFunctionBegin; 1726cec326SBarry Smith #if defined(TYPE_BS_ON) 1826cec326SBarry Smith PetscCall(MatGetBlockSize(A, &bs)); 1926cec326SBarry Smith #endif 2026cec326SBarry Smith for (PetscInt r = 0; r < m; ++r) { 2126cec326SBarry Smith PetscHashIJKey key; 2226cec326SBarry Smith PetscBool missing; 2326cec326SBarry Smith PetscScalar value; 2426cec326SBarry Smith #if defined(TYPE_BS_ON) 2526cec326SBarry Smith PetscHashIJKey bkey; 2626cec326SBarry Smith #endif 2726cec326SBarry Smith 2826cec326SBarry Smith key.i = rows[r]; 2926cec326SBarry Smith #if defined(TYPE_BS_ON) 3026cec326SBarry Smith bkey.i = key.i / bs; 3126cec326SBarry Smith #endif 3226cec326SBarry Smith if (key.i < 0) continue; 3326cec326SBarry Smith for (PetscInt c = 0; c < n; ++c) { 3426cec326SBarry Smith key.j = cols[c]; 3526cec326SBarry Smith #if defined(TYPE_BS_ON) 3626cec326SBarry Smith bkey.j = key.j / bs; 3726cec326SBarry Smith #if defined(TYPE_SBAIJ) 3826cec326SBarry Smith if (bkey.j < bkey.i) continue; 3926cec326SBarry Smith #else 4026cec326SBarry Smith if (key.j < 0) continue; 4126cec326SBarry Smith #endif 4226cec326SBarry Smith #else 4326cec326SBarry Smith #if defined(TYPE_SBAIJ) 4426cec326SBarry Smith if (key.j < key.i) continue; 4526cec326SBarry Smith #else 4626cec326SBarry Smith if (key.j < 0) continue; 4726cec326SBarry Smith #endif 4826cec326SBarry Smith #endif 49*f4f49eeaSPierre Jolivet value = values ? (a->roworiented ? values[r * n + c] : values[r + m * c]) : 0; 5026cec326SBarry Smith switch (addv) { 5126cec326SBarry Smith case INSERT_VALUES: 5226cec326SBarry Smith PetscCall(PetscHMapIJVQuerySet(a->ht, key, value, &missing)); 5326cec326SBarry Smith break; 5426cec326SBarry Smith case ADD_VALUES: 5526cec326SBarry Smith PetscCall(PetscHMapIJVQueryAdd(a->ht, key, value, &missing)); 5626cec326SBarry Smith break; 5726cec326SBarry Smith default: 5826cec326SBarry Smith SETERRQ(PETSC_COMM_SELF, PETSC_ERR_ARG_WRONG, "InsertMode not supported"); 5926cec326SBarry Smith } 6026cec326SBarry Smith if (missing) ++a->dnz[key.i]; 6126cec326SBarry Smith #if defined(TYPE_BS_ON) 6226cec326SBarry Smith PetscCall(PetscHSetIJQueryAdd(a->bht, bkey, &missing)); 6326cec326SBarry Smith if (missing) ++a->bdnz[bkey.i]; 6426cec326SBarry Smith #endif 6526cec326SBarry Smith } 6626cec326SBarry Smith } 6726cec326SBarry Smith PetscFunctionReturn(PETSC_SUCCESS); 6826cec326SBarry Smith } 69