[petsc-users] Output question for ex29.
Alan Wei
zhenglun.wei at gmail.com
Thu Jun 16 16:49:24 CDT 2011
I still have some problem with the output by using VecView(). I read its
source code but still confusing.
1) Does it just execute in 0 rank process after a MPI reduce or it execute
in every process;
2) for every execution of VecView, does it loop 'i' first or 'j' first if it
is x[j][i] in VecView(x,viewer). There is a minor question here. If VecView
does do loop, is it generally faster than that I do loop by for() command
manually ^_^ I believe it is, but I want to confirm it;
3) the VTK file output by VecView is a single column file with some header
content in the beginning. I want a 2 column file with, say MPI rank number
as the first column, can I do that? Could you please suggest a function to
call or I need to loop it by myself.
thanks in advance, ^_^
Alan
> On Fri, Jun 10, 2011 at 5:03 PM, Alan Wei <zhenglun.wei at gmail.com> wrote:
>
>> Oh, I got it. Indeed I found the original subroutine has the coordinate.
>> However, I may not need it since I want to plot it to a software named:
>> Tecplot. It needs data only. Thanks a lot, Matt.
>>
>> sincerely,
>> Alan
>>
>>
>> On Fri, Jun 10, 2011 at 4:57 PM, Matthew Knepley <knepley at gmail.com>wrote:
>>
>>> On Fri, Jun 10, 2011 at 4:54 PM, Alan Wei <zhenglun.wei at gmail.com>wrote:
>>>
>>>> oh, really. what do you meant 'valid'? it is created and data is inside.
>>>> If I have to use it, what should I do for this function? actually, I do not
>>>> have any thing in 'DM' format other than the 'da'. However, the 'da' does
>>>> not contain anything. >_<
>>>
>>>
>>> A VTK file must have a mesh in it. If you have not used VTK before, I do
>>> not think you should start with this function.
>>>
>>> Matt
>>>
>>>
>>>>
>>>> Alan
>>>>
>>>>
>>>> On Fri, Jun 10, 2011 at 4:44 PM, Matthew Knepley <knepley at gmail.com>wrote:
>>>>
>>>>> On Fri, Jun 10, 2011 at 4:40 PM, Alan Wei <zhenglun.wei at gmail.com>wrote:
>>>>>
>>>>>> Thanks, Matt. I appreciate a lot for your help. I just delete 'DMView'
>>>>>> part since I do not need to see the plot of 'dm'. Right now it really plot
>>>>>> out everything.
>>>>>>
>>>>>
>>>>> Without the DMView(), the VTK file will not be valid.
>>>>>
>>>>> Matt
>>>>>
>>>>>
>>>>>> ^_^ thank you so much, again.
>>>>>> Alan
>>>>>>
>>>>>>
>>>>>> On Fri, Jun 10, 2011 at 4:26 PM, Matthew Knepley <knepley at gmail.com>wrote:
>>>>>>
>>>>>>> On Fri, Jun 10, 2011 at 4:18 PM, Alan Wei <zhenglun.wei at gmail.com>wrote:
>>>>>>>
>>>>>>>> Here is my code right now, and the error message is attached. ^_^
>>>>>>>>
>>>>>>>>
>>>>>>>> PetscErrorCode VecView_VTK(Vec x, const char filename[], const char
>>>>>>>> bcName[])
>>>>>>>> {
>>>>>>>>
>>>>>>>> MPI_Comm comm;
>>>>>>>> DM da;
>>>>>>>> Vec coords;
>>>>>>>> PetscViewer viewer;
>>>>>>>> PetscScalar *array, *values;
>>>>>>>> PetscInt n, N, maxn, mx, my, dof;
>>>>>>>> PetscInt i, p;
>>>>>>>> MPI_Status status;
>>>>>>>> PetscMPIInt rank, size, tag, nn;
>>>>>>>> PetscErrorCode ierr;
>>>>>>>>
>>>>>>>> PetscFunctionBegin;
>>>>>>>> PetscViewerASCIIOpen(PETSC_COMM_WORLD, filename, &viewer);
>>>>>>>>
>>>>>>>
>>>>>>> ALWAYS check the return values:
>>>>>>>
>>>>>>> ierr = PetscVIewerASCIIOpen(PETSC_COMM_WORLD, filename,
>>>>>>> &viewer);CHKERRQ(ierr);
>>>>>>>
>>>>>>> Do this for all the function calls.
>>>>>>>
>>>>>>>
>>>>>>>> PetscViewerSetFormat(viewer, PETSC_VIEWER_ASCII_VTK);
>>>>>>>> DMView(x, viewer);
>>>>>>>>
>>>>>>>
>>>>>>> The first argument here is a Vec, x, not the DM. Pass in the DM as
>>>>>>> well.
>>>>>>>
>>>>>>> Matt
>>>>>>>
>>>>>>>
>>>>>>>> VecView(x, viewer);
>>>>>>>> PetscViewerDestroy(&viewer);
>>>>>>>> PetscFunctionReturn(0);
>>>>>>>> }
>>>>>>>>
>>>>>>>> thanks a lot,
>>>>>>>> Alan
>>>>>>>>
>>>>>>>> On Fri, Jun 10, 2011 at 4:03 PM, Matthew Knepley <knepley at gmail.com
>>>>>>>> > wrote:
>>>>>>>>
>>>>>>>>> On Fri, Jun 10, 2011 at 3:47 PM, Alan Wei <zhenglun.wei at gmail.com>wrote:
>>>>>>>>>
>>>>>>>>>> Thanks, Matt. You're brilliant.
>>>>>>>>>> I re-write it and the subroutine is like this. It indeed works.
>>>>>>>>>> However, there are two questions.
>>>>>>>>>>
>>>>>>>>>> PetscErrorCode VecView_VTK(Vec x, const char filename[], const
>>>>>>>>>> char bcName[])
>>>>>>>>>> {
>>>>>>>>>>
>>>>>>>>>> MPI_Comm comm;
>>>>>>>>>> DM da;
>>>>>>>>>> Vec coords;
>>>>>>>>>> PetscViewer viewer;
>>>>>>>>>> PetscScalar *array, *values;
>>>>>>>>>> PetscInt n, N, maxn, mx, my, dof;
>>>>>>>>>> PetscInt i, p;
>>>>>>>>>> MPI_Status status;
>>>>>>>>>> PetscMPIInt rank, size, tag, nn;
>>>>>>>>>> PetscErrorCode ierr;
>>>>>>>>>>
>>>>>>>>>> PetscFunctionBegin;
>>>>>>>>>> PetscViewerASCIIOpen(PETSC_COMM_WORLD, filename, &viewer);
>>>>>>>>>>
>>>>>>>>>> PetscViewerSetFormat(viewer, PETSC_VIEWER_ASCII_MATLAB);
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> This still reads ASCII_MATLAB. It should be ASCII_VTK. I put that
>>>>>>>>> in my last email.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>> DMView(x, viewer);
>>>>>>>>>> VecView(x, PETSC_VIEWER_STDOUT_SELF);
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> This should be 'viewer', not PETSC_VIEWER_STDOUT_SELF.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>> PetscViewerDestroy(&viewer);
>>>>>>>>>> PetscFunctionReturn(0);
>>>>>>>>>> }
>>>>>>>>>>
>>>>>>>>>> 1) It does plot out the matrix to the console, but it does not
>>>>>>>>>> create the file and write it to the file;
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> There is nothing to do with any matrix in this function, only a
>>>>>>>>> vector. The vector is written to the
>>>>>>>>> console because the argument is wrong above.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>> 2) everytime I execute it, it pop up a error message at the end of
>>>>>>>>>> the computation, as I attached here.
>>>>>>>>>> Could you please help me about these. ^_^
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Its taking forever to download this message (3M) so I cannot see
>>>>>>>>> the error right now.
>>>>>>>>>
>>>>>>>>> Matt
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>> thanks in advance,
>>>>>>>>>> Alan
>>>>>>>>>>
>>>>>>>>>> On Fri, Jun 10, 2011 at 3:23 PM, Matthew Knepley <
>>>>>>>>>> knepley at gmail.com> wrote:
>>>>>>>>>>
>>>>>>>>>>> On Fri, Jun 10, 2011 at 3:16 PM, Alan Wei <
>>>>>>>>>>> zhenglun.wei at gmail.com> wrote:
>>>>>>>>>>>
>>>>>>>>>>>> ooops, sorry, here it is.
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> You did not pass a valid communicator to PetscVIewerASCIIOpen().
>>>>>>>>>>> Use PETSC_COMM_WORLD.
>>>>>>>>>>>
>>>>>>>>>>> Matt
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>> ^_^
>>>>>>>>>>>>
>>>>>>>>>>>> Alan
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On Fri, Jun 10, 2011 at 3:09 PM, Matthew Knepley <
>>>>>>>>>>>> knepley at gmail.com> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>>> On Fri, Jun 10, 2011 at 3:05 PM, <zhenglun.wei at gmail.com>wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>>> Dear Matt,
>>>>>>>>>>>>>> Following your suggestions, I modified the VecView_VTK in
>>>>>>>>>>>>>> /src/ksp/ksp/example/tutorial/ex29.c to
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> PetscFunctionBegin;
>>>>>>>>>>>>>> PetscViewerASCIIOpen(comm, filename, &viewer);
>>>>>>>>>>>>>> PetscViewerSetFormat(viewer, PETSC_VIEWER_ASCII_MATLAB);
>>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> I told you to use ASCII_VTK, not ASCII_MATLAB.
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>> DMView(x, viewer);
>>>>>>>>>>>>>> VecView(x, PETSC_VIEWER_STDOUT_WORLD);
>>>>>>>>>>>>>> PetscViewerDestroy(&viewer);
>>>>>>>>>>>>>> PetscFunctionReturn(0);
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> However, I always give me some error. Could you please briefly
>>>>>>>>>>>>>> check if there is any obvious coding problem here.
>>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> How can I possibly know what went wrong if you do not send the
>>>>>>>>>>>>> ENTIRE error message.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Matt
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>> thanks,
>>>>>>>>>>>>>> Alan
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On , Matthew Knepley <knepley at gmail.com> wrote:
>>>>>>>>>>>>>> > On Thu, Jun 9, 2011 at 6:18 PM, Matthew Knepley
>>>>>>>>>>>>>> knepley at gmail.com> wrote:
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > On Thu, Jun 9, 2011 at 6:01 PM, zhenglun.wei at gmail.com>
>>>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > Dear Sir/Madam,
>>>>>>>>>>>>>> > I'm still studying on the ex29 of
>>>>>>>>>>>>>> /src/ksp/ksp/example/tutorial. Before I met a problem on VecView_VTK in
>>>>>>>>>>>>>> parallel computation. I'm trying to modify it in order to output some data
>>>>>>>>>>>>>> from the computation.
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > Here is a better answer. If you want output, throw away this
>>>>>>>>>>>>>> old function which is broken, and use
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > PetscViewerASCIIOpen()
>>>>>>>>>>>>>> > PetscViewerASCIISetFormat(PETSC_VIEWER_ASCII_VTK)
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > DMView()
>>>>>>>>>>>>>> > VecView()
>>>>>>>>>>>>>> > PetscViewerDestroy()
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > Thanks,
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > Matt
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > 1) My first questions is that what does this section do in
>>>>>>>>>>>>>> VecView_VTK:
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > 272: MPI_Comm_rank(comm, &rank);
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > 273: MPI_Comm_size(comm, &size);
>>>>>>>>>>>>>> > 274: MPI_Reduce(&n, &maxn, 1, MPIU_INT, MPI_MAX, 0, comm);
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > 275: tag = ((PetscObject) viewer)->tag;
>>>>>>>>>>>>>> > 276: if (!rank) {
>>>>>>>>>>>>>> > 277: PetscMalloc((maxn+1) * sizeof(PetscScalar), &values);
>>>>>>>>>>>>>> > 278: for(i = 0; i 279: PetscViewerASCIIPrintf(viewer,
>>>>>>>>>>>>>> "%G\n", PetscRealPart(array[i]));
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > 280: }
>>>>>>>>>>>>>> > 281: for(p = 1; p 282: MPI_Recv(values, (PetscMPIInt) n,
>>>>>>>>>>>>>> MPIU_SCALAR, p, tag, comm, &status);
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> > 283: MPI_Get_count(&status, MPIU_SCALAR, &nn);
>>>>>>>>>>>>>> > 284: for(i = 0; i
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > 285: PetscViewerASCIIPrintf(viewer, "%G\n",
>>>>>>>>>>>>>> PetscRealPart(array[i]));
>>>>>>>>>>>>>> > 286: }
>>>>>>>>>>>>>> > 287: }
>>>>>>>>>>>>>> > 288: PetscFree(values);
>>>>>>>>>>>>>> > 289: } else {
>>>>>>>>>>>>>> > 290: MPI_Send(array, n, MPIU_SCALAR, 0, tag, comm);
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > 291: }
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > What I understand is: it gather all the data from different
>>>>>>>>>>>>>> process in parallel computation, and output it to the 'viewer'. I comment
>>>>>>>>>>>>>> out everything in VecView_VTK except this part, there is no error message
>>>>>>>>>>>>>> coming up in my parallel computation so far.
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > 2) however, I really don't know how did it split the domain
>>>>>>>>>>>>>> for parallel computation. For example, if I use 4 processes, is the domain
>>>>>>>>>>>>>> split like:
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > The DMDA describes the domain splitting.
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > Matt
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > a)
>>>>>>>>>>>>>> > |
>>>>>>>>>>>>>> > 0 | 1
>>>>>>>>>>>>>> > |
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > ---------------|--------------
>>>>>>>>>>>>>> > |
>>>>>>>>>>>>>> > 2 | 3
>>>>>>>>>>>>>> > |
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > b)
>>>>>>>>>>>>>> > |
>>>>>>>>>>>>>> > 0 | 2
>>>>>>>>>>>>>> > |
>>>>>>>>>>>>>> > ---------------|--------------
>>>>>>>>>>>>>> > |
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > 1 | 3
>>>>>>>>>>>>>> > |
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > c)
>>>>>>>>>>>>>> > | | | |
>>>>>>>>>>>>>> > | | | |
>>>>>>>>>>>>>> > 0 | | 2 | |
>>>>>>>>>>>>>> > | 1 | | 3 |
>>>>>>>>>>>>>> > | | | |
>>>>>>>>>>>>>> > | | | |
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > d)
>>>>>>>>>>>>>> > 0
>>>>>>>>>>>>>> > ------------------------
>>>>>>>>>>>>>> > 1
>>>>>>>>>>>>>> > ------------------------
>>>>>>>>>>>>>> > 2
>>>>>>>>>>>>>> > ------------------------
>>>>>>>>>>>>>> > 3
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > thanks in advance,
>>>>>>>>>>>>>> > Alan
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > --
>>>>>>>>>>>>>> > 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
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>> > --
>>>>>>>>>>>>>> > 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
>>>>>>>>>>>>>> >
>>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> --
>>>>>>>>>>>>> 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
>>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>> 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
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> 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
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> 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
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> 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
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> 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
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110616/b0a62af3/attachment-0001.htm>
More information about the petsc-users
mailing list