I still have some problem with the output by using VecView(). I read its source code but still confusing. <br>1) Does it just execute in 0 rank process after a MPI reduce or it execute in every process;<br>
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;<br>
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.<br>
<br>thanks in advance, ^_^<br>Alan <br><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div class="h5"><br>
<div class="gmail_quote">On Fri, Jun 10, 2011 at 5:03 PM, Alan Wei <span dir="ltr"><<a href="mailto:zhenglun.wei@gmail.com" target="_blank">zhenglun.wei@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
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. <br><br>sincerely,<br>Alan<div>
<div></div><div><br>
<br><div class="gmail_quote">On Fri, Jun 10, 2011 at 4:57 PM, Matthew Knepley <span dir="ltr"><<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div>On Fri, Jun 10, 2011 at 4:54 PM, Alan Wei <span dir="ltr"><<a href="mailto:zhenglun.wei@gmail.com" target="_blank">zhenglun.wei@gmail.com</a>></span> wrote:<br></div><div class="gmail_quote"><div>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
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. >_<</blockquote>
<div><br></div></div><div>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.</div><div><div></div><div><div><br></div><div> Matt</div><div>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<font color="#888888"><br>Alan</font><div><div></div><div><br><br><div class="gmail_quote">On Fri, Jun 10, 2011 at 4:44 PM, Matthew Knepley <span dir="ltr"><<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div>On Fri, Jun 10, 2011 at 4:40 PM, Alan Wei <span dir="ltr"><<a href="mailto:zhenglun.wei@gmail.com" target="_blank">zhenglun.wei@gmail.com</a>></span> wrote:<br></div><div class="gmail_quote"><div>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
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. <br></blockquote><div><br></div></div><div>
Without the DMView(), the VTK file will not be valid.</div>
<div><br></div><div> Matt</div><div><div></div><div><div> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">^_^ thank you so much, again.<br>
<font color="#888888">Alan</font><div><div>
</div><div><br>
<br><div class="gmail_quote">On Fri, Jun 10, 2011 at 4:26 PM, Matthew Knepley <span dir="ltr"><<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div>On Fri, Jun 10, 2011 at 4:18 PM, Alan Wei <span dir="ltr"><<a href="mailto:zhenglun.wei@gmail.com" target="_blank">zhenglun.wei@gmail.com</a>></span> wrote:<br></div><div class="gmail_quote"><div>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Here is my code right now, and the error message is attached. ^_^<div><br><br>PetscErrorCode VecView_VTK(Vec x, const char filename[], const char bcName[])<br>{<br><br> MPI_Comm comm;<br> DM da;<br>
Vec coords;<br>
PetscViewer viewer;<br> PetscScalar *array, *values;<br> PetscInt n, N, maxn, mx, my, dof;<br> PetscInt i, p;<br> MPI_Status status;<br> PetscMPIInt rank, size, tag, nn;<br>
PetscErrorCode ierr;<br><br> PetscFunctionBegin;<br> PetscViewerASCIIOpen(PETSC_COMM_WORLD, filename, &viewer);<br></div></blockquote><div><br></div></div><div>ALWAYS check the return values:</div><div><br></div>
<div>
ierr = PetscVIewerASCIIOpen(PETSC_COMM_WORLD, filename, &viewer);CHKERRQ(ierr);</div><div><br></div><div>Do this for all the function calls.</div><div><div> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div></div> PetscViewerSetFormat(viewer, PETSC_VIEWER_ASCII_VTK);<br> DMView(x, viewer);<br></blockquote><div><br></div></div><div>The first argument here is a Vec, x, not the DM. Pass in the DM as well.</div><div>
<br></div><div> Matt</div><div><div></div><div><div> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"> VecView(x, viewer);<br>
PetscViewerDestroy(&viewer);<br> PetscFunctionReturn(0);<br>}<br><br>thanks a lot,<br><font color="#888888">Alan</font><div><div></div><div><br><div class="gmail_quote">On Fri, Jun 10, 2011 at 4:03 PM, Matthew Knepley <span dir="ltr"><<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div>On Fri, Jun 10, 2011 at 3:47 PM, Alan Wei <span dir="ltr"><<a href="mailto:zhenglun.wei@gmail.com" target="_blank">zhenglun.wei@gmail.com</a>></span> wrote:<br>
</div><div class="gmail_quote"><div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Thanks, Matt. You're brilliant. <br> I re-write it and the subroutine is like this. It indeed works. However, there are two questions. <br><br>PetscErrorCode VecView_VTK(Vec x, const char filename[], const char bcName[])<br>
{<br><br> MPI_Comm comm;<br> DM da;<br> Vec coords;<br> PetscViewer viewer;<br> PetscScalar *array, *values;<br> PetscInt n, N, maxn, mx, my, dof;<br>
PetscInt i, p;<br>
MPI_Status status;<br> PetscMPIInt rank, size, tag, nn;<br> PetscErrorCode ierr;<br><br> PetscFunctionBegin;<br> PetscViewerASCIIOpen(PETSC_COMM_WORLD, filename, &viewer);<div><br>
PetscViewerSetFormat(viewer, PETSC_VIEWER_ASCII_MATLAB);<br></div></blockquote><div><br></div></div><div>This still reads ASCII_MATLAB. It should be ASCII_VTK. I put that in my last email.</div><div><div> </div>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div></div>
DMView(x, viewer);<br> VecView(x, PETSC_VIEWER_STDOUT_SELF);<br></blockquote><div><br></div></div><div>This should be 'viewer', not PETSC_VIEWER_STDOUT_SELF.</div><div><div> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
PetscViewerDestroy(&viewer);<br> PetscFunctionReturn(0);<br>}<br><br>1) It does plot out the matrix to the console, but it does not create the file and write it to the file;<br></blockquote><div><br></div></div><div>
There is nothing to do with any matrix in this function, only a vector. The vector is written to the</div>
<div>console because the argument is wrong above.</div><div><div> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
2) everytime I execute it, it pop up a error message at the end of the computation, as I attached here.<br> Could you please help me about these. ^_^<br></blockquote><div><br></div></div><div>Its taking forever to download this message (3M) so I cannot see the error right now.</div>
<div><br></div><div> Matt</div><div><div></div><div><div> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">thanks in advance,<br>
<font color="#888888">Alan</font><div><div></div><div>
<br><div class="gmail_quote">On Fri, Jun 10, 2011 at 3:23 PM, Matthew Knepley <span dir="ltr"><<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div>On Fri, Jun 10, 2011 at 3:16 PM, Alan Wei <span dir="ltr"><<a href="mailto:zhenglun.wei@gmail.com" target="_blank">zhenglun.wei@gmail.com</a>></span> wrote:<br>
</div><div class="gmail_quote"><div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
ooops, sorry, here it is.<br></blockquote><div> </div></div><div>You did not pass a valid communicator to PetscVIewerASCIIOpen(). Use PETSC_COMM_WORLD.</div><div><br></div><div> Matt</div><div><div></div><div>
<div> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
^_^<br><font color="#888888"><br>Alan</font><div><div></div><div><br><br><div class="gmail_quote">On Fri, Jun 10, 2011 at 3:09 PM, Matthew Knepley <span dir="ltr"><<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div>On Fri, Jun 10, 2011 at 3:05 PM, <span dir="ltr"><<a href="mailto:zhenglun.wei@gmail.com" target="_blank">zhenglun.wei@gmail.com</a>></span> wrote:<br>
</div><div class="gmail_quote"><div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Dear Matt,<br> Following your suggestions, I modified the VecView_VTK in /src/ksp/ksp/example/tutorial/ex29.c to <br><br> PetscFunctionBegin;<br> PetscViewerASCIIOpen(comm, filename, &viewer);<br> PetscViewerSetFormat(viewer, PETSC_VIEWER_ASCII_MATLAB);<br>
</blockquote><div><br></div></div><div>I told you to use ASCII_VTK, not ASCII_MATLAB.</div><div><div> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
DMView(x, viewer);<br>
VecView(x, PETSC_VIEWER_STDOUT_WORLD);<br> PetscViewerDestroy(&viewer);<br> PetscFunctionReturn(0);<br><br> However, I always give me some error. Could you please briefly check if there is any obvious coding problem here.<br>
</blockquote><div><br></div></div><div>How can I possibly know what went wrong if you do not send the ENTIRE error message.</div><div><br></div><div> Matt</div><div><div></div><div><div> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
thanks,<br>Alan<div><br><br>On , Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>> wrote:<br>> On Thu, Jun 9, 2011 at 6:18 PM, Matthew Knepley <a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>> wrote:<br>
> <br>> On Thu, Jun 9, 2011 at 6:01 PM, <a href="mailto:zhenglun.wei@gmail.com" target="_blank">zhenglun.wei@gmail.com</a>> wrote:<br>> <br>> <br>> Dear Sir/Madam,<br>> 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. <br>
> <br>> <br>> <br>> <br>> Here is a better answer. If you want output, throw away this old function which is broken, and use<br>> <br>> <br>> PetscViewerASCIIOpen()<br>> PetscViewerASCIISetFormat(PETSC_VIEWER_ASCII_VTK)<br>
> <br>> DMView()<br>> VecView()<br>> PetscViewerDestroy()<br>> <br>> <br>> Thanks,<br>> <br>> <br>> Matt<br>> <br>> <br>> 1) My first questions is that what does this section do in VecView_VTK:<br>
> <br>> 272: MPI_Comm_rank(comm, &rank);<br>> <br>> 273: MPI_Comm_size(comm, &size);<br>> 274: MPI_Reduce(&n, &maxn, 1, MPIU_INT, MPI_MAX, 0, comm);<br>> <br>> 275: tag = ((PetscObject) viewer)->tag;<br>
> 276: if (!rank) {<br>> 277: PetscMalloc((maxn+1) * sizeof(PetscScalar), &values);<br></div>> 278: for(i = 0; i 279: PetscViewerASCIIPrintf(viewer, "%G\n", PetscRealPart(array[i]));<br>
> <br>> <br>> 280: }<br>> 281: for(p = 1; p 282: MPI_Recv(values, (PetscMPIInt) n, MPIU_SCALAR, p, tag, comm, &status);<div><br>> 283: MPI_Get_count(&status, MPIU_SCALAR, &nn);<br>
> 284: for(i = 0; i <br>> <br></div><div><div></div><div>> 285: PetscViewerASCIIPrintf(viewer, "%G\n", PetscRealPart(array[i]));<br>> 286: }<br>> 287: }<br>> 288: PetscFree(values);<br>
> 289: } else {<br>> 290: MPI_Send(array, n, MPIU_SCALAR, 0, tag, comm);<br>> <br>> <br>> 291: }<br>> <br>> 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. <br>
> <br>> <br>> <br>> 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:<br>> <br>> <br>> The DMDA describes the domain splitting.<br>
> <br>> <br>> <br>> <br>> Matt<br>> <br>> a) <br>> |<br>> 0 | 1 <br>> |<br>> <br>> <br>> ---------------|--------------<br>> | <br>
> 2 | 3<br>> |<br>> <br>> b) <br>> |<br>> 0 | 2 <br>> |<br>> ---------------|--------------<br>> | <br>
> <br>> <br>> 1 | 3<br>> |<br>> <br>> c) <br>> | | | |<br>> | | | |<br>> 0 | | 2 | |<br>> | 1 | | 3 |<br>
> | | | |<br>> | | | |<br>> <br>> <br>> <br>> d)<br>> 0<br>> ------------------------<br>> 1<br>> ------------------------<br>> 2<br>
> ------------------------<br>> 3<br>> <br>> thanks in advance,<br>> Alan<br>> <br>> <br>> <br>> <br>> -- <br>> 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<br>> <br>> <br>> <br>> <br>> -- <br>> 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<br>></div></div></blockquote></div></div></div><div><div></div><div><br><br clear="all"><br>-- <br>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<br>
</div></div></blockquote></div><br>
</div></div></blockquote></div></div></div><div><div></div><div><br><br clear="all"><br>-- <br>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<br>
</div></div></blockquote></div><br>
</div></div></blockquote></div></div></div><div><div></div><div><br><br clear="all"><br>-- <br>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<br>
</div></div></blockquote></div><br>
</div></div></blockquote></div></div></div><div><div></div><div><br><br clear="all"><br>-- <br>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<br>
</div></div></blockquote></div><br>
</div></div></blockquote></div></div></div><div><div></div><div><br><br clear="all"><br>-- <br>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<br>
</div></div></blockquote></div><br>
</div></div></blockquote></div></div></div><div><div></div><div><br><br clear="all"><br>-- <br>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<br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>