Hey Vijay,<br> I can spot something wrong. VecGetSize gives you the global length of the vector. However VecGetArray only gives you access to the LOCAL portion of the vector data for that processor. Thus you need to use a local index if you are going to set the values directly into the array.
<br><br>In parallel, xx[n-1] will always be outside the bounds of the processors local portion of the vector if n is the global vector length.<br><br>Cheers,<br> Dave.<br><br><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Here's the function.<br><br>PetscErrorCode FormFunction(SNES snes,Vec x,Vec f,void *ctx)<br>{<br> PetscScalar *xx,*ff,d;<br> PetscErrorCode ierr;<br> PetscInt i,n;<br><br> PetscFunctionBegin;<br> ierr = VecGetArray(x,&xx);CHKERRQ(ierr);
<br> ierr = VecGetArray(f,&ff);CHKERRQ(ierr);<br> ierr = VecGetSize(x,&n);CHKERRQ(ierr);<br><br> double h = 1.0/(n-1) ;<br> d = (PetscReal)(n - 1); d = d*d;<br> double pos ;<br><br> ff[0] = xx[0]; // left boundary with Dirichlet = 0
<br> // residual : (un-1 -2*un + un+1)/h^2 + Reaction*u - f<br> for (i=1; i<n-1; i++) {<br> pos = i*h ;<br> ff[i] = -Diffusion(pos, 0, 0, 0, xx[i])*d*(xx[i-1] - 2.0*xx[i] +<br>xx[i+1]) + Reaction(pos, 0, 0, 0, xx[i])*xx[i] - RHS(pos, 0, 0, 0,
<br>xx[i]) ;<br> }<br> ff[n-1] = xx[n-1] - 1.0; // right boundary with Dirichlet = 1<br><br> ierr = VecRestoreArray(x,&xx);CHKERRQ(ierr);<br> ierr = VecRestoreArray(f,&ff);CHKERRQ(ierr);<br> PetscFunctionReturn(0);
<br>}<br><br>One question though. If i use GetArray and RestoreArray to change the<br>values directly in memory, do i still have to make the<br>VecAssemblyBegin-End calls ?<br><br>Thanks again for the help Matt.<br><font color="#888888">
<br>Vijay<br></font><div><div></div><div class="Wj3C7c"><br>On Jan 22, 2008 5:02 PM, Matthew Knepley <<a href="mailto:knepley@gmail.com">knepley@gmail.com</a>> wrote:<br>> On Jan 22, 2008 3:54 PM, Vijay M <<a href="mailto:vijay.m@gmail.com">
vijay.m@gmail.com</a>> wrote:<br>> > Hi all,<br>> ><br>> > I am currently trying to use LibMesh with PETSc SNES solver to solve a<br>> > nonlinear Diffusion-reaction problem. The code works fine with 1
<br>> > processor but when i use 2 processors for the exact same problem, it<br>> > throws me this error regarding memory corruption. I am not sure what<br>> > this error is about and was wondering if someone can help me out on
<br>> > this. Note: My residual function is being called successfully and<br>> > returns the residual back without any problem since i can see some<br>> > print message at the end of the call ! Hence, this problem is not in
<br>> > my custom FormFunction.<br>><br>> Actually, it is very likely that the problem is in your FormFunction. The<br>> error is being reported because after every call to FormFunction, we<br>> walk the PETSc heap and validate all the pieces of memory we allocated.
<br>> Something wrote over a piece of memory we already own, so the OS<br>> did not complain and you saw your printout, however there is still corruption.<br>> I would advise you to run 'valgrind' on the code. It is the best tool I have
<br>> used for finding these kind of errors.<br>><br>> Matt<br>><br>><br>> > [1]PETSC ERROR: PetscMallocValidate: error detected at<br>> > SNESComputeFunction() line 950 in src/snes/interface/snes.c
<br>> > [1]PETSC ERROR: Memory at address 0xa5cf40 is corrupted<br>> > [1]PETSC ERROR: Probably write past beginning or end of array<br>> > [1]PETSC ERROR: Last intact block allocated in PetscStrallocpy() line
<br>> > 82 in src/sys/utils/str.c<br>> > [0]PETSC ERROR: PetscMallocValidate: error detected at<br>> > SNESComputeFunction() line 950 in src/snes/interface/snes.c<br>> > [0]PETSC ERROR: Memory at address 0xa5cf30 is corrupted
<br>> > [0]PETSC ERROR: Probably write past beginning or end of array<br>> > [0]PETSC ERROR: Last intact block allocated in PetscStrallocpy() line<br>> > 82 in src/sys/utils/str.c<br>> > [0]PETSC ERROR: --------------------- Error Message
<br>> > ------------------------------------<br>> > [0]PETSC ERROR: Memory corruption!<br>> > [0]PETSC ERROR: !<br>> > [0]PETSC ERROR:<br>> > ------------------------------------------------------------------------
<br>> > [0]PETSC ERROR: Petsc Release Version 2.3.3, Patch 7, Fri Oct 26<br>> > 14:21:35 CDT 2007 HG revision:<br>> > 2e223033ba960114833e1f9713ab393ec78c056f<br>> > [0]PETSC ERROR: See docs/changes/index.html for recent updates.
<br>> > [0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.<br>> > [0]PETSC ERROR: See docs/index.html for manual pages.<br>> > [0]PETSC ERROR:<br>> > ------------------------------------------------------------------------
<br>> > [0]PETSC ERROR: ./myProg-opt on a linux-gnu named [1]PETSC ERROR:<br>> > --------------------- Error Message<br>> > ------------------------------------<br>> > [1]PETSC ERROR: Memory corruption!
<br>> > [1]PETSC ERROR: !<br>> > [1]PETSC ERROR:<br>> > ------------------------------------------------------------------------<br>> > [1]PETSC ERROR: Petsc Release Version 2.3.3, Patch 7, Fri Oct 26
<br>> > 14:21:35 CDT 2007 HG revision:<br>> > 2e223033ba960114833e1f9713ab393ec78c056f<br>> > [1]PETSC ERROR: See docs/changes/index.html for recent updates.<br>> > [1]PETSC ERROR: See docs/faq.html for hints about trouble shooting.
<br>> > [1]PETSC ERROR: See docs/index.html for manual pages.<br>> > [1]PETSC ERROR: ----------------------------[cli_0]: aborting job:<br>> > application called MPI_Abort(comm=0x84000000, 78) - process 0
<br>> > [cli_1]: aborting job:<br>> > application called MPI_Abort(comm=0x84000000, 78) - process 1<br>> > <a href="http://grove.ne.tamu.edu" target="_blank">grove.ne.tamu.edu</a> by vijaysm Tue Jan 22 15:47:58 2008
<br>> > [0]PETSC ERROR: Libraries linked from<br>> > /state/partition1/local/petsc-2.3.3-p7/lib/linux-gnu-c-debug<br>> > [0]PETSC ERROR: Configure run at Fri Nov 9 15:02:46 2007<br>> > [0]PETSC ERROR: Configure options --with-cc=gcc --with-fc=ifort
<br>> > --with-cxx=g++ --download-f-blas-lapack=1 --download-mpich=1<br>> > --with-shared=1<br>> > [0]PETSC ERROR:<br>> > ------------------------------------------------------------------------<br>
> > [0]PETSC ERROR: PetscMallocValidate() line 139 in src/sys/memory/mtr.c<br>> > [0]PETSC ERROR: SNESComputeFunction() line 950 in src/snes/interface/snes.c<br>> > [0]PETSC ERROR: SNESSolve_LS() line 158 in src/snes/impls/ls/ls.c
<br>> > [0]PETSC ERROR: SNESSolve() line 1871 in src/snes/interface/snes.c<br>> > [0]PETSC ERROR: main() line 395 in unknowndirectory/myProg.C<br>> ><br>> > If you need some more information, feel free to let me know. Thanks in advance !
<br>> ><br>> > Vijay<br>> ><br>> ><br>><br>><br>><br>> --<br>> What most experimenters take for granted before they begin their<br>> experiments is infinitely more interesting than any results to which
<br>> their experiments lead.<br>> -- Norbert Wiener<br>><br>><br><br></div></div></blockquote></div><br>