<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On 19 August 2015 at 11:08, TAY wee-beng <span dir="ltr"><<a href="mailto:zonexo@gmail.com" target="_blank">zonexo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000"><div><div class="h5">
    <br>
    <div>On 19/8/2015 4:58 PM, Dave May wrote:<br>
    </div>
    <blockquote type="cite">
      <div dir="ltr"><br>
        <div class="gmail_extra"><br>
          <div class="gmail_quote">On 19 August 2015 at 10:54, TAY
            wee-beng <span dir="ltr"><<a href="mailto:zonexo@gmail.com" target="_blank">zonexo@gmail.com</a>></span>
            wrote:<br>
            <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
              <div bgcolor="#FFFFFF" text="#000000"><span> <br>
                  <div>On 21/7/2015 7:28 PM, Matthew Knepley wrote:<br>
                  </div>
                  <blockquote type="cite">
                    <div dir="ltr">
                      <div class="gmail_extra">
                        <div class="gmail_quote">On Tue, Jul 21, 2015 at
                          1:35 AM, TAY wee-beng <span dir="ltr"><<a href="mailto:zonexo@gmail.com" target="_blank">zonexo@gmail.com</a>></span>
                          wrote:<br>
                          <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
                            <br>
                            I need to check the contents of the array
                            which was declared using:<br>
                            <br>
                            PetscScalar,pointer ::
                            u_array(:,:,:),v_array(:,:,:),w_array(:,:,:),p_array(:,:,:)<br>
                            <br>
                            I tried to use :<br>
                            <br>
                            call
                            PetscViewerASCIIOpen(MPI_COMM_WORLD,"pres.txt",viewer,ierr)<br>
                            <br>
                            call VecView(p_array,viewer,ierr)<br>
                            <br>
                            or<br>
                            <br>
                            call MatView(p_array,viewer,ierr)<br>
                            <br>
                            call PetscViewerDestroy(viewer,ierr)<br>
                            <br>
                            but I got segmentation error. So is there a
                            PETSc routine I can use?</blockquote>
                          <div><br>
                          </div>
                          <div>No. Those routines work only for Vec
                            objects. You could</div>
                          <div><br>
                          </div>
                          <div> a) Declare a DMDA of the same size</div>
                          <div><br>
                          </div>
                          <div> b) Use DMDAVecGetArrayF90() to get out
                            the multidimensional array</div>
                          <div><br>
                          </div>
                          <div> c) Use that in your code</div>
                          <div><br>
                          </div>
                          <div> d) Use VecView() on the original vector</div>
                        </div>
                      </div>
                    </div>
                  </blockquote>
                  <br>
                </span> Hi,<br>
                <br>
                Supposed I need to check the contents of the u_array
                which was declared using:<span><br>
                  <br>
                  PetscScalar,pointer :: u_array(:,:,:)<br>
                  <br>
                </span> call
DMDACreate3d(MPI_COMM_WORLD,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DMDA_STENCIL_STAR,size_x,size_y,&<br>
                <br>
size_z,1,PETSC_DECIDE,PETSC_DECIDE,1,stencil_width,lx,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,da_u,ierr)<br>
                <br>
                call DMDAVecGetArrayF90(da_u,u_local,u_array,ierr)<br>
                <br>
                call
                PetscViewerASCIIOpen(MPI_COMM_WORLD,"u.txt",viewer,ierr)<br>
                        <br>
                call VecView(array,viewer,ierr)<br>
              </div>
            </blockquote>
            <div><br>
            </div>
            <div><br>
              The first argument of VecView must be of type Vec (as Matt
              noted).<br>
            </div>
            <div>It looks you are passing in an array of PetscScalar's.<br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br></div></div>
    Oh so should it be:<br>
    <br>
    Vec u_global,u_local<span class=""><br>
    <br>
    call
DMDACreate3d(MPI_COMM_WORLD,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DMDA_STENCIL_STAR,size_x,size_y,&<br>
    <br>
size_z,1,PETSC_DECIDE,PETSC_DECIDE,1,stencil_width,lx,PETSC_NULL_INTEGER,PETSC_NULL_INTEGER,da_u,ierr)<br>
    <br>
    call DMDAVecGetArrayF90(da_u,u_local,u_array,ierr)<br>
    <br>
    call PetscViewerASCIIOpen(MPI_COMM_WORLD,"u.txt",viewer,ierr)<br>
            <br></span>
    call VecView(u_local,viewer,ierr)<br>
    <br>
    call PetscViewerDestroy(viewer,ierr)</div></blockquote><div><br></div><div><br>Yes, the arguments types now match.<br><br>However, if you run this in parallel there will be two issues:<br></div><div><br>(1) You have a different local vector per process, thus you will need to use a unique file name, e.g. "u-rankXXX.txt" to avoid overwriting the data from each process<br><br></div><div>(2) You need to make sure that the communicator used for the viewer and the vector are the same.<br></div><div><br></div><div>To implement (1) and (2) you could do something like this:<br></div><div><br></div><div>MPI_Comm comm;<br></div><div>PetscMPIInt rank;<br></div><div>char filename[PETSC_MAX_PATH_LEN];<br></div><div><br></div><div>ierr = MPI_Comm_rank(PETSC_COMM_WORLD,&rank);CHKERRQ(ierr);<br></div><div>ierr = PetscSNPrintf(filename,PETSC_MAX_PATH_LEN-1,"u-%d.txt",rank);CHKERRQ(ierr);<br></div><div>ierr = PetscObjectGetComm(((PetscObject)u_local,&comm);CHKERRQ(ierr);<br></div><div>ierr = PetscViewerASCIIOpen(comm,filename,viewer);CHKERRQ(ierr);<br></div><div><br></div><div><br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div bgcolor="#FFFFFF" text="#000000"><span class=""><br>
    <blockquote type="cite">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <div><br>
               </div>
            <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
              <div bgcolor="#FFFFFF" text="#000000"> <br>
                call PetscViewerDestroy(viewer,ierr)<br>
                <br>
                Is this the correct way?<span><br>
                  <blockquote type="cite">
                    <div dir="ltr">
                      <div class="gmail_extra">
                        <div class="gmail_quote">
                          <div><br>
                          </div>
                          <div>   Matt</div>
                          <div> </div>
                          <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><font color="#888888"><br>
                                -- <br>
                                Thank you<br>
                                <br>
                                Yours sincerely,<br>
                                <br>
                                TAY wee-beng<br>
                                <br>
                              </font></span></blockquote>
                        </div>
                        <br>
                        <br clear="all">
                        <div><br>
                        </div>
                        -- <br>
                        <div>What most experimenters take for granted
                          before they begin their experiments is
                          infinitely more interesting than any results
                          to which their experiments lead.<br>
                          -- Norbert Wiener</div>
                      </div>
                    </div>
                  </blockquote>
                  <br>
                </span></div>
            </blockquote>
          </div>
          <br>
        </div>
      </div>
    </blockquote>
    <br>
  </span></div>

</blockquote></div><br></div></div>