[petsc-users] how to use MatSetValues?

Tomasz Jankowski tomjan at jay.au.poznan.pl
Tue Mar 8 05:58:39 CST 2011


>> I'm building 100mln x 100mln matrices and bigger. what means that with
>> linebyline scheme i have to 100mln times allocate array with size equal to
>> 100mln with only few nonzero entries.
>> not efficient too much i think...
>
> You don't have to allocate a full array for each line, just an array
> with the nonzero elements and a corresponding array with the row
> indices.
>
> That is, to store a line like
> [ 0 0 0 1 0 0 2 0 0 0 3 0 0]
>
> the two array would be
>
> icols[] = { 3 , 6, 10 };
> ivals[] = { 1 , 2, 3};
>
> and the call for the value would be
>
> MatSetValues(xx,1,irow,3,icols,*ivals,INSERT_VALUES);
>
> If there are multiple lines with the same nonzero structure they can
> be stored together.

yes, yes. of course you are absolutely right.
I did a mistake here. But I was only my supposedly thinking about 
'linebyline' scheme. In fact each entry of my matrix 'appear' (when the 
data file is processed)  in random order. so, it seems that with 
MatSetValues I could only use 'onebyone' scheme :-(

i hope I will find how to access private structure of matrix.

tom



More information about the petsc-users mailing list