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

**URL:** <https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639>\
**Category:** Performance\
**Created:** [September 15, 2020, 2:17pm UTC](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639 "2020-09-15T14:17:07Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lucas\_Pollito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucas_pollito/32/14518_2.png) [@Lucas\_Pollito](https://discourse.julialang.org/u/Lucas_Pollito)\
**Post date:** [September 15, 2020, 2:17pm UTC](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639/1 "2020-09-15T14:17:07Z")

</div>

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

```julia
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 ?

---

<div class="post-metadata">

**Author:** ![Rudi79](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rudi79/32/3884_2.png) [@Rudi79](https://discourse.julialang.org/u/Rudi79)\
**Post date:** [September 15, 2020, 2:25pm UTC](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639/2 "2020-09-15T14:25:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [September 15, 2020, 3:10pm UTC](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639/3 "2020-09-15T15:10:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Lucas\_Pollito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucas_pollito/32/14518_2.png) [@Lucas\_Pollito](https://discourse.julialang.org/u/Lucas_Pollito)\
**Post date:** [September 15, 2020, 3:13pm UTC](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639/4 "2020-09-15T15:13:07Z")

</div>

> [@johnh](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![Lucas\_Pollito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucas_pollito/32/14518_2.png) [@Lucas\_Pollito](https://discourse.julialang.org/u/Lucas_Pollito)\
**Post date:** [September 15, 2020, 3:14pm UTC](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639/5 "2020-09-15T15:14:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [September 15, 2020, 3:41pm UTC](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639/6 "2020-09-15T15:41:40Z")

</div>

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?

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![Lucas\_Pollito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucas_pollito/32/14518_2.png) [@Lucas\_Pollito](https://discourse.julialang.org/u/Lucas_Pollito)\
**Post date:** [September 15, 2020, 3:46pm UTC](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639/7 "2020-09-15T15:46:16Z")

</div>

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 …

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [September 15, 2020, 4:27pm UTC](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639/8 "2020-09-15T16:27:04Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Lucas\_Pollito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucas_pollito/32/14518_2.png) [@Lucas\_Pollito](https://discourse.julialang.org/u/Lucas_Pollito)\
**Post date:** [September 15, 2020, 4:49pm UTC](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639/9 "2020-09-15T16:49:50Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [September 15, 2020, 5:19pm UTC](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639/10 "2020-09-15T17:19:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Lucas\_Pollito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucas_pollito/32/14518_2.png) [@Lucas\_Pollito](https://discourse.julialang.org/u/Lucas_Pollito)\
**Post date:** [September 15, 2020, 5:36pm UTC](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639/11 "2020-09-15T17:36:06Z")

</div>

> [@StefanKarpinski](#):
>
> Threads.@spawn

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

```julia
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")

```

```julia

```

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [September 15, 2020, 5:43pm UTC](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639/12 "2020-09-15T17:43:30Z")

</div>

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

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![danielw2904](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielw2904/32/10890_2.png) [@danielw2904](https://discourse.julialang.org/u/danielw2904)\
**Post date:** [September 15, 2020, 7:30pm UTC](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639/13 "2020-09-15T19:30:56Z")

</div>

Maybe take a look at [`@threads`](https://docs.julialang.org/en/v1/manual/multi-threading/#The-@threads-Macro) instead of the comprehension. For the three different computations why not just start 3 julia processes?

---

<div class="post-metadata">

**Author:** ![Lucas\_Pollito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucas_pollito/32/14518_2.png) [@Lucas\_Pollito](https://discourse.julialang.org/u/Lucas_Pollito)\
**Post date:** [September 15, 2020, 11:38pm UTC](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639/14 "2020-09-15T23:38:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [September 16, 2020, 12:52am UTC](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639/15 "2020-09-16T00:52:13Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Rudi79](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rudi79/32/3884_2.png) [@Rudi79](https://discourse.julialang.org/u/Rudi79)\
**Post date:** [September 16, 2020, 9:26am UTC](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639/16 "2020-09-16T09:26:17Z")

</div>

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](https://docs.julialang.org/en/v1/manual/profile/#Profiling) .  
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.

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [September 16, 2020, 4:25pm UTC](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639/17 "2020-09-16T16:25:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Lucas\_Pollito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucas_pollito/32/14518_2.png) [@Lucas\_Pollito](https://discourse.julialang.org/u/Lucas_Pollito)\
**Post date:** [September 16, 2020, 5:11pm UTC](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639/18 "2020-09-16T17:11:46Z")

</div>

[https://drive.google.com/drive/folders/111VCGNQIwiugwOMq94qExnBLAukplN0x?usp=sharing](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.

---

<div class="post-metadata">

**Author:** ![Lucas\_Pollito](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucas_pollito/32/14518_2.png) [@Lucas\_Pollito](https://discourse.julialang.org/u/Lucas_Pollito)\
**Post date:** [September 16, 2020, 5:12pm UTC](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639/19 "2020-09-16T17:12:48Z")

</div>

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](https://drive.google.com/drive/folders/111VCGNQIwiugwOMq94qExnBLAukplN0x?usp=sharing)

---

<div class="post-metadata">

**Author:** ![danielw2904](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielw2904/32/10890_2.png) [@danielw2904](https://discourse.julialang.org/u/danielw2904)\
**Post date:** [September 16, 2020, 7:07pm UTC](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639/20 "2020-09-16T19:07:23Z")

</div>

I’m not able to access the document.

[Next page](https://discourse.julialang.org/t/its-possible-to-use-all-cores-or-parallel-cores-to-do-some-project-calculations/46639.md?page=2)
