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

Julia interface #90

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft

Julia interface #90

wants to merge 14 commits into from

Conversation

cadaverous-lives
Copy link
Collaborator

@cadaverous-lives cadaverous-lives commented May 24, 2023

(reopening on new branch)

Introduces a new interface to XBraid, written in Julia, along with an example and a couple of drivers demonstrating the usage of the interface.

I originally did not intend to make a pull request for this, as I made it for my own personal use, so I have made some choices that may be too restrictive. I have made this a draft pr so we can discuss the choices made.

My goal was to write the interface so that the user does not have to manage any memory or communication, and as a result the user does not write clone, free, bufpack, or bufunpack routines, and some default functions are provided for sum, norm, and inner_prod, assuming the user's vector is a Julia array.

Julia also being a just-in-time compiled language resulted in the need for a "warmup" function, which allows the user's functions to be compiled before braid_Drive is called. Without this, if the first downcycle is skipped, the user's step function is compiled every time it is called on the coarse grid by a new processor, which adds a lot of extra serial work to the first iteration.

notable features missing:

  • XBraid adjoint
  • spatial coarsening/refinement
  • residual option
  • sync function (Implemented)

I believe all of these features are fairly straightforward to implement, I just haven't had a need to work on them.

@cadaverous-lives cadaverous-lives changed the title New branch for julia interface pull request Julia interface May 24, 2023
cadaverous-lives and others added 6 commits May 24, 2023 18:52
added sync function to Julia wrapper
moved julia utility functions into BraidUtils.jl
moved wrapper_functions.jl into Wrappers.jl
created new namespace for Status structures
added calling_function constants to status.jl
added GetCFactor function to braid_status.c
/** Turn on the optional user-defined spatial coarsening and refinement functions */
/** Turn on/off the Fortran interface (useful for avoiding undefined symbol
* errors in shared library builds) */
#define braid_Fortran_Iface 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use a makefile mechanism instead?

@rfalgout
Copy link
Collaborator

rfalgout commented Jun 1, 2023

Hi @cadaverous-lives . I just pushed the changes we talked about yesterday. I used your MPIPreferences suggestion, but modified the path to something less specific (this still works and I think it's the right lib directory to point to anyway). See the examples README for details.

A couple of notes:

  • We should change the mechanism for turning the Fortran interface on/off (use make fortran=yes?)

  • I get the following warning from make shared=yes. Do we really need this option?

Building libbraid.so ...
mpicc  -g -Wall -fPIC -shared -undefined dynamic_lookup access.o adjoint.o base.o braid.o braid_status.o braid_F90_iface.o braid_test.o communication.o delta.o distribution.o drive.o grid.o hierarchy.o interp.o mpistubs.o norm.o refine.o relax.o residual.o restrict.o space.o step.o tape.o util.o uvector.o -o libbraid.so
ld: warning: -undefined dynamic_lookup may not work with chained fixups

- this currently just removes braid_F90_iface.c from the list of braid files/linked objects
@cadaverous-lives
Copy link
Collaborator Author

I just pushed the changes we talked about yesterday...

Hey Rob, thanks for doing that! I'm glad you were able to figure out how to provide a less specific location to use_system_binary(). The developer I talked to was not very helpful with that... I see now what you meant about there not being a make braid shared=yes option in the braid directory. I wasn't sure what the right way to do that was, so thank you for fixing that! I added a simple compiler option that just removes braid_F90_iface.c from the list of files to compile, and that seems to work. I'm assuming there is a better way to do this, maybe with a configure script, but I think this works!

I get the following warning from make shared=yes. Do we really need this option?

Weird... I don't get that warning, but with the fortran=no make option I no longer seem to need -undefined dynamic_lookup, so I'll remove it now.

@cadaverous-lives
Copy link
Collaborator Author

I just merged a bunch of changes from my fork, including:

  • support for sync function
  • reorganized braid.jl directory
  • added distinct status structure types (e.g. StepStatus, AccessStatus) so that now Julia knows which status functions can be called on each status object, and e.g. XBraid.Status.getTStop(status::AccessStatus) will result in a compile time error, rather than causing a potential segfault!

Added .dSYM file extension to .gitignore
This prevents having to make calls to XBraid.set functions to set common parameters like max_iters, max_levels, etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants