1

Suppose that I launch Julia through bash script:

for i in {1..10}; do for j in 0.1 0.5 1 2 5 10; do j7 src/some_script.jl $i $j; done ; done

Currently, I am doing the following within some_script.jl so the compilation time gets faster:

# some_script.jl

main(i, j)
    some_fct(time_limit=20, i, j) # time_limit is 20s
    some_fct(time_limit=3600, i, j) # time limit is one hour
end

main(parse(Int, ARGS[1]), parse(Int, ARGS[2]))

Am I right doing so? Will the second execution of some_fct be faster thanks to the first launch?

EDIT: As a clarification to Ashlin Harris' answer. It is normal that my for loop is not precompilied as I want every launch to be independant. However, for a given i, and j, I would like that my script takes advantage of on-time precompilation. That is why I launch my function twice, hoping that its second launch will be faster. At end, I am wondering myself, whether this:

# some_script.jl

main(i, j)
    some_fct(time_limit=20, i, j) # time_limit is 20s
    some_fct(time_limit=3600, i, j) # time limit is one hour
end
main(1,2)

Is better for some_fct than this:

# some_script.jl

main(i, j)
    some_fct(time_limit=3600, i, j) # time limit is one hour
end
main(1,2)

?

JKHA
  • 1,800
  • 11
  • 28
  • What's the meaning of 'MWE"? Does the fct_mwe inside any package? – Daniel YC Lin Dec 15 '22 at 01:36
  • @DanielYCLin, MWE: Minimal Working Exemple https://stackoverflow.com/help/minimal-reproducible-example – JKHA Dec 15 '22 at 12:43
  • @DanielYCLin fct_mwe can or can not be inside a module, I coded both of the possibilities – JKHA Dec 15 '22 at 12:43
  • Anyway, your mwe is not a minimal reproducible example. we can not put it into rustc and compile it. it will cause error. And you don't need to include the word mwe, it just let people confuse. I have similar question of your question here, wish it helps https://stackoverflow.com/questions/74741436/how-to-speed-up-julia-script-launch-time – Daniel YC Lin Dec 16 '22 at 07:46
  • @DanielYCLin, you are right, I did not provide a mwe. I edited my question with `some_fct` instead of `mwe_fct`. Thank you for your relevant remark. Anyway as you said, this is not the main point of my question. To go back to it, it seems that what you ask in the link you gave is not an answer to my question. I think Julia is faster at its second launch because it can understand for instance what are the types of the arguments and variables once it has already been launch once. That is what I am trying to do by launching `some_fct` twice :) – JKHA Dec 16 '22 at 14:21

1 Answers1

2

Your Bash script starts up your Julia script at each iteration of the loop. This doesn't preserve any precompilation and would probably outweigh any optimization inside the script. Instead, you should write your loop entirely in Julia to take advantage of any precompilation.

Ashlin Harris
  • 414
  • 2
  • 6
  • I edited my question accordingly to your answer! – JKHA Dec 15 '22 at 12:48
  • For now, I recommend that you don't worry about precompilation. Instead, write good Julia code and let the compiler decide what to do. Calling a Julia script multiple times from the shell isn't efficient. https://viralinstruction.com/posts/badjulia/#compile_time_latency – Ashlin Harris Dec 15 '22 at 14:32
  • I thought Julia was more efficient in its second launch because it can detect what are the types of the variables for instance and go faster. Detect that some variables are `Bool` (second launch) instead of `Any` (first launch). You suggest that I am wrong and I should only launch my function once? – JKHA Dec 16 '22 at 14:26
  • Yes. Declare your variable types to make sure that these don't change. If the compiler knows the types, it can compile efficient code. But I think all that is less important than your loop structure. Don't call your Julia script inside a double-nested Bash loop unless you like waiting. – Ashlin Harris Dec 16 '22 at 17:53