On Tue, Oct 2, 2012 at 5:25 AM, TAY wee-beng <span dir="ltr"><<a href="mailto:zonexo@gmail.com" target="_blank">zonexo@gmail.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">
<div bgcolor="#FFFFFF" text="#000000"><div class="im">
<div>On 1/10/2012 4:39 PM, Jed Brown wrote:<br>
</div>
<blockquote type="cite">MatSetValues() inserts logically dense blocks. You are
thinking of it as inserting a bunch of arbitrary (row,col,value)
but that's not how it works. Read the man page and look at any of
the examples.<br>
</blockquote>
<br></div>
If that's the case, is the 1st method I used the best way to insert
the matrix?<br></div></blockquote><div><br></div><div>Yes, inserting one row at a time is typical.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
<br>
In other words, I already have the A matrix and b vector in Fortran
matrix, used for solving Ax = b.<br>
<br>
Is there a better or more efficient way of inserting the Fortran
matrix into PETSC's matrix?<br>
<br>
Thanks<div class="im"><br>
<blockquote type="cite"><br>
<div class="gmail_quote">
On Mon, Oct 1, 2012 at 10:36 AM, TAY wee-beng <span dir="ltr"><<a href="mailto:zonexo@gmail.com" target="_blank">zonexo@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"> Hi,<br>
<br>
I'm trying to insert values into my PETSc matrix using
MatSetValues.<br>
<br>
I tried using:<br>
<br>
<i>do ijk=ijk_xyz_sta,ijk_xyz_end</i><i><br>
</i><i><br>
</i><i> II = ijk - 1 !Fortran shift to 0-based</i><i><br>
</i><i> </i><i><br>
</i><i> call
MatSetValues(A_semi_xyz,1,II,7,int_semi_xyz(ijk,1:7),semi_mat_xyz(ijk,1:7),INSERT_VALUES,ierr)</i><i><br>
</i><i><br>
</i><i>end do</i><br>
<br>
where ijk_xyz_sta/ijk_xyz_end are the starting/end index<br>
<br>
int_semi_xyz(ijk,1:7) stores the 7 column global indices<br>
<br>
semi_mat_xyz has the corresponding values.<br>
<br>
This work well but I'm trying to call MatSetValues in 1
statement, it failed. I tried:<br>
<br>
<i>do ijk = 1,ijk_xyz_end-ijk_xyz_sta</i><i><br>
</i><i><br>
</i><i> rows(ijk) = ijk_xyz_sta + ijk - 1</i><i> !to
get row's global indices<br>
</i><i> </i><i><br>
</i><i>end do</i><i><br>
</i><i><br>
</i><i>call
MatSetValues(A_semi_xyz,ijk_xyz_end-ijk_xyz_sta,rows,7,int_semi_xyz(ijk_xyz_sta+1:ijk_xyz_end,1:7),semi_mat_xyz(ijk_xyz_sta+1:ijk_xyz_end,1:7),INSERT_VALUES,ierr)</i><br>
<br>
but when I use MatView, the values are in the wrong
locations.<br>
<br>
May I know what's wrong?<br>
<br>
Thanks<span><font color="#888888"><br>
<pre cols="72">--
Yours sincerely,
TAY wee-beng</pre>
</font></span></div>
</blockquote>
</div>
<br>
</blockquote>
<br>
</div></div>
</blockquote></div><br>