<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" id="owaParaStyle"></style>
</head>
<body fpstyle="1" ocsi="0">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hello, 
<div><br>
</div>
<div>The following lines of code give me trouble because PETSc gives me an error message saying the object A is in a wrong state, and <span style="font-family: Menlo; font-size: 11px;">Must call MatXXXSetPreallocation() or MatSetUp() on argument 1 "mat" before
 MatGetOwnershipRange()</span><span style="font-size: 10pt;">.</span></div>
<div><span style="font-size: 10pt;"><br>
</span></div>
<div><span style="font-size: 10pt;">Here is part of the code:  </span></div>
<div>
<div><br>
</div>
<div>
<p style="margin-right: 0px; margin-left: 0px; font-size: 11px; font-family: Menlo;">
    ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr);</p>
<p style="margin-right: 0px; margin-left: 0px; font-size: 11px; font-family: Menlo;">
    ierr = MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,<span style="color: #272ad8">2</span>*nx*ny,<span style="color: #272ad8">2</span>*nx*ny);CHKERRQ(ierr);</p>
<p style="margin-right: 0px; margin-left: 0px; font-size: 11px; font-family: Menlo;">
    ierr = MatSetType(A,MATAIJ);CHKERRQ(ierr);</p>
<p style="margin-right: 0px; margin-left: 0px; font-size: 11px; font-family: Menlo;">
    ierr = MatMPIAIJSetPreallocation(A,<font color="#272ad8">9</font>,<span style="color: rgb(187, 44, 162);">NULL</span>,<span style="color: rgb(39, 42, 216);">9</span>,<span style="color: rgb(187, 44, 162);">NULL</span>);CHKERRQ(ierr);</p>
<p style="margin-right: 0px; margin-left: 0px; font-size: 11px; font-family: Menlo;">
    ierr = MatGetOwnershipRange(A, &start, &end);CHKERRQ(ierr);</p>
<p style="margin-right: 0px; margin-left: 0px; font-size: 11px; font-family: Menlo;">
<br>
</p>
<p style="margin-right: 0px; margin-left: 0px;">I think I have called <span style="font-family: Menlo; font-size: 11px;">MatMPIAIJSetPreallocation, </span><span style="font-size: 10pt;">so what might be causing the problem here? </span></p>
<p style="margin-right: 0px; margin-left: 0px;"><span style="font-size: 10pt;"><br>
</span></p>
<p style="margin-right: 0px; margin-left: 0px;">Best,</p>
<p style="margin-right: 0px; margin-left: 0px;">Hui</p>
</div>
</div>
</div>
</body>
</html>