Last active
February 9, 2024 01:24
-
-
Save ajwheeler/90c5abf7fc333dbfd4d7dcbaf96b6ca1 to your computer and use it in GitHub Desktop.
Julia parallelism with JuliaCall
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from juliacall import Main as jl | |
import time | |
jl.include("utils.jl") | |
def wait_for_spectrum(s): | |
while True: | |
time.sleep(0.1) | |
if jl.isready(s): | |
print("Worker is ready!") | |
print(jl.fetch(s)) | |
break | |
else: | |
print("Worker is not ready yet...") | |
# start two worker processes | |
s1 = jl.generate_spectrum_on_worker(5777.0, 4.44) | |
s2 = jl.generate_spectrum_on_worker(5777.0, 4.44) | |
wait_for_spectrum(s1) | |
wait_for_spectrum(s2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Distributed | |
# Start a worker process for each thread | |
addprocs(Sys.CPU_THREADS) | |
@everywhere begin | |
using Korg | |
function generate_spectrum(teff, logg) | |
println("interpolating atmosphere") | |
atm = Korg.interpolate_marcs(teff, logg) | |
println("synthesizing") | |
sol = synthesize(atm, [], format_A_X(), 5000, 5050) | |
println("done!") | |
# only return 10 pixels to keep stdout tidy | |
sol.flux[1:10] | |
end | |
end | |
function generate_spectrum_on_worker(teff, logg) | |
@spawnat :any generate_spectrum(teff, logg) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment