AIJ and BAIJ convertion

Hong Zhang hzhang at
Tue May 5 10:50:41 CDT 2009

On Tue, 5 May 2009, SUN Chun wrote:

> Thanks Hong and Satish,
> Unfortunately I did use MatCreateMPIAIJ. It's difficult to change that part of my code.
>Plus I have matrices dumped out with AIJ format and I want to read it as 
>BAIJ. It seems that I have no option other than MatCreateMPIBAIJ then 
>MatSetBlockSize then add entries one by one...?

You can call
ierr = MatLoad(fd,MATBAIJ,&newbaijmat);CHKERRQ(ierr);
and run your code with '-matload_block_size 6'.
In this way, a new baij matrix is created with bs=6.

> I was reading MatCopy and it says A and B should have same nnz pattern, which won't happen between AIJ and BAIJ. Also I was reading MatConvert, but it allocates new matrix for you without asking blocksize. I'm not sure either of them can do this.
MatCopy() cannot be used because aij and baij have very differnt data 
structure. MatConvert() gives a baij matrix with bs=1, not the one you 


> Thanks,
> Chun
> -----Original Message-----
> From: petsc-users-bounces at [mailto:petsc-users-bounces at] On Behalf Of Satish Balay
> Sent: Tuesday, May 05, 2009 11:18 AM
> To: PETSc users list
> Subject: Re: AIJ and BAIJ convertion
> This is assuming MatCreate() is used - not MatCreateMPIAIJ()..
> Satish
> On Tue, 5 May 2009, Hong Zhang wrote:
>> Run your code with the option
>> '-mat_type baij -mat_block_size 6'
>> You can use '-mat_view_info' to varify the matrix type
>> that is actually used.
>> Hong
>> On Tue, 5 May 2009, SUN Chun wrote:
>>> Hi,
>>> I created a matrix with AIJ format. I knew the structure of this matrix
>>> should also fit BAIJ type with some certain block size (say 6). Now instead
>>> of creating another BAIJ matrix then fill in the values again, do I have an
>>> easier way to convert this AIJ matrix to BAIJ matrix with given block size?
>>> I'm willing to allocate another memory for the new matrix.
>>> Thanks,
>>> Chun

More information about the petsc-users mailing list