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

Automatically wrapping with Clang.jl #149

Closed
wants to merge 53 commits into from
Closed

Automatically wrapping with Clang.jl #149

wants to merge 53 commits into from

Conversation

jkozdon
Copy link
Member

@jkozdon jkozdon commented Jul 15, 2021

Experimenting to play with #147

Todo

@jkozdon
Copy link
Member Author

jkozdon commented Jul 15, 2021

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

@jkozdon
Copy link
Member Author

jkozdon commented Jul 15, 2021

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
Copy link
Member Author

jkozdon commented Jul 16, 2021

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

@psanan
Copy link
Contributor

psanan commented Jul 20, 2021

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?

@vchuravy
Copy link
Member

I think everything in lib is autogenerated.

@jkozdon
Copy link
Member Author

jkozdon commented Jul 20, 2021

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 jkozdon force-pushed the jek/gen branch 2 times, most recently from 53fc7ab to aa8e660 Compare July 21, 2021 23:09
@jkozdon jkozdon force-pushed the jek/gen branch 4 times, most recently from afbe26f to 0f22d51 Compare August 3, 2021 19:55
@boriskaus boriskaus marked this pull request as ready for review August 3, 2021 21:49
@jkozdon jkozdon force-pushed the jek/gen branch 4 times, most recently from 3e3e0f9 to 1850ac4 Compare August 4, 2021 17:53
@psanan
Copy link
Contributor

psanan commented Aug 5, 2021

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".

@jkozdon
Copy link
Member Author

jkozdon commented Aug 5, 2021

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

@jkozdon jkozdon force-pushed the jek/gen branch 2 times, most recently from 8880682 to 0846151 Compare August 26, 2021 17:02
@jkozdon jkozdon force-pushed the jek/gen branch 2 times, most recently from 7d50259 to f499bc4 Compare August 31, 2021 23:08
@jkozdon jkozdon linked an issue Aug 31, 2021 that may be closed by this pull request
@jkozdon jkozdon force-pushed the jek/gen branch 2 times, most recently from 4db9766 to 581f379 Compare September 3, 2021 18:48
# ideally we would capture the output directly, but this looks difficult
# easiest option is to redirect stdout
# based on suggestion from https://github.com/JuliaLang/julia/issues/32567
function _show(io::IO, obj)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still has problems with large matrices.

Might be better to create a temp file with mktemp(), redirect the PETSC output to an ascii file with PetscViewerASCIIOpenWithFILE, then dump the contents to io.

Or something is wrong with the flush?

@jkozdon jkozdon mentioned this pull request Dec 3, 2021
3 tasks
@jkozdon jkozdon closed this Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants