[petsc-users] about MatTranspose

Likun Tan likunt at andrew.cmu.edu
Thu Sep 1 12:45:45 CDT 2011


Thank you for your patience.

I still have some confusions. When computing B before MPI_Scan(), could i
compute the values in parallel? After using MPI_Scan(), does that mean the
columns of B will be gathered in one processor?

Here are main steps i took based on your suggestion,

PetscSplitOwnership(PETSC_COMM_WORLD, &n, &N);
MatCreateSeqDense(PETSC_COMM_SELF, M, n, PETSC_NULL, &B);
MatCreateSeqDense(PETSC_COMM_SELF, M, M, PETSC_NULL, &A);
MatCreateSeqDense(PETSC_COMM_SELF, M, N, PETSC_NULL, &x);
for(j=0; j<N; j++)
{
   for(i=0; i<M; i++)
   {
      MatSetValues(B, 1, &i, 1, &j, &value, INSERT_VALUES);
   }
}
MatAssemblyBegin(...);
MatAssemblyEnd(...)
MPI_Scan(&n, &cstart, 1, MPIU_INT, MPI_SUM, PETSC_COMM_WORLD);
cstart -= n;

MatConvert(...);
MatCholeskyFactor(...);
MatMatSolve(...);


best,
Likun

On Thu, September 1, 2011 11:59 am, Jed Brown wrote:
> On Thu, Sep 1, 2011 at 10:46, Likun Tan <likunt at andrew.cmu.edu> wrote:
>
>
>> I tried to use
>> PetscSplitOwnership(PETSC_COMM_WORLD,&n,&N);
>> MatCreateSeqDense(PETSC_COMM_SELF,M,n,PETSC_NULL,&B);
>>
>>
>> But it seems not working. This command is make B store in N/n
>> processors with n columns in each processor?
>>
>
> B (in the code) is a different matrix on each process. You should fill
> the columns so that each process has part of B (the logical thing you are
> working with).
>
>
>> I try to calculate the N/n parts in
>> parallel, but when i apply MatGetOwnershipRange(), i found the matrix
>> will be automatically partitioned by row.
>>
>
> MatGetOwnershipRange() just gives you the rows from 0 to 26. You need to
> sum the column partition that was computed earlier. The most explicit way
> to do that is
>
> PetscInt cstart;
> MPI_Scan(&n,&cstart,1,MPIU_INT,MPI_SUM,PETSC_COMM_WORLD);
> cstart -= n;
>
> Now each process should compute columns of the logical B in the range
> [cstart,cstart+n). The B object in your code will indexed [0,n) on each
> process, but these columns correspond to [cstart,cstart+n).
>
>
>> That's why i go back to use MatCreate() to create a 200*27 matrix and
>> try to get the tranpose of it.I used MatCreateSeqDense(PETSC_COMM_SELF,
>> M, N, PETSC_NULL, &C)
>> to create C, there is no partition of C, i guess this is the reason of
>> the error.
>>
>
> Don't go down this route, it doesn't do what you want.
>
>






More information about the petsc-users mailing list