<!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> </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 requirements I should convert the
nz 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 the idxn array type also must be
promoted to be compliant with a 64 bit PetscInt type.
This requires the double amount of memory for nz and
idxn.</FONT></DIV>
<DIV><FONT size=2><FONT size=2></FONT></FONT> </DIV>
<DIV><FONT size=2>What do you think about the opportunity to provide another
version of MatMPIAIJSetPreallocationCSR based on relative
offsets to save memory?</FONT></DIV>
<DIV><FONT size=2>Absolute offsets could be managed internally
... </FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>Finally I've look into the body
of MatMPIAIJSetPreallocationCSR_MPIAIJ function ad I found this
snippet of code</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>for (i=0; i<m; i++) {<BR> ii
= i + rstart;<BR> nnz = I[i+1]-
I[i];<BR> ierr =
MatSetValues_MPIAIJ(B,1,&ii,nnz,J+I[i],values+(v ? I[i] :
0),INSERT_VALUES);CHKERRQ(ierr);<BR> }</FONT></DIV>
<DIV><FONT size=2></FONT> </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> </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>> Hi,
guys,<BR>><BR>> I'm trying to solve a linear system with M equations and
N unknowns (M >> N) using the LSQR method.<BR>><BR>> I have a C
parallel sparse matrix MxN with NZ nonzero elements stored in this
way:<BR>><BR>> double values[NZ]; // the nonzero values<BR>> int
idxn[NZ]; // the column indices<BR>> 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>><BR>>
what is the best way to create a PETSc
matrix?<BR><BR>MatMPIAIJSetPreallocationCSR()</DIV>
<DIV> </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>><BR>> 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>> Just another detail. Initially M is
unknown. All my structures are<BR>> allocated dynamically because the
number of rows M (and the number<BR>> of nonzero NZ also) is determined
just before to solve the system,<BR>> so I think it's no feasible for me to
call MatCreateMPIAIJ at the<BR>> begin of my code and to perform the
MatSetValues loop.<BR><BR> 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>
Barry<BR><BR>><BR>> Roberto<BR>><BR>>
================================================================<BR>> |
Roberto
Gori
CINECA<BR>> | High Performance System
Group Via Magnanelli 6/3
40033<BR>> | e-mail: <A
href="mailto:r.gori@cineca.it">r.gori@cineca.it</A>
Casalecchio di Reno<BR>> | Tel:
051/6171522
Bologna - ITALY<BR>> | Fax:
051/6132198
<A href="http://www.cineca.it">http://www.cineca.it</A><BR>>
================================================================<BR>><BR>><BR><BR></DIV></BLOCKQUOTE></BODY></HTML>