Open LouisJenkinsCS opened 5 years ago
I feel like I've heard anecdotally that people have been able to use GSL via extern blocks and/or c2chapel, but I agree that making this into an official library with Chapeltastic interfaces would be better.
Athough I have no experience with GSL (and so cannot say anything about it), I think it would be definitely useful to have enhanced/increased support for statistics/probability somehow. For example, I recently wrote a mini routine for generating normal (Gaussian) random numbers based on the Box-Muller method, but I believe it is very poor in terms of performance...
(Looking at the above page, GSL seems to be using other algorithms for generating Gaussians.) https://www.gnu.org/software/gsl/doc/html/randist.html#the-gaussian-distribution The standard library in C++ also has such a generator: http://www.cplusplus.com/reference/random/normal_distribution/
For example, I recently wrote a mini routine for generating normal (Gaussian) random numbers based on the Box-Muller method, but I believe it is very poor in terms of performance...
FYI - There's an issue for this feature request here: https://github.com/chapel-lang/chapel/issues/6852
An example of using GSL gaussian distributions in Chapel is also included in the comments: link to gist
@ben-albrecht Thanks very much for the links, I will check how to connect with such C libraries.
Edit: Nevertheless, I also feel that the most important subset of random number distribution(s) (such as Gaussian) may be better provided in the standard library in future, because it appears so commonly in various simulations...
It'd be nice to wrap and 'extern' some key things you'd want. With the availability of Mason, you can create your own package that does exactly this and distribute it @ty1027. Even incremental development would be great, and since it's open-source it allows people to contribute and provide their own wrappers.
Dear all -- I've been slowly converting the examples in the GSL documentation into Chapel codes. In this process, I've also been sometimes adding in helper routines, although in large part, I've just stuck to the C API for simplicity.
Since the GSL list of functions is large, I've been leveraging the extern
block functionality of Chapel to keep the GSL module simple. @mppf made a number of improvements to this in the last iteration, making this largely possible (thanks!). The only downside is that this requires compiling with LLVM support (although later usage doesn't require running through LLVM).
I've just pulled things into a public repo here: https://gitlab.com/npadmana/chpl-gsl
I have some more examples floating around (including the RNG distribution cases). I'll push those through.
This could also be made into a Mason package relying on GSL installed through Spack (which is what I use). However, the current testing uses start_test
, so that would need to be migrated as well.
This is nice, but I really would like for an actual wrapper to exist for these kinds of things.
use GSL.RNG;
config const RNGType="mt19937";
config const iseed : uint(64) = 0;
var r = new owned RNG(engine = RNGType, seed = iseed);
writef("generator type: %s\n", r.getEngine());
writef("seed = %i\n", r.getSeed());
writef("first value = %i\n", r.getNext());
I think its fine to incrementally wrap this up, rather than do it all at once. I know GSL is large, but it'd really benefit from actual Chapel bindings.
My standard question: Was c2chapel
unable to handle the GSL header?
@bradcray -- the problem is that it isn't a single header, it's ~200 header files all including each other. I did make some progress with c2chapel, but it required a fair amount of hand-holding to make something clean. And would have been a pain for me to try and maintain.
This version is quite compact and lets me focus on the niceties...
That isn't to say that c2chapel isn't the best approach for the long-run, but extern blocks gave me what I needed.
@LouisJenkinsCS -- I agree; it was just slightly lower priority for me. That being said, the particular API you describe would be pretty easy to do.
I just added in random number distributions, although again with the C API only.
I do sincerely appreciate the heroic effort, especially since you managed to get a very nice proof of concept going so far. If possible, can you make a clone on GitHub so that I can collaborate and make my own PRs?
@LouisJenkinsCS -- https://github.com/npadmana/chpl-gsl
Feel free to file PRs/issues; all would be much appreciated. I can try to push over a first draft at the RNG code later.
Thanks!
@npadmana Made a PR: https://github.com/npadmana/chpl-gsl/pull/2
One thing that I have sorely missed, especially while working on scientific applications, was a good statistics/probability library. It would be very nice to have some bindings around the GNU Scientific Library (GSL).
https://www.gnu.org/software/gsl/