[petsc-users] Some Problems in Modifying Parallel Programs

Matthew Knepley knepley at gmail.com
Mon Oct 15 09:52:39 CDT 2018


On Mon, Oct 15, 2018 at 10:42 AM Yingjie Wu <yjwu16 at gmail.com> wrote:

> Dear Petsc developer:
> Hi,
> Thank you very much for your previous reply.
> I recently wanted to modify my program to parallel version, and
> encountered some problems in modifying it.
> 1. There are functions (read matrix) in the program that reads files,will
> they affect my parallelism?
>

No, MatLoad works in parallel. This will work unchanged if you want the
default layout. If you want a special partition,
you must call MatSetSizes() after MatCreate().


> The codes are as follows:
>
> ierr = PetscViewerBinaryOpen (PETSC_COMM_WORLD, file, FILE_MODE_READ,
> &viewer); CHKERRQ (ierr);
> ierr = MatCreate (PETSC_COMM_WORLD, &A1); CHKERRQ (ierr);
> ierr = MatSetFromOptions (A1); CHKERRQ (ierr);
> ierr = MatCreate (PETSC_COMM_WORLD, &A2); CHKERRQ (ierr);
> ierr = MatSetFromOptions (A2); CHKERRQ (ierr);
> ierr = MatLoad (A1, viewer); CHKERRQ (ierr);
> ierr = MatLoad (A2, viewer); CHKERRQ (ierr);
> ierr = PetscViewerDestroy (&viewer); CHKERRQ (ierr);
>
> I read two matrix information from a binary file and wanted to use it on
> each processor (in fact, my goal was to use these two matrices to give
> initial values to the two field variables). The program can run in serial
> time. Now I want to change it to parallel program. What do I need to
> modify?
> 2. Following the last question, I used the following code in giving
> initial value procedure FormInitialGuess():
>
> ierr = MatSeqAIJGetArray (A1, &initial_phi1); CHKERRQ (ierr);
> ierr = MatSeqAIJGetArray (A2, &initial_phi2); CHKERRQ (ierr);
>
> I found this function on manualpages, and I felt that it could fulfill my
> need to represent the elements of the matrix in arrays to give field
> variables an initial value in each grid. The matrix A1 and A2 above are
> actually the matrix information that was read from the file before. Now I
> want to modify it as a parallel program. How do I use matrix information to
> give initial values in parallel? (In program, field variables are
> implemented through DM because parallel computing and Ghost Value are
> supported)
>

I do not understand the use of matrices to initialize field values. Usually
field values are stored on Vec objects, and this is
the philosophy of DM objects.

  Thanks,

     Matt


> Thanks,
> Yingjie
>


-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20181015/d4e8af13/attachment-0001.html>


More information about the petsc-users mailing list