Its possible to use all cores or parallel cores to do some project/calculations?

I have three different and independent task/calculation to do.

function interpQa()
  

     ag = 0.01:0.05:3    
     aσ = 0.03 : 0.025 : 0.63

    if PrimeiraVez

    mQ = [Q(g,sigma) for g in ag, sigma in aσ]


     writedlm("Qa_termo2020.dat",mQ)

    else

     mQ=readdlm("C:\\Users\\Lucas\\Desktop\\LUCAS\\Julia\\Qa_termo2020.dat")
     
    iQ = interpolate(mQ, BSpline(Cubic(Line())), OnGrid())    # Interpola na grade
    sQ = scale(iQ, ag, aσ)
    (x,y)->sQ[x,y]
end


function interpQb()
    
     ag = 0.01:0.05:3    # teste
     aσ = 0.03 : 0.025 : 0.63
     aα = 0:0.1:0.4
     aT= 0.1:0.05:0.4

    if PrimeiraVez
          mQ = [Qd(g,sigma,α,T) for g in ag, sigma in aσ, α in aα, T in aT]
          writedlm("Qb_termo2020.dat",mQ)
    else
          mQ=readdlm("C:\\Users\\Lucas\\Desktop\\LUCAS\\Julia\\Qb_termo2020.dat")
         
          mQ = reshape(mQ,(length(ag),length(aσ),length(aα),length(aT)))
    end

           # Matriz com os valores de Q na grade
    iQ = interpolate(mQ, BSpline(Cubic(Line())), OnGrid())    # Interpola na grade
    sQ = scale(iQ, ag, aσ, aα,aT)
    (x,y,z,w) -> sQ[x,y,z,w]
end


function interpQc()
    

    ag = 0.01:0.05:3    # teste
    aσ = 0.03 : 0.025 : 0.63


    if PrimeiraVez
    mQ = [Qi(g,sigma) for g in ag, sigma in aσ]
    writedlm("Qc_termo2020.dat",mQ)
   else
      mQ=readdlm("C:\\Users\\Lucas\\Desktop\\LUCAS\\Julia\\Qc_termo2020.dat")
      #mQ=readdlm("/media/lucas/Backup/Linux/Julia/Qc_todos.dat")
   end

         # Matriz com os valores de Q na grade
    iQ = interpolate(mQ, BSpline(Cubic(Line())), OnGrid())    # Interpola na grade
    sQ = scale(iQ, ag, aσ)
    (x,y)->sQ[x,y]
end






time0 = time()
println("Gerando a função Qa(g,sigma)")
Qa = interpQa()
tempod = (time() - time0)/60
println("Tempo decorrido: $tempod min")

time0 = time()
println("Gerando a função Qb(g,α,sigma,T) ")
Qb = interpQb()
tempod = (time() - time0)/60
println("Tempo decorrido: $tempod min")

time0 = time()
println("Gerando a função Qc(g,sigma)")
Qc = interpQc()
tempod = (time() - time0)/60
println("Tempo decorrido: $tempod min")

How can i use all cores or do the three tasks at the same time ?

Maybe this helps:
https://docs.julialang.org/en/v1/manual/distributed-computing/

You need to make some decisions here.
Let us say you have 24 cores available.
You need to see if running on 24 cores versus 12 cores makes calculations 1 and 3 run twice as fast.

Calculation 2 - what is the nature of this calculation?

And remember - you will ultimately be bound by the serial part of any of these calculations.

This calculations is an integral with many variables, so i make all calculations to make a table to use further … this 3 calculations are independent. I have 8 cores and 16 threading to make it … but i think i use only one core.

i need to see a quick example to pay attencion and re use that

The details of your problem matter - can you provide a toy example (no more than a few dozen lines of code) that captures the essential behavior of your program?

my program is too complicated to reproduce here …
i am interpolate (cubic) 3 integrals with many variables … i do all integrals with many factors and keep it in a table to use further …

Even a bit of pseudocode? Again, knowledge of the particulars is really important for efficient parallelism. Are you using any Julia packages for integration or interpolation?

I am using quadgk and interpolation routine. Julia Packages …
I think before the command “interpolation” can have some command that uses all cores, or to use some specific core and use another cores for the other 2 interpolations.

General problem statements can only have general answers and the general answer for how to do this kind of thing is the manual chapter on parallel computing, already linked. You may be able to use Threads.@spawn to get some parallel speedup. If you post actual code here, you’ll very likely get help from people to parallelize that code. Absent that, you’ll have to try it yourself and see how it goes.

3 Likes

I will write only the major commands to do what i want.
I hope it helps you to see what i am doing.

