efficient matrix block assignment

Barry Smith bsmith at mcs.anl.gov
Thu Aug 6 11:37:21 CDT 2009

On Aug 6, 2009, at 8:55 AM, Umut Tabak wrote:

> Matthew Knepley wrote:
>> On Thu, Aug 6, 2009 at 8:18 AM, Umut Tabak <u.tabak at tudelft.nl <mailto:u.tabak at tudelft.nl 
>> >> wrote:
>>    Dear all,
>>    I am trying some block matrix assembly in Petsc, so far, I was
>>    puzzling with the right calling and set up of MatSetValuesBlocked.
>>    Matthew Knepley confirmed my previous post. I guess it is the
>>    function I should use. But it accepts the values as a 1D array,
>>    which is  represented in row major order(by default). So the
>>    burden on this approach is to convert my Matrix into a 1D array,
>>    this seemed as the only solution for the moment. If I would like
>>    to use this function.
>> I need to understand what you mean here. The 1D array we accept  
>> here is the input values. It is physically 1D, but conceptually
>> 2D, and by default is in row-major order. This has nothing to do  
>> with your larger Mat object.
> Precisely, what i meant, there is a 2d array which is conceptually a  
> matrix in my case(where I read from a Finite element code). So I  
> must represent it as a 1D array.

    I most cases (Fortran always) a 2d array is just stored in memory  
as a 1d array so no conversion is needed. In C if you declare an array  
double something[3][3] then yes it is not suitable to directly passing  
into MatSetValues....().

>>    BTW, some blocks are square and some are rectangular, with block
>>    size type operations, I guess it is not possible to assign
>>    rectangular matrices to some part of a larger square matrix.
>> Not true. You can have any mxn dimension to the input values. I  
>> think there is some underlying confusion here
>> that I do not understand. I would suggest you look at the example  
>> in the manual.
>>  Matt
> This is also confusing for me for the moment. But there is only one  
> parameter, for operation MatSetBlockSize(Mat, blocksize), this was  
> what I meant by "block size" above. I should check the docs more, I  
> guess.

    The "blocks" in the matrix are always square. When you call  
MatSetValues() you can put in a rectangular block of values. When you  
call MatSetValuesBlock() you can put in a rectangular set of blocks.


> Hope made it clear.
> Thanks
> Umut

More information about the petsc-users mailing list