[petsc-users] about MatTranspose
Likun Tan
likunt at andrew.cmu.edu
Thu Sep 1 13:33:29 CDT 2011
Thank you very much.
With the command:
for(j=0; j<n; j++)
{
for(i=0; i<M; i++)
{
MatSetValues(B, 1, &i, 1, &j, &Value, INSERT_VALUES);
}
}
This only defines the columns from 0 to n-1? How exactly MPI_Scan()
getting used here?
And when i try to print out the result with
PetscViewer viewer;
PetscViewerSetFormat(viewer, PETSC_VIEWER_ASCII_MATLAB);
MatView(B, viewer);
I can only see the columns from 0 to n-1. Maybe there is still problem in
computing B.
Many thanks,
Likun
On Thu, September 1, 2011 1:54 pm, Jed Brown wrote:
> On Thu, Sep 1, 2011 at 12:45, Likun Tan <likunt at andrew.cmu.edu> wrote:
>
>
>> 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?
>>
>
> No, the scan is just computing the start column for a given process.
>
>
>
>>
>> Here are main steps i took based on your suggestion,
>>
>>
>> PetscSplitOwnership(PETSC_COMM_WORLD, &n, &N);
>>
>>
>
> Add these two lines here:
>
>
> MPI_Scan(&n, &cstart, 1, MPIU_INT, MPI_SUM, PETSC_COMM_WORLD);
> cstart -= n;
>
>
>> MatCreateSeqDense(PETSC_COMM_SELF, M, n, PETSC_NULL, &B);
>> MatCreateSeqDense(PETSC_COMM_SELF, M, M, PETSC_NULL, &A);
>>
>>
>
> Good
>
>
>
>> MatCreateSeqDense(PETSC_COMM_SELF, M, N, PETSC_NULL, &x);
>>
>>
>
> Replace with
>
>
> MatDuplicate(B,MAT_DO_NOT_COPY_VALUES,&x);
>
>
>
>> for(j=0; j<N; j++)
>>
>
> change the loop bounds here:
>
> for(j=0; j<n; j++)
>
>
>> {
>> for(i=0; i<M; i++) {
>>
>>
>
> Good, now compute value as the value that goes in (i,cstart+j).
>
>
> MatSetValues(B, 1, &i, 1, &j, &value, INSERT_VALUES);
>
>> }
>> }
>> MatAssemblyBegin(...);
>> MatAssemblyEnd(...)
>>
>>
>
> This part is correct.
>
>
>
>> MPI_Scan(&n, &cstart, 1, MPIU_INT, MPI_SUM, PETSC_COMM_WORLD);
>> cstart -= n;
>>
>
> We did this already.
>
>
>
>>
>> MatConvert(...);
>> MatCholeskyFactor(...);
>> MatMatSolve(...);
>>
>>
>
> Yes.
>
>
>
> You can gather the matrix x onto all processes if you need the whole
> result everywhere, but for performance reasons if you scale further, you
> should avoid it if possible.
>
More information about the petsc-users
mailing list