PETSc.jl icon indicating copy to clipboard operation
PETSc.jl copied to clipboard

Automatically wrapping with `Clang.jl`

Open jkozdon opened this issue 4 years ago • 29 comments

Experimenting to play with #147

Todo

  • [x] wrap MAT + MPI
  • [x] wrap ksp
  • [x] wrap DM and DMDA
  • [ ] DMStag
  • [x] wrap snes
  • [ ] docs (see also https://github.com/JuliaParallel/PETSc.jl/pull/149#issuecomment-893291251)
  • [ ] explore windows, MPI, and test/dmda.jl failure...
  • [ ] explore windows and examples/laplacian.jl failure...

jkozdon avatar Jul 15 '21 23:07 jkozdon

Doesn't work with everything yet but you can call initialize and finalize.

jkozdon avatar Jul 15 '21 23:07 jkozdon

Input:

# For some reason you need to initialize MPI before using multiple libraries.
# Need to debug this
using MPI
MPI.Initialized() || MPI.Init()
using PETSc
for petsclib in PETSc.LibPETSc.petsclibs
    println(splitpath(petsclib.petsc_library)[end])
    @show PETSc.initialized(petsclib)
    @show PETSc.initialize(petsclib)
    @show PETSc.initialized(petsclib)
    @show PETSc.finalized(petsclib)
    @show PETSc.finalize(petsclib)
    @show PETSc.initialized(petsclib)
    @show PETSc.finalized(petsclib)
    println()
end

Output:

libpetsc_double_real_Int64.dylib
PETSc.initialized(petsclib) = false
PETSc.initialize(petsclib) = nothing
PETSc.initialized(petsclib) = true
PETSc.finalized(petsclib) = false
PETSc.finalize(petsclib) = nothing
PETSc.initialized(petsclib) = false
PETSc.finalized(petsclib) = true

libpetsc_single_real_Int64.dylib
PETSc.initialized(petsclib) = false
PETSc.initialize(petsclib) = nothing
PETSc.initialized(petsclib) = true
PETSc.finalized(petsclib) = false
PETSc.finalize(petsclib) = nothing
PETSc.initialized(petsclib) = false
PETSc.finalized(petsclib) = true

libpetsc_double_complex_Int64.dylib
PETSc.initialized(petsclib) = false
PETSc.initialize(petsclib) = nothing
PETSc.initialized(petsclib) = true
PETSc.finalized(petsclib) = false
PETSc.finalize(petsclib) = nothing
PETSc.initialized(petsclib) = false
PETSc.finalized(petsclib) = true

libpetsc_single_complex_Int64.dylib
PETSc.initialized(petsclib) = false
PETSc.initialize(petsclib) = nothing
PETSc.initialized(petsclib) = true
PETSc.finalized(petsclib) = false
PETSc.finalize(petsclib) = nothing
PETSc.initialized(petsclib) = false
PETSc.finalized(petsclib) = true

jkozdon avatar Jul 15 '21 23:07 jkozdon

I guess I still need to sort out the types (But I think it should be possible with more walking of the syntax tree).

jkozdon avatar Jul 16 '21 02:07 jkozdon

Lazy question, but what's the high-level procedure here? What is now automatic and what still has to be maintained "by hand"? Are the specific things here related to various PETSc components all of the "by hand" flavor, or are those things that have been generated automatically and are then checked in?

psanan avatar Jul 20 '21 07:07 psanan

I think everything in lib is autogenerated.

vchuravy avatar Jul 20 '21 09:07 vchuravy

As @vchuravy said, the file in lib is generated from the PETSc header files with the code in gen. These produce pretty raw wrappers, that I am then expanding on to make it all a little more friendly to work with.

There is a bunch of stuff we do not currently wrap (look at generator.toml), some of it will need to be sorted out and some of it won't (I think I know / have a plan for how to support most of what will be needed, just waiting to fix it until I am ready to use it / write the test).

There probably some gotchas left in there with respect to system / build dependent types that will need to be sorted out, but right now it does support multiple PETSc builds living side-by-side in Julia.

@psanan shoot me an email if you'd like to VTC to chat about what I am doing, I'd be more than happy to have feedback.

jkozdon avatar Jul 20 '21 15:07 jkozdon

Docs suggestion, re our chat our yesterday. Perhaps somewhere like here one could add language like "PETSc.jl's high-level, easy-to-use interface exposes only some of the functionality of PETSc. However, PETSc.jl includes an automatically-generated wrapper layer which directly exposes more of the PETSc API, which may be of use to existing expert users. See (link to minimal example/test of using the wrappers, directly) for an example".

psanan avatar Aug 05 '21 09:08 psanan

Thanks for the recommendation. I've put it as part of the PR task list.

jkozdon avatar Aug 05 '21 15:08 jkozdon