> On Apr 17, 2018, at 4:25 PM, Young, Matthew, Adam <[email protected]> wrote: > > That all makes sense. Thanks. > > Is it okay to MatCreate() and MatDestroy() in each time step or am I just > defeating the purpose of preserving the KSP?
You are defeating the purpose. Barry > > Is there a way to tell if the KSP is reusing the factorization (e.g., with > -ksp_view)? > From: Smith, Barry F. <[email protected]> > Sent: Tuesday, April 17, 2018 5:13:10 PM > To: Young, Matthew, Adam > Cc: Matthew Knepley; [email protected] > Subject: Re: [petsc-users] Reuse KSP > > > If the matrix has a null space then, in general, direct LU factorizations > should fail. If they don't fail they can produce an incorrect answer > > If your matrix has a null space then you should not remove the [Set > nullspace of A with MatSetNullSpace] > > Barry > > > On Apr 17, 2018, at 7:48 AM, Young, Matthew, Adam <[email protected]> wrote: > > > > > > > > > > From: Matthew Knepley <[email protected]> > > Sent: Tuesday, April 17, 2018 8:38 AM > > To: Young, Matthew, Adam > > Cc: [email protected] > > Subject: Re: [petsc-users] Reuse KSP > > > > On Tue, Apr 17, 2018 at 8:33 AM, Young, Matthew, Adam <[email protected]> wrote: > > My code (C/C++) uses PETSc to solve a linear system at each iteration in a > > time-stepping scheme. The PETSc routines are separated out because the > > scheme that uses them is optional in the larger code. > > > > At each time step, the PETSc scheme calls a routine that includes: > > > > { > > Mat A; > > Vec x,b; > > KSP ksp; > > > > [Set up A,x,b] > > > > KSPCreate(PETSC_COMM_WORLD,&ksp); > > > > [Build A and b from simulation data] > > > > [Set nullspace of A with MatSetNullSpace] > > > > KSPSetOperators(ksp,A,A); > > KSPSetFromOptions(ksp); > > KSPSolve(ksp,b,x); > > > > [Write x into an instance of our array class, perform checks, etc.] > > > > KSPDestroy(&ksp); > > > > return(0); > > } > > > > My question is: If I want to use superLU_DIST with the option > > -mat_superlu_dist_fact SamePattern (or SamePattern_SameRowPerm), should I > > move KSPCreate/Destroy outside of the time-step loop in the larger code? > > > > 1) Yes > > > > 2) How are you using LU when A has a nullspace? > > My bad - that code is in there from when I was trying iterative solvers. > > Should I remove it if I use LU or will PETSc just ignore it? > > > > 3) You can also move out SetFromOptions(). > > Thanks for the advice. So, that means I'll build A and b from simulation > > data, SetOperators(), Solve(), and carry on? > > > > Matt > > > > Thanks. > > ---------------------------- > > Matthew Young > > PhD Candidate > > Astronomy Department > > Boston University > > > > > > > > > > > > -- > > 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 > > > > https://www.cse.buffalo.edu/~knepley/
