#include static char help[] = ""; int main(int argc,char **args) { PetscInt n = 2; Mat array[1],B,conjugate; PetscBool flg = PETSC_FALSE, correct = PETSC_FALSE; PetscCall(PetscInitialize(&argc,&args,NULL,help)); PetscCall(MatCreateConstantDiagonal(PETSC_COMM_WORLD,n,n,n,n,-1.0,array)); PetscCall(MatConvert(array[0],MATDENSE,MAT_INPLACE_MATRIX,array)); PetscCall(MatSetRandom(array[0],NULL)); PetscCall(MatViewFromOptions(array[0],NULL,"-A_view")); PetscCall(PetscOptionsGetBool(NULL,NULL,"-convert",&flg,NULL)); if (flg) { PetscCall(MatConvert(array[0],MATAIJ,MAT_INPLACE_MATRIX,array)); PetscCall(PetscOptionsGetBool(NULL,NULL,"-correct",&correct,NULL)); } PetscCall(MatProductCreate(array[0],array[0],NULL,&B)); PetscCall(MatProductSetType(B,MATPRODUCT_AtB)); PetscCall(MatProductSetFromOptions(B)); PetscCall(MatProductSymbolic(B)); if (PetscDefined(USE_COMPLEX)) { PetscCall(MatDuplicate(array[0], MAT_COPY_VALUES, &conjugate)); PetscCall(MatConjugate(conjugate)); if (!correct) PetscCall(MatProductReplaceMats(conjugate,array[0],NULL,B)); else PetscCall(MatProductReplaceMats(array[0],conjugate,NULL,B)); } PetscCall(MatProductNumeric(B)); if (PetscDefined(USE_COMPLEX)) { PetscCall(MatDestroy(&conjugate)); if (correct) PetscCall(MatConjugate(B)); } PetscCall(MatViewFromOptions(B,NULL,"-product_view")); PetscCall(MatDestroy(&B)); PetscCall(MatDestroy(array)); PetscCall(PetscFinalize()); return 0; }