I was tired of writing MatSetOption(Ap,MAT_NEW_NONZERO_ALLOCATION_ERR,PETSC_TRUE) into my code to find preallocation issues, so I added -mat_new_nonzero_allocation_err to MatSetFromOptions(). Now I actually call that function. In particular, I do things like<div>
<br></div><div>PetscOptionsList("-Ap_mat_type","Matrix type for velocity operator","",MatList,mattype_Ap,mattype_Ap,sizeof(mattype_Ap),NULL);</div><div>...</div><div>DMGetMatrix(fsu,mattype_Ap,&Ap);</div>
<div>MatSetOptionsPrefix(Ap,"Ap_");</div><div>MatSetOption(Ap,MAT_SYMMETRIC,PETSC_TRUE);</div><div>MatSetFromOptions(Ap);</div><div>// Check type and set MAT_IGNORE_LOWER_TRIANGULAR if necessary</div><div><br></div>
<div><br></div><div>Three problems:</div><div><br></div><div>1. This is too damn much work.</div><div><br></div><div>2. Checking the type is an ugly hack. Should MAT_IGNORE_LOWER_TRIANGULAR be default, or should nonsymmetric matrices ignore it, or should there be a new option with those semantics?</div>
<div><br></div><div>3. It's wrong to use "-Ap_mat_type sbaij" because the actual type becomes seqsbaij, and then preallocation is thrown away [*] when MatSetFromOptions finds "sbaij", calls MatSetType which compares it to "seqsbaij", and resets the type. This means that I have to use a different prefix to choose which type to pass to DMGetMatrix() than the prefix I subsequently set on the matrix.</div>
<div><br></div><div><br></div><div>Any ideas how to make this work in a sane way?</div><div><br></div><div>[*] I was getting a seg-fault, but I set mat->preallocated to false in MatSetType. It doesn't crash any more, but preallocation is still thrown away.</div>