[petsc-users] Normalize vectors
Matthew Knepley
knepley at gmail.com
Sun May 11 20:09:40 CDT 2014
On Sun, May 11, 2014 at 8:07 PM, LikunTan <tlk0812 at hotmail.com> wrote:
> Dear Petsc developers,
>
> I have a vector M which consists of a series of 3d vectors, and I want to
> reset M by normalizing each 3d vector. Here is my code:
>
> /**********************************************************************
> VecGetArray(M, &aM);
>
Its easier not to make a mistake if you use
DMDAVecGetArrayDof()
Matt
> DMDAGetCorners(da, &xs, 0, 0, &xm, 0, 0);
> for(node=xs; node<xs+xm; node++)
> {
> mag=0.0;
> for(l=0; l<3; l++)
> {
> val[l]=aM[node*3+l];
> mag=mag+val[l]*val[l];
> }
> mag=sqrt(mag);
> for(l=0; l<user->NDOF; l++)
> {
> aM[node*3+l]=val[l]/mag;
> }
> }
> VecRestoreArray(M, &aM);
> VecAssemblyBegin(M);
> VecAssemblyEnd(M);
> VecView(M, PETSC_VIEWER_STDOUT_WORLD);
> **********************************************************************/
>
> but I got the error at the last step:
> --------------------------------------------------------------------------
> mpiexec noticed that process rank 3 with PID 17156 on node
> compute-21-8.local exited on signal 6 (Aborted).
> --------------------------------------------------------------------------
> and if I commented out VecView, and used vector M for other operations,
> e.g.
> KSPSolve(ksp, M, b), I got "memory corruption" message. Your comment on
> this issue is well appreciated.
>
>
>
>
--
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/20140511/fd811493/attachment.html>
More information about the petsc-users
mailing list