Re: [petsc-users] petsc-users Digest, Vol 173, Issue 131
Thank you for your reply and help. I followed your advice to try it out, but found that the results were not quite right. It may be due to my misunderstanding. Could you please help me? The specific information is as follows: Codes: /* Solve J Y = F, where J is Jacobian matrix */ ierr = SNESComputeJacobian(snes, X, snes->jacobian, snes->jacobian_pre); CHKERRQ(ierr); PetscViewer viewer; /* View the matrix in a text file */ ierr = PetscViewerASCIIOpen(PETSC_COMM_WORLD, "/share/userfile/jianglei/Muti-layers-well-working/petsc/jacobianmatrix.m", &viewer);CHKERRQ(ierr); ierr = PetscViewerPushFormat(viewer, PETSC_VIEWER_ASCII_MATLAB);CHKERRQ( ierr); /* Optional: use MATLAB format */ ierr = MatView(snes->jacobian, viewer);CHKERRQ(ierr); ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr); MatAssemblyBegin(snes->jacobian,MAT_FINAL_ASSEMBLY); MatAssemblyEnd(snes->jacobian,MAT_FINAL_ASSEMBLY); PetscInt rstart, rend; MatGetOwnershipRange(snes->jacobian, &rstart, &rend); PetscInt row=1000, col=1000; PetscScalar v; if (row>=rstart && row<rend) { MatGetValues(snes->jacobian, 1, &row, 1, &col, &v); PetscPrintf(PETSC_COMM_WORLD, "rstart: %d, rend: %d, row: %d, col: %d, v: %e\n", rstart, rend, row, col, PetscRealPart(v)); } Results: [image: image.png] [image: image.png] [image: image.png] ====================== Step: 1, time: 0. days==================== 0 SNES Function norm 1.772062116708e-01 rstart: 0, rend: 4000, row: 1000, col: 1000, v: 7.443232e-06 That's all. Could you help me? On Tue, May 30, 2023 at 1:00 AM <[email protected]> wrote:
Send petsc-users mailing list submissions to [email protected]
To subscribe or unsubscribe via the World Wide Web, visit https://lists.mcs.anl.gov/mailman/listinfo/petsc-users or, via email, send a message with subject or body 'help' to [email protected]
You can reach the person managing the list at [email protected]
When replying, please edit your Subject line so it is more specific than "Re: Contents of petsc-users digest..."
Today's Topics:
1. MatGetValues() can't return the correct values (Waltz Jan) 2. Re: MatGetValues() can't return the correct values (Barry Smith)
----------------------------------------------------------------------
Message: 1 Date: Mon, 29 May 2023 16:49:40 +0800 From: Waltz Jan <[email protected]> To: [email protected] Subject: [petsc-users] MatGetValues() can't return the correct values Message-ID: <CAEj=jGKvgY5ys=4_=YoEZrE5Xu4Pj6FVxSq8XgUH=N= [email protected]> Content-Type: text/plain; charset="utf-8"
/* Solve J Y = F, where J is Jacobian matrix */ ierr = SNESComputeJacobian(snes, X, snes->jacobian, snes->jacobian_pre); CHKERRQ(ierr);
PetscInt rstart, rend; MatGetOwnershipRange(snes->jacobian, &rstart, &rend); PetscInt row=1000, col=1000; PetscScalar v; if (row>=rstart && row<rend) { MatGetValues(snes->jacobian, 1, &row, 1, &col, &v); PetscPrintf(PETSC_COMM_WORLD, "rstart: %d, rend: %d, row: %d, col: %d, v: %e\n", rstart, rend, row, col, v); }
It was supposed to return the value of the matrix at row 1001 and column 1001, but it returned the value at row 2001 and column 2001 instead. There is a two-fold relationship between these coordinates, and I'm not sure if it's related to the fact that I set the number of processes to 2.
What version of PETSc are you using? The output looks a little funny. Would you be willing to send your code to [email protected] <mailto:[email protected]> so I can debug it quickly?
On May 29, 2023, at 9:54 PM, Waltz Jan <[email protected]> wrote:
Thank you for your reply and help. I followed your advice to try it out, but found that the results were not quite right. It may be due to my misunderstanding. Could you please help me? The specific information is as follows:
Codes: /* Solve J Y = F, where J is Jacobian matrix */ ierr = SNESComputeJacobian(snes, X, snes->jacobian, snes->jacobian_pre); CHKERRQ(ierr);
PetscViewer viewer; /* View the matrix in a text file */ ierr = PetscViewerASCIIOpen(PETSC_COMM_WORLD, "/share/userfile/jianglei/Muti-layers-well-working/petsc/jacobianmatrix.m", &viewer);CHKERRQ(ierr); ierr = PetscViewerPushFormat(viewer, PETSC_VIEWER_ASCII_MATLAB);CHKERRQ(ierr); /* Optional: use MATLAB format */ ierr = MatView(snes->jacobian, viewer);CHKERRQ(ierr); ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
MatAssemblyBegin(snes->jacobian,MAT_FINAL_ASSEMBLY); MatAssemblyEnd(snes->jacobian,MAT_FINAL_ASSEMBLY); PetscInt rstart, rend; MatGetOwnershipRange(snes->jacobian, &rstart, &rend); PetscInt row=1000, col=1000; PetscScalar v;
if (row>=rstart && row<rend) { MatGetValues(snes->jacobian, 1, &row, 1, &col, &v); PetscPrintf(PETSC_COMM_WORLD, "rstart: %d, rend: %d, row: %d, col: %d, v: %e\n", rstart, rend, row, col, PetscRealPart(v)); }
Results: <image.png> <image.png> <image.png> ====================== Step: 1, time: 0. days==================== 0 SNES Function norm 1.772062116708e-01 rstart: 0, rend: 4000, row: 1000, col: 1000, v: 7.443232e-06
That's all. Could you help me?
On Tue, May 30, 2023 at 1:00 AM <[email protected] <mailto:[email protected]>> wrote:
Send petsc-users mailing list submissions to [email protected] <mailto:[email protected]>
To subscribe or unsubscribe via the World Wide Web, visit https://lists.mcs.anl.gov/mailman/listinfo/petsc-users or, via email, send a message with subject or body 'help' to [email protected] <mailto:[email protected]>
You can reach the person managing the list at [email protected] <mailto:[email protected]>
When replying, please edit your Subject line so it is more specific than "Re: Contents of petsc-users digest..."
Today's Topics:
1. MatGetValues() can't return the correct values (Waltz Jan) 2. Re: MatGetValues() can't return the correct values (Barry Smith)
----------------------------------------------------------------------
Message: 1 Date: Mon, 29 May 2023 16:49:40 +0800 From: Waltz Jan <[email protected] <mailto:[email protected]>> To: [email protected] <mailto:[email protected]> Subject: [petsc-users] MatGetValues() can't return the correct values Message-ID: <CAEj=jGKvgY5ys=4_=YoEZrE5Xu4Pj6FVxSq8XgUH=N=QF_C-vA@mail.gmail.com <mailto:[email protected]>> Content-Type: text/plain; charset="utf-8"
/* Solve J Y = F, where J is Jacobian matrix */ ierr = SNESComputeJacobian(snes, X, snes->jacobian, snes->jacobian_pre); CHKERRQ(ierr);
PetscInt rstart, rend; MatGetOwnershipRange(snes->jacobian, &rstart, &rend); PetscInt row=1000, col=1000; PetscScalar v; if (row>=rstart && row<rend) { MatGetValues(snes->jacobian, 1, &row, 1, &col, &v); PetscPrintf(PETSC_COMM_WORLD, "rstart: %d, rend: %d, row: %d, col: %d, v: %e\n", rstart, rend, row, col, v); }
It was supposed to return the value of the matrix at row 1001 and column 1001, but it returned the value at row 2001 and column 2001 instead. There is a two-fold relationship between these coordinates, and I'm not sure if it's related to the fact that I set the number of processes to 2.
participants (2)
-
Barry Smith -
Waltz Jan