Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable -log_view #171

Open
boriskaus opened this issue Aug 26, 2021 · 1 comment
Open

Enable -log_view #171

boriskaus opened this issue Aug 26, 2021 · 1 comment

Comments

@boriskaus
Copy link
Collaborator

In PETSc, the command-line option -log_view will show an overview with timings and memory allocations of the simulation, once the simulation is finalised. This is currently not working, but would be handy to have (good for benchmarking and running simulations).
I recall that -log_view is treated slightly different than other parameter options and should be set at the beginning of the simulation, but @psanan can probably explain this better.

@jkozdon
Copy link
Member

jkozdon commented Aug 26, 2021

We can run the logger directly:

using PETSc
using MPI

petsclib = PETSc.getlib()
PETSc.initialize(petsclib)

# Start the logger
PETSc.LibPETSc.PetscLogDefaultBegin(petsclib)

# Run some PETSc code
using SparseArrays: spdiagm
PetscScalar = petsclib.PetscScalar
Nq = 100
n = Nq - 2
x = range(PetscScalar(0), length = Nq, stop = 1)[2:(end - 1)]
Δx = PetscScalar(x.step)
A =
    spdiagm(
        -1 => -ones(PetscScalar, n - 1),
        0 => 2ones(PetscScalar, n),
        1 => -ones(PetscScalar, n - 1),
    ) / Δx^2
κ = 2PetscScalar(π)
u(x) = sin* x)
f(x) = κ^2 * sin* x)
ksp = PETSc.KSP(A; ksp_monitor = true);
v = ksp \ f.(x);
ϵ = sqrt(sum((v - u.(x)) .^ 2 * Δx))

# Dump the logger
viewer = PETSc.LibPETSc.PETSC_VIEWER_STDOUT_(petsclib, MPI.COMM_SELF)
PETSc.LibPETSc.PetscLogView(petsclib, viewer)

# Finalize PETSc
PETSc.finalize(petsclib)

(This obviously isn't clean yet, and the calls to LibPETSc should be hidden in some way).

I tried pushing log_view directly but got some errors from PETSc on finalize. My guess is they want the options set with PetscInitialize whereas we use PetscInitializeNoArguments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants