[petsc-users] Read in sequential, solve in parallel

Jed Brown jed at 59A2.org
Wed Sep 29 05:18:13 CDT 2010


On Wed, Sep 29, 2010 at 11:46, Moinier, Pierre (UK)
<Pierre.Moinier at baesystems.com> wrote:
> I have a Matrix and a Right Hand Side (RHS) in an ASCII format stored in 2
> different files. I have written the code that reads the data and solve the
> system in sequential. I would like to solve the same problem in parallel. I
> read the FAQ section that says:
>
> Never read or write in parallel an ASCII matrix file, instead for reading:
> read in sequentially then save the matrix with the binary viewer
> PetscBinaryViewerOpen() and load the matrix in parallel with MatLoad().
>
> So far, I did not manage to implement this. Could any one help me?

With your matrix assembled in serial:

    ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,"A.dat",FILE_MODE_WRITE,&viewer);CHKERRQ(ierr);
    ierr = MatView(A,viewer);CHKERRQ(ierr);
    ierr = PetscViewerDestroy(viewer);CHKERRQ(ierr);

In parallel:

    ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,"A.dat",FILE_MODE_READ,&viewer);CHKERRQ(ierr);
    ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr);
    ierr = MatLoad(A,viewer);CHKERRQ(ierr);
    ierr = PetscViewerDestroy(viewer);CHKERRQ(ierr);
    ierr = KSPSetOperators(ksp,A,A,DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr);


Jed


More information about the petsc-users mailing list