xbraid icon indicating copy to clipboard operation
xbraid copied to clipboard

Julia interface

Open cadaverous-lives opened this issue 1 year ago • 3 comments

(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 avatar May 24 '23 21:05 cadaverous-lives

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

rfalgout avatar Jun 01 '23 14:06 rfalgout

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 avatar Jun 01 '23 17:06 cadaverous-lives

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!

cadaverous-lives avatar Jun 01 '23 17:06 cadaverous-lives