Reputation: 233
My desktop CPU is intel i7-4770 which has 4 physical Cores and 8 logical Cores. To get the most performance, how can I start Julia with additional arguments. "julia -p 4 -t 8" is right?
Upvotes: 1
Views: 605
Reputation: 42194
These are two different options.
-t
is for the number of threads withing a single Julia process-p
is for the number of processes in a (local) Julia cluster, each of those processes can have one or many threads.The difference between threads and multiprocessing is the patterns for parallel computing - mainly resulting from different ways how the memory is accessed by tasks. For multithreading you will use Threads
package and for mutltiprocessing the Distributed
package.
The examples below should clear things out.
Running 4 threads in a single process:
$ julia -t 4
julia> Threads.nthreads()
4
julia> using Distributed
julia> Distributed.nworkers()
1
Running 4 single-threaded workers (a total of 5 julia
processes) and checking the number of threads on the second worker:
$ julia -p 4
julia> using Distributed
julia> Distributed.nworkers()
4
julia> fetch(@spawnat 2 Threads.nthreads())
1
Running 4 multi-threaded workers (a total of 5 julia
processes with each process having 4 threads) and checking the number of threads on the master and the second worker:
$ julia -p 4 -t 4
julia> using Distributed
julia> Distributed.nworkers()
4
julia> Threads.nthreads()
4
julia> fetch(@spawnat 2 Threads.nthreads())
4
Now regarding the performance the short answer is "it depends". Some libraries will use the multi-threading functionality while other will mostly not.
For an example LinearAlgebra
is by default using BLAS
which has its own multi-threading setting:
$ julia -t 3
julia> using LinearAlgebra
julia> BLAS.vendor()
:openblas64
julia> BLAS.get_num_threads()
8
Other packages such as DataFrames
are currently being heavily developed for multi-threading and should make a good use of the -t
parameter.
Basically using -t auto
which defaults to the number of logical cores could be a good setting.
When running your own algorithms you will decide whether to go for multi-threading or multi-processing. A general rule of thumb is that for numerical computation multi-threading is often easier to use but multi-processing scales butter (and using the --machine-file
option you can have a huge distributed Julia cluster).
Upvotes: 6
Reputation: 4370
That will work, as will julia -p 8
. However, which one gives optimal performance will likely depend on which exact algorithms and parallel processing methods your code is using. For reference, julia -p auto
defaults to the number of logical cores, so in this case would be equivalent to julia -p 8
. From the list of command line-arguments in the docs [1]:
-p, --procs {N|auto} Integer value N launches N additional local worker processes; auto launches as many workers as the number of local CPU threads (logical cores)
[1] https://docs.julialang.org/en/v1.6/manual/command-line-options/
Upvotes: 0