[petsc-dev] PetscObjectViewFromOptions() pull request 1005 1006
Lawrence Mitchell
wence at gmx.li
Thu Jun 28 12:17:35 CDT 2018
> On 28 Jun 2018, at 17:24, Lisandro Dalcin <dalcinl at gmail.com> wrote:
>
> On Thu, 28 Jun 2018 at 19:16, Lawrence Mitchell <wence at gmx.li> wrote:
>>
>> This uses the Push/Pop stuff that I added in PR#604, in response to noting (in PCPATCH runs) that 90% of the time was spent in XXXViewFromOptions. After adding the push/pop pair, this dropped to basically 0%. I didn't do further exhaustive benchmarking to check for further problems.
>>
>
> There you have! Thanks for confirming my previous guess. I would
> really like that PR being split, and leave the changes to
> XXXSetFromOptions() on hold in a separate PR.
OK, I've done some more benchmarking now, and cooked up a very simple test case. I just solve a tiny problem 10 million times.
On master, this completes on my machine in:
If I leave the viewers on, this takes ages:
(master-viewers-on) $ time taskset -c 1 ./many-ksps
real 0m37.07s
When I turn the viewers off
(master-viewers-off) $ time taskset -c 1 ./many-ksps
real 0m17.979s
On knepley/feature-pc-patch both are faster, with no difference between turning viewers on and turning viewers off.
(patch) $ time task set -c 1 ./many-ksps
real 0m12.512s
So a 25%-30% win.
IOW, Patrick and I would definitely like this change to make it into master (it has a noticeable effect on the speed of our solver). But it could arguably be split in two.
Lawrence
#include <petsc.h>
int main(int argc, char **argv)
{
PetscErrorCode ierr;
Vec x, y;
KSP ksp;
Mat A;
MPI_Comm comm;
ierr = PetscInitialize(&argc, &argv, NULL, NULL);
if (ierr) return ierr;
comm = PETSC_COMM_WORLD;
ierr = MatCreate(comm, &A); CHKERRQ(ierr);
ierr = MatSetSizes(A, PETSC_DECIDE, PETSC_DECIDE, 20, 20); CHKERRQ(ierr);
ierr = MatSetUp(A); CHKERRQ(ierr);
for (int i = 0; i < 20; i++) {
PetscScalar one = 1;
ierr = MatSetValues(A, 1, &i, 1, &i, &one, INSERT_VALUES); CHKERRQ(ierr);
}
ierr = MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);
ierr = MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);
ierr = MatCreateVecs(A, &x, &y); CHKERRQ(ierr);
ierr = KSPCreate(comm, &ksp); CHKERRQ(ierr);
ierr = KSPSetOperators(ksp, A, A); CHKERRQ(ierr);
ierr = KSPSetFromOptions(ksp); CHKERRQ(ierr);
ierr = PetscOptionsPushGetViewerOff(PETSC_TRUE); CHKERRQ(ierr);
for ( int i = 0; i < 10000000; i++ ) {
ierr = VecSet(x, 0); CHKERRQ(ierr);
ierr = VecSet(y, 1); CHKERRQ(ierr);
ierr = KSPSolve(ksp, y, x); CHKERRQ(ierr);
}
ierr = PetscOptionsPopGetViewerOff(); CHKERRQ(ierr);
ierr = KSPDestroy(&ksp); CHKERRQ(ierr);
ierr = MatDestroy(&A); CHKERRQ(ierr);
ierr = VecDestroy(&x); CHKERRQ(ierr);
ierr = VecDestroy(&y); CHKERRQ(ierr);
ierr = PetscFinalize();
return ierr;
}
More information about the petsc-dev
mailing list