Using Rust on the Open Science Grid03 Jan 2019
I will admit that the Rust programming language fascinates me. It’s got all the things I want in a programming language, that I normally get from C, and also gives me some measure of protection against really screwing up. Not that I do that much…or even have a use for, anymore. I mean, my last round of “systems-level programming” was in C++ for the Phonics package. But hey, I can dream, right?
But I also do not know Rust, beyond some basics, since I don’t do any systems programming. But I wanted to learn a bit more decided to really have some fun. I ported the Open Science Grid’s R tutorial to Rust, which I will then submit to the Open Science Grid (OSG) for parallel computation. The program uses the shotgun method to estimate the value of [latex]\pi[/latex], so this gives us a fun little project of no value.
First, I am using OSG Connect for access to the OSG. Whatever resource you are using must have Rust installed and OSG Connect does not. Fortunately, we have a large quota and the standard installation instructions for Rust work just fine, if taking a few minutes.
Once I installed Rust, I used Cargo to create a new project.
Then I did a straight port of the R Monte Carlo code, and got
Now, this Rust code is probably overspecified. But I was in a mood
and wanted to make sure I didn’t really mess this up. This was good,
since the original version also kept calculating the final value
as 3, since it was being converted to an integer. So this was the
compromise with Rust. Another tick in this program is that the
result is prefaced by “” to match the R output. The R demo uses
awk to average all the outputs and I didn’t want to rewrite that
Next up is the Condor submission file:
As you can see, this code just calls the executable right out of the Cargo build space and runs it 100 times. All over the world. Or perhaps in my backyard. I don’t know and I don’t even have to care! Using the averager function from the R tutorial, this is what we get:
All-in-all, this is a pretty trivial exercise. But that’s ultimately the point of this post. Kicking Rust into action on the OSG should not be a big deal. And in practice, it is not. Given Rust’s increased protections against programmer error (over C), it would not be unwise to see more mathematical and scientific codes moving over.
This research was done using resources provided by the Open Science Grid, which is supported by the National Science Foundation award 1148698, and the U.S. Department of Energy’s Office of Science.