<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2900.2802" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2>Many thanks Barry,</FONT></DIV>
<DIV><FONT size=2><FONT size=2><FONT size=2></FONT></FONT></FONT>&nbsp;</DIV>
<DIV><FONT size=2>MatMPIAIJSetPreallocationCSR could be a good solution for 
me.</FONT></DIV>
<DIV><FONT size=2>It seems that to satisfy the 
MatMPIAIJSetPreallocationCSR&nbsp; requirements I should convert the 
nz&nbsp;array from a relative to an absolute representation of the row offsets 
but ...</FONT></DIV>
<DIV><FONT size=2>I think this implies a not negligible drawback: my matrix is 
too large and offsets must be promoted to a long long int (64 bit) 
type.</FONT></DIV>
<DIV><FONT size=2>Moreover&nbsp;the&nbsp;&nbsp;idxn array type also must be 
promoted to be compliant with a 64 bit PetscInt&nbsp; type. 
&nbsp;This&nbsp;requires the double amount of memory for nz and 
idxn.</FONT></DIV>
<DIV><FONT size=2><FONT size=2></FONT></FONT>&nbsp;</DIV>
<DIV><FONT size=2>What do you think about the opportunity to provide another 
version of&nbsp;&nbsp;MatMPIAIJSetPreallocationCSR&nbsp;&nbsp;based on relative 
offsets to save memory?</FONT></DIV>
<DIV><FONT size=2>Absolute offsets could be managed internally&nbsp; 
...&nbsp;&nbsp;&nbsp;&nbsp;</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>Finally I've look into the body 
of&nbsp;&nbsp;MatMPIAIJSetPreallocationCSR_MPIAIJ function ad I found this 
snippet of code</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>for (i=0; i&lt;m; i++) {<BR>&nbsp;&nbsp;&nbsp; ii&nbsp;&nbsp; 
= i + rstart;<BR>&nbsp;&nbsp;&nbsp; nnz&nbsp; = I[i+1]- 
I[i];<BR>&nbsp;&nbsp;&nbsp; ierr = 
MatSetValues_MPIAIJ(B,1,&amp;ii,nnz,J+I[i],values+(v ? I[i] : 
0),INSERT_VALUES);CHKERRQ(ierr);<BR>&nbsp; }</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV><FONT size=2>There's no way to avoid the copy of the values? This doubles 
one more time the memory for the values array and spend time into the 
loop.</FONT></DIV>
<DIV><FONT size=2>Morevover nnz corresponds exactly to my nz[i] ...</FONT></DIV>
<DIV><FONT size=2></FONT>&nbsp;</DIV>
<DIV>----- Original Message ----- </DIV>
<BLOCKQUOTE 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV 
  style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B> 
  <A title=bsmith@mcs.anl.gov href="mailto:bsmith@mcs.anl.gov">Barry Smith</A> 
  </DIV>
  <DIV style="FONT: 10pt arial"><B>To:</B> <A title=r.gori@cineca.it 
  href="mailto:r.gori@cineca.it">Roberto Gori</A> </DIV>
  <DIV style="FONT: 10pt arial"><B>Cc:</B> <A title=petsc-users@mcs.anl.gov 
  href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</A> </DIV>
  <DIV style="FONT: 10pt arial"><B>Sent:</B> Monday, February 06, 2006 4:15 
  PM</DIV>
  <DIV style="FONT: 10pt arial"><B>Subject:</B> Re: mat creation</DIV>
  <DIV><BR></DIV>
  <DIV><BR><BR>On Mon, 6 Feb 2006, Roberto Gori wrote:<BR><BR>&gt; Hi, 
  guys,<BR>&gt;<BR>&gt; I'm trying to solve a linear system with M equations and 
  N unknowns (M &gt;&gt; N) using the LSQR method.<BR>&gt;<BR>&gt; I have a C 
  parallel sparse matrix MxN with NZ nonzero elements stored in this 
  way:<BR>&gt;<BR>&gt; double values[NZ]; // the nonzero values<BR>&gt; int 
  idxn[NZ]; // the column indices<BR>&gt; int nz[M]; // the number of nonzero 
  values for each row<BR><BR>This needs to be instead indices to start of each 
  row in idxn and values<BR>instead of the length of each row.<BR>&gt;<BR>&gt; 
  what is the best way to create a PETSc 
  matrix?<BR><BR>MatMPIAIJSetPreallocationCSR()</DIV>
  <DIV>&nbsp;</DIV><FONT size=2></FONT></BLOCKQUOTE>
<BLOCKQUOTE 
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV><BR>&gt;<BR>&gt; Do exists a statement like VecCreateMPIWithArray for 
  already distributed vectors that could do all the work in one shot without 
  copy?<BR><BR>Yes<BR><BR>&gt;&nbsp; Just another detail. Initially M is 
  unknown.&nbsp; All my structures are<BR>&gt; allocated dynamically because the 
  number of rows M (and the number<BR>&gt; of nonzero NZ also) is determined 
  just before to solve the system,<BR>&gt; so I think it's no feasible for me to 
  call MatCreateMPIAIJ at the<BR>&gt; begin of my code and to perform the 
  MatSetValues loop.<BR><BR>&nbsp; There is nothing saying that you must "call 
  MatCreateMPIAIJ at the<BR>beginning of your code", you can call it anytime 
  that you have the<BR>needed information.<BR><BR>&nbsp;&nbsp; 
  Barry<BR><BR>&gt;<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Roberto<BR>&gt;<BR>&gt; 
  ================================================================<BR>&gt; | 
  Roberto 
  Gori&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  CINECA<BR>&gt; | High Performance System 
  Group&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Via Magnanelli 6/3 
  40033<BR>&gt; | e-mail: <A 
  href="mailto:r.gori@cineca.it">r.gori@cineca.it</A>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  Casalecchio di Reno<BR>&gt; | Tel: 
  051/6171522&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  Bologna - ITALY<BR>&gt; | Fax: 
  051/6132198&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  <A href="http://www.cineca.it">http://www.cineca.it</A><BR>&gt; 
  ================================================================<BR>&gt;<BR>&gt;<BR><BR></DIV></BLOCKQUOTE></BODY></HTML>