function interpQa()
  

     ag = 0.01:0.05:3    
     aσ = 0.03 : 0.025 : 0.63

    if PrimeiraVez

    mQ = [Q(g,sigma) for g in ag, sigma in aσ]


     writedlm("Qa_termo2020.dat",mQ)

    else

     mQ=readdlm("C:\\Users\\Lucas\\Desktop\\LUCAS\\Julia\\Qa_termo2020.dat")
     
    iQ = interpolate(mQ, BSpline(Cubic(Line())), OnGrid())    # Interpola na grade
    sQ = scale(iQ, ag, aσ)
    (x,y)->sQ[x,y]
end


function interpQb()
    
     ag = 0.01:0.05:3    # teste
     aσ = 0.03 : 0.025 : 0.63
     aα = 0:0.1:0.4
     aT= 0.1:0.05:0.4

    if PrimeiraVez
          mQ = [Qd(g,sigma,α,T) for g in ag, sigma in aσ, α in aα, T in aT]
          writedlm("Qb_termo2020.dat",mQ)
    else
          mQ=readdlm("C:\\Users\\Lucas\\Desktop\\LUCAS\\Julia\\Qb_termo2020.dat")
         
          mQ = reshape(mQ,(length(ag),length(aσ),length(aα),length(aT)))
    end

           # Matriz com os valores de Q na grade
    iQ = interpolate(mQ, BSpline(Cubic(Line())), OnGrid())    # Interpola na grade
    sQ = scale(iQ, ag, aσ, aα,aT)
    (x,y,z,w) -> sQ[x,y,z,w]
end


function interpQc()
    

    ag = 0.01:0.05:3    # teste
    aσ = 0.03 : 0.025 : 0.63


    if PrimeiraVez
    mQ = [Qi(g,sigma) for g in ag, sigma in aσ]
    writedlm("Qc_termo2020.dat",mQ)
   else
      mQ=readdlm("C:\\Users\\Lucas\\Desktop\\LUCAS\\Julia\\Qc_termo2020.dat")
      #mQ=readdlm("/media/lucas/Backup/Linux/Julia/Qc_todos.dat")
   end

         # Matriz com os valores de Q na grade
    iQ = interpolate(mQ, BSpline(Cubic(Line())), OnGrid())    # Interpola na grade
    sQ = scale(iQ, ag, aσ)
    (x,y)->sQ[x,y]
end






time0 = time()
println("Gerando a função Qa(g,sigma)")
Qa = interpQa()
tempod = (time() - time0)/60
println("Tempo decorrido: $tempod min")

time0 = time()
println("Gerando a função Qb(g,α,sigma,T) ")
Qb = interpQb()
tempod = (time() - time0)/60
println("Tempo decorrido: $tempod min")

time0 = time()
println("Gerando a função Qc(g,sigma)")
Qc = interpQc()
tempod = (time() - time0)/60
println("Tempo decorrido: $tempod min")

This post has instructions for how to properly quote your code:

Maybe take a look at @threads instead of the comprehension. For the three different computations why not just start 3 julia processes?

i want to implement a parallel computation to optimize my code.
6 hours is ok to wait. But 10 days is too much.

We’ll happily help speed up your code, but it’s important to boil down the code to the bare minimum and provide a completely reproducible example that can be pasted into the REPL without modification. It’s much harder to provide help if parts of the code are missing. As it is, you haven’t defined PrimeiraVez or Q, and the .dat directory is specific to your computer (it’s better to use tempdir() to create a temporary directory for testing). You’re also not using quadgk anywhere in the provided example.

To simplify, let’s focus on the 10 day code & ignore the 6 hour codes for the moment. Can you provide an example from the 10 hour code that can be run in a fresh Julia session without modification, as well as a measurement of how long it takes to run the example on your computer?

1 Like

Usually, one starts by figuring out where the most time is spent in your code.
This is called profiling. See e.g., here
Profiling · The Julia Language .
Why do you think that using more cores will significantly speed up your code?
It sounds like your code is on the math heavy side. In this case it is often way better to change the algorithm to fit your particular problem better. But again: without knowledge about what you are actually doing, it is nearly impossible to help you.

Even math-heavy code can benefit from multiple cores if (the hotspot determined from profiling) is sufficiently parallelizable. I don’t think anyone can tell whether that is the case from the OP’s description.

https://drive.google.com/drive/folders/111VCGNQIwiugwOMq94qExnBLAukplN0x?usp=sharing
the file “” principal"" is my program … another files is to complete the principal file. I think only "brent.jl"is using.

the file “” principal"" is my program … another files is to complete the principal file. I think only "brent.jl"is using. I hope you can help me

https://drive.google.com/drive/folders/111VCGNQIwiugwOMq94qExnBLAukplN0x?usp=sharing

I’m not able to access the document.