On Tue, Apr 19, 2011 at 9:08 PM, Debao Shao <span dir="ltr"><<a href="mailto:Debao.Shao@brion.com">Debao.Shao@brion.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Dear Barry:<br>
<br>
If I add "MatSetOption(C,MAT_KEEP_NONZERO_PATTERN,PETSC_TRUE)" before " MatZeroEntries", need I reset it back when doing MatCopy?<br></blockquote><div><br></div><div>No.</div><div><br></div><div> Matt</div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I'm a freshman to PETSC, your reply is very appreciated.<br>
<br>
Thanks,<br>
Debao<br>
<br>
-----Original Message-----<br>
From: <a href="mailto:petsc-users-bounces@mcs.anl.gov">petsc-users-bounces@mcs.anl.gov</a> [mailto:<a href="mailto:petsc-users-bounces@mcs.anl.gov">petsc-users-bounces@mcs.anl.gov</a>] On Behalf Of Debao Shao<br>
Sent: Wednesday, April 20, 2011 9:50 AM<br>
To: PETSc users list<br>
Subject: Re: [petsc-users] MatCopy and MatSetValue consume most 99 percentage of runtime<br>
<br>
Here is my sample code:<br>
ierr = MatZeroEntries( M ); assert( ierr == 0);<br>
ierr = MatDiagonalSet( M, vec.pv, INSERT_VALUES );<br>
ierr = MatCopy( ms->M, mStorage->M, DIFFERENT_NONZERO_PATTERN );<br>
<br>
I checked PETSC api, both "MatDiagonalSet" and "MatCopy" called MatAssembly***, Is the usage wrong, or, how to deal with the problem?<br>
<br>
Thanks,<br>
Debao<br>
-----Original Message-----<br>
From: <a href="mailto:petsc-users-bounces@mcs.anl.gov">petsc-users-bounces@mcs.anl.gov</a> [mailto:<a href="mailto:petsc-users-bounces@mcs.anl.gov">petsc-users-bounces@mcs.anl.gov</a>] On Behalf Of Barry Smith<br>
Sent: Wednesday, April 20, 2011 9:40 AM<br>
To: PETSc users list<br>
Subject: Re: [petsc-users] MatCopy and MatSetValue consume most 99 percentage of runtime<br>
<br>
<br>
On Apr 19, 2011, at 8:31 PM, Debao Shao wrote:<br>
<br>
> Hi, Barry:<br>
><br>
> Thanks for the reply.<br>
><br>
> I preallocated enough space for the sparse matrix, but I found mat->data->imax changed after "MatAssemblyEnd", and it caused many rowmax less than the number of nonzeros per row, then "MatSeqXAIJReallocateAIJ" is called frequently when doing MatSetValues again to the matrix.<br>
<br>
Are you using MatZeroRows()? If so call MatSetOption(mat, MAT_KEEP_NONZERO_PATTERN) before calling the zero rows to retain that structure.<br>
<br>
If you are not using MatZeroRows() then apparently the first time you set values in there and call MatAssemblyEnd() you have left many locations that later will be filled unfilled and so they are eliminated at MatAssembly time. You must make sure that all potentially nonzero locations get a value put in initially (put zero for the locations that you don't yet have a value for) before you first call MatAssemblyEnd().<br>
<br>
Barry<br>
<br>
PETSc matrices have no way of retaining extra locations you preallocated for unless you put something (like 0) in there.<br>
<br>
><br>
> Any suggestions?<br>
><br>
> Thanks,<br>
> Debao<br>
> -----Original Message-----<br>
> From: <a href="mailto:petsc-users-bounces@mcs.anl.gov">petsc-users-bounces@mcs.anl.gov</a> [mailto:<a href="mailto:petsc-users-bounces@mcs.anl.gov">petsc-users-bounces@mcs.anl.gov</a>] On Behalf Of Barry Smith<br>
> Sent: Friday, April 15, 2011 9:25 PM<br>
> To: PETSc users list<br>
> Subject: Re: [petsc-users] MatCopy and MatSetValue consume most 99 percentage of runtime<br>
><br>
><br>
> Debao,<br>
><br>
> Please see <a href="http://www.mcs.anl.gov/petsc/petsc-as/documentation/faq.html#efficient-assembly" target="_blank">http://www.mcs.anl.gov/petsc/petsc-as/documentation/faq.html#efficient-assembly</a> It should resolve the difficulties.<br>
><br>
> Barry<br>
><br>
> On Apr 15, 2011, at 2:16 AM, Debao Shao wrote:<br>
><br>
>> Dear Petsc:<br>
>><br>
>> I'm trying on Petsc iterative solver(KSPCG & PCJACOBI), but it's strange that the two functions "MatCopy" and "MatSetValue" consume most of runtime, and the functions were not called frequently, just several times.<br>
>><br>
>> My libpetsc.a is built as follows:<br>
>> 1, /config/configure.py --with-mpi=0 --with-debugging=0 -with-log=0 -with-info=0<br>
>> 2, make all;<br>
>><br>
>> It's very appreciated to get your reply.<br>
>><br>
>> Thanks a lot,<br>
>> Debao<br>
>><br>
>> -- The information contained in this communication and any attachments is confidential and may be privileged, and is for the sole use of the intended recipient(s). Any unauthorized review, use, disclosure or distribution is prohibited. Unless explicitly stated otherwise in the body of this communication or the attachment thereto (if any), the information is provided on an AS-IS basis without any express or implied warranties or liabilities. To the extent you are relying on this information, you are doing so at your own risk. If you are not the intended recipient, please notify the sender immediately by replying to this message and destroy all copies of this message and any attachments. ASML is neither liable for the proper and complete transmission of the information contained in this communication, nor for any delay in its receipt.<br>
><br>
><br>
> -- The information contained in this communication and any attachments is confidential and may be privileged, and is for the sole use of the intended recipient(s). Any unauthorized review, use, disclosure or distribution is prohibited. Unless explicitly stated otherwise in the body of this communication or the attachment thereto (if any), the information is provided on an AS-IS basis without any express or implied warranties or liabilities. To the extent you are relying on this information, you are doing so at your own risk. If you are not the intended recipient, please notify the sender immediately by replying to this message and destroy all copies of this message and any attachments. ASML is neither liable for the proper and complete transmission of the information contained in this communication, nor for any delay in its receipt.<br>
<br>
<br>
-- The information contained in this communication and any attachments is confidential and may be privileged, and is for the sole use of the intended recipient(s). Any unauthorized review, use, disclosure or distribution is prohibited. Unless explicitly stated otherwise in the body of this communication or the attachment thereto (if any), the information is provided on an AS-IS basis without any express or implied warranties or liabilities. To the extent you are relying on this information, you are doing so at your own risk. If you are not the intended recipient, please notify the sender immediately by replying to this message and destroy all copies of this message and any attachments. ASML is neither liable for the proper and complete transmission of the information contained in this communication, nor for any delay in its receipt.<br>
<br>
-- The information contained in this communication and any attachments is confidential and may be privileged, and is for the sole use of the intended recipient(s). Any unauthorized review, use, disclosure or distribution is prohibited. Unless explicitly stated otherwise in the body of this communication or the attachment thereto (if any), the information is provided on an AS-IS basis without any express or implied warranties or liabilities. To the extent you are relying on this information, you are doing so at your own risk. If you are not the intended recipient, please notify the sender immediately by replying to this message and destroy all copies of this message and any attachments. ASML is neither liable for the proper and complete transmission of the information contained in this communication, nor for any delay in its receipt.<br>
</blockquote></div><br><br clear="all"><br>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener<br>