Hi Joon, yes, MatGetSubMatrices should do the job - even though it copies the values. Just create the respective index sets for irow and icol directly. Have a look at at src/mat/examples/tests/ex51.c [1] on how to extract the matrices. Keep in mind that you need to specify all indices within a block (cf. MatGetSubMatrices man page [2])
Best regards, Karli [1] http://www.mcs.anl.gov/petsc/petsc-dev/src/mat/examples/tests/ex51.c.html [2] http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatGetSubMatrices.html On 04/24/2013 11:24 AM, Joon hee Choi wrote: > Hi Karli, > > It may be a good idea to compute the result blocks directly. What function do > I need to use for getting each block? I tried to use MatGetSubMatrices(Mat > mat,PetscInt n,const IS irow[],const IS icol[],MatReuse scall,Mat *submat[]), > but I didn't know how I got irow[] and icol[] from block matrix. > > Best regards, > Joon > > ----- ?? ??? ----- > ?? ??: "Karl Rupp" <rupp at mcs.anl.gov> > ?? ??: "Joon hee Choi" <choi240 at purdue.edu> > ??: petsc-users at mcs.anl.gov > ?? ??: 2013? 4? 24?, ??? ?? 12:07:11 > ??: Re: [petsc-users] Transpose of Block Matrix with aij type > > Hi Joon, > > you're welcome - another idea: if you have just six matrices A1, A2, and > B1-B4, it's worthwhile to compute the result blocks B1A1 + B2A2 and B3A1 > + B4A2 directly into temporary matrices using standard operations and > compose the result into a single matrix. This way you can avoid the more > expensive copies of A1, A2, B1-B4. > > Best regards, > Karli > > > On 04/24/2013 10:45 AM, Joon hee Choi wrote: >> Hi Karli, >> >> Thank you. Actually, B is very huge(more than 10^10) and sparse(about 1% >> dense). 3x3 and 3x4 matrices were an example. I think I have to set up A >> again. Anyway, thank you again. >> >> Best regards, >> Joon >> >> >> ----- ?? ??? ----- >> ?? ??: "Karl Rupp" <rupp at mcs.anl.gov> >> ?? ??: "Choi240" <choi240 at purdue.edu> >> ??: petsc-users at mcs.anl.gov >> ?? ??: 2013? 4? 23?, ??? ?? 9:39:56 >> ??: Re: [petsc-users] Transpose of Block Matrix with aij type >> >> Hi Joon, >> >> sorry, that was a pretty bad idea (wouldn't even work with square >> matrices in general) >> >> I'm afraid you'll have to set up new matrices A, B with the respective >> entries. For performance reasons you better use a dense format since >> your matrices are so small. >> >> Best regards, >> Karli >> >> >> On 04/23/2013 06:05 PM, Choi240 wrote: >>> Hi, >>> >>> Thank you for your reply. But A1,A2 are not square(3x4). B1~B4 are 3x3 >>> matrices. So A1*B1 is not impossible. >>> >>> Best regards, >>> Joon >>> >>> >>> >>> >>> -------- Original message -------- >>> Subject: Re: [petsc-users] Transpose of Block Matrix with aij type >>> From: Karl Rupp <rupp at mcs.anl.gov> >>> To: Choi240 <choi240 at purdue.edu> >>> CC: petsc-users at mcs.anl.gov >>> >>> >>> Hi again, >>> >>> if you have control over the structure of B, what about computing >>> [A1 A2] * [B1 B3; B2 B4] >>> instead? >>> >>> Best regards, >>> Karli >>> >>> >>> On 04/23/2013 05:17 PM, Choi240 wrote: >>> > Hi, >>> > >>> > I have to compute multiplication between two block matrices. It should >>> > be as follows: >>> > >>> > B1 | B2 A1 B1A1+B2A2 >>> > ---------- * --- = --------------- >>> > B3 | B4 A2 B3A1+B4A2 >>> > >>> > However, I just have A = [A1 A2]. So, I need to get A^T. Is there a >>> way >>> > I can get the transpose of this block matrix with the MatTranspose()? >>> Or >>> > do I have to use another function such as MatGetSubMatrices()? >>> > >>> > Thank you, >>> > Joon >>> > >>> > >>> > >>> > -------- Original message -------- >>> > Subject: Re: [petsc-users] Transpose of Block Matrix with aij type >>> > From: Karl Rupp <rupp at mcs.anl.gov> >>> > To: petsc-users at mcs.anl.gov >>> > CC: choi240 at purdue.edu >>> > >>> > >>> > Hi, >>> > >>> > why would you expect that the transpose of a 3x8 matrix is not a >>> 8x3-matrix? >>> > >>> > Best regards, >>> > Karli >>> > >>> > >>> > On 04/23/2013 03:27 PM, Joon hee Choi wrote: >>> > > Hello, >>> > > >>> > > I tried to get transpose of block matrix(just with aij type), but >>> the >>> > result was not a block matrix. For example, >>> > > >>> > > A = >>> > > 1 2 3 4 | 4 3 2 1 >>> > > 2 3 4 5 | 5 4 3 2 >>> > > 3 4 5 6 | 6 5 4 3 >>> > > >>> > > >>> > > AT(expected) = >>> > > 1 2 3 4 >>> > > 2 3 4 5 >>> > > 3 4 5 6 >>> > > ------- >>> > > 4 3 2 1 >>> > > 5 4 3 2 >>> > > 6 5 4 3 >>> > > >>> > > >>> > > AT(result) = >>> > > 1 2 3 >>> > > 2 3 4 >>> > > 3 4 5 >>> > > 4 5 6 >>> > > 4 5 6 >>> > > 3 4 5 >>> > > 2 3 4 >>> > > 1 2 3 >>> > > >>> > > If someone knows about this problem, please let me know it. >>> > > >>> > > Thank you >>> > > >>> > >>> >> >
