Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exectute Julia code in command line?

Tags:

julia

I have been recently transfer my code in Julia. I'm wondering how to exectute Julia code in command line?

I know the Julia code can be complied by running it once.

But the thing is I need to do parameter sweep for my simulation models on the cluster, where I could only use command line -- not the REPL.

What is the best practice to run simulation replications on the cluster?

like image 316
Yifei Avatar asked Oct 28 '25 17:10

Yifei


2 Answers

Just call your script using the command line:

julia myscript.jl

But the thing is I need to do parameter sweep for my simulation models on the cluster, where I could only use command line.

I think it's easiest to use Julia's built-in parallelism. pmap usually does the trick. If you're solving differential equations, DifferentialEquations.jl has a function which will parallelize your problem across a cluster, and its internal implementation uses pmap. That can serve as a good reference for how to handle other problems as well.

Then all you have to do is call Julia so that way it has access to all cores. You can easily do this by passing in the machinefile:

julia myscript.jl --machinefile the_machine_file

The machine file is generated whenever you create a batch job (for some clusters, sometimes you need to enable MPI for the machine file to show up). For more information, see this blog post.

like image 108
Chris Rackauckas Avatar answered Oct 31 '25 13:10

Chris Rackauckas


Forgot to mention that I've managed to run Julia from command line on the cluster.

In the PBS job script, you can add julia run_mytest.jl $parameter. In the run_mytest.jl, you can add

include("mytest.jl")
arg = parse(Float64, ARGS[1])
mytest(arg)
like image 28
Yifei Avatar answered Oct 31 '25 12:10

Yifei



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!