[petsc-users] Confusion with MatGetLocalSubMatrix

Lawrence Mitchell lawrence.mitchell at imperial.ac.uk
Fri Dec 19 12:19:16 CST 2014


...

>> Calling MatGetLocalSubMatrix results in an error:
>> 
>> [0]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------
>> [0]PETSC ERROR: Petsc has generated inconsistent data
>> [0]PETSC ERROR: Blocksize of localtoglobalmapping 1 must match that of layout 2
> 
> Hmm, I'm concerned that this might not work right after some recent
> changes to ISLocalToGlobalMapping.  Can you reproduce this with some
> code I can run?

Here we go:

#include <petsc.h>

int main(int argc, char **argv)
{
    PetscErrorCode ierr;
    DM v;
    DM p;
    DM pack;
    PetscSection vsec;
    PetscSection psec;
    PetscInt rbs, cbs;
    PetscInt srbs, scbs;
    Mat mat;
    Mat submat;
    IS *ises;

    MPI_Comm c;
    PetscInitialize(&argc, &argv, NULL, NULL);

    c = PETSC_COMM_WORLD;
    ierr = DMDACreate1d(c, DM_BOUNDARY_NONE, 10, 2, 1, NULL, &v); CHKERRQ(ierr);
    ierr = DMDACreate1d(c, DM_BOUNDARY_NONE, 10, 1, 1, NULL, &p); CHKERRQ(ierr);
    ierr = DMSetFromOptions(v); CHKERRQ(ierr);
    ierr = DMSetFromOptions(p); CHKERRQ(ierr);

    
    ierr = DMCreateMatrix(v, &mat); CHKERRQ(ierr);

    ierr = MatGetBlockSizes(mat, &rbs, &cbs); CHKERRQ(ierr);

    ierr = PetscPrintf(c, "Global Mat block size (%d, %d)\n", rbs, cbs); CHKERRQ(ierr);
    ierr = DMCompositeCreate(c, &pack); CHKERRQ(ierr);

    ierr = DMCompositeAddDM(pack, v); CHKERRQ(ierr);
    ierr = DMCompositeAddDM(pack, p); CHKERRQ(ierr);
    ierr = DMSetFromOptions(pack); CHKERRQ(ierr);

    ierr = DMCompositeGetLocalISs(pack, &ises); CHKERRQ(ierr);

    ierr = DMCreateMatrix(pack, &mat); CHKERRQ(ierr);

    ierr = MatGetBlockSizes(mat, &rbs, &cbs); CHKERRQ(ierr);

    ierr = PetscPrintf(c, "Global Mat block size (%d, %d)\n", rbs, cbs); CHKERRQ(ierr);
    ierr = MatGetLocalSubMatrix(mat, ises[0], ises[0], &submat); CHKERRQ(ierr);
    ierr = MatGetBlockSizes(submat, &srbs, &scbs); CHKERRQ(ierr);
    ierr = PetscPrintf(c, "Local Mat block size (%d, %d)\n", srbs, scbs); CHKERRQ(ierr);

    ierr = MatDestroy(&submat); CHKERRQ(ierr);
    ierr = MatDestroy(&mat); CHKERRQ(ierr);

    ierr = PetscSectionDestroy(&vsec); CHKERRQ(ierr);
    ierr = PetscSectionDestroy(&psec); CHKERRQ(ierr);

    ierr = DMDestroy(&pack); CHKERRQ(ierr);
    ierr = DMDestroy(&v); CHKERRQ(ierr);
    ierr = DMDestroy(&p); CHKERRQ(ierr);

    ierr = ISDestroy(&(ises[0])); CHKERRQ(ierr);
    ierr = ISDestroy(&(ises[1])); CHKERRQ(ierr);
    ierr = PetscFree(ises); CHKERRQ(ierr);

    PetscFinalize();

    return 0;
}


Cheers,

Lawrence
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20141219/066f13da/attachment.pgp>


More information about the petsc-users mailing list