[petsc-users] Matrix Construction Question
Matthew Knepley
knepley at gmail.com
Thu Jul 7 13:09:34 CDT 2011
On Thu, Jul 7, 2011 at 5:02 PM, Adam Byrd <adam1.byrd at gmail.com> wrote:
> Changing the matrix types worked. When solving AX=B, X and B have to be
> dense and A can be a sparse format? I'd like to avoid storing the identity
> as a dense format, if possible. By the way, the man page for MATAIJ says
> it's a sparse format
> http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-current/docs/manualpages/Mat/MATAIJ.html
> .
Yes, AIJ is sparse.
> I must ask, is there somewhere in the documentation I should be looking to
> figure these sorts of questions out? I feel like a pest, but I'm not sure
> where else to look for answers.
>
Which questions? If you mean about the MatMatSolve, it says the arguments
must be dense on the webpage:
http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-current/docs/manualpages/Mat/MatMatSolve.html
There is also a manual, FAQ, and hundreds of hyperlinked examples.
Matt
> On Thu, Jul 7, 2011 at 12:20 AM, Jed Brown <jedbrown at mcs.anl.gov> wrote:
>
>> On Wed, Jul 6, 2011 at 09:53, Adam Byrd <adam1.byrd at gmail.com> wrote:
>>
>>> I do not want the transpose, but that is what is coming out as the
>>> solution. Both my tests show the correct original matrix, and both yield the
>>> transpose of the solution verified against Mathematica and the website from
>>> which I pulled the 4x4 matrix in test.cpp. Could it be related to the
>>> factoring?
>>
>>
>> The problem is that you are trying to solve with an AIJ matrix instead of
>> a DENSE matrix. MatMatSolve() calls MatGetArray(). Since this is serial and
>> you preallocated enough for a dense matrix, it goes through with no memory
>> errors. The storage format for MATAIJ (that happens to be dense) and
>> MATDENSE is transposed, so you see the transpose. If you make the solution
>> matrix dense, then it will work correctly.
>>
>>
>> --- a/test.cpp
>> +++ b/test.cpp
>> @@ -48,7 +48,9 @@ int main(int argc,char **args)
>> ierr = MatAssemblyEnd(identityMat,
>> MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
>>
>> //Setup inverseMat
>> - ierr = MatDuplicate(testMat, MAT_DO_NOT_COPY_VALUES,
>> &inverseMat);CHKERRQ(ierr);
>> + ierr = MatCreate(PETSC_COMM_WORLD, &inverseMat);CHKERRQ(ierr);
>> + ierr = MatSetSizes(inverseMat, PETSC_DECIDE, PETSC_DECIDE, rows,
>> columns);CHKERRQ(ierr);
>> + ierr = MatSetType(inverseMat, MATDENSE);CHKERRQ(ierr);
>> ierr = MatAssemblyBegin(inverseMat,
>> MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
>> ierr = MatAssemblyEnd(inverseMat,
>> MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
>>
>>
>>
>> PETSc should be more careful about matching types here.
>>
>
>
--
What most experimenters take for granted before they begin their experiments
is infinitely more interesting than any results to which their experiments
lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110707/a725b928/attachment.htm>
More information about the petsc-users
mailing list