I am new to parallel programming concept and I am trying to follow up with the basics but I have this problem
when I run
julia -t 4
using Base.Threads
nthreads()
The result is always 1 so I cannot start applying the concepts.
I tried it on my machine which is core I5 and on a remote server for high end computing platform.
Now that’s strange, I get 4 if I run that code. Which version of Julia are you running?
1.0.5
this photo from remote server but its the same on my local machine
Are you launching Julia with the command julia --threads=4
/ julia -t 4
? For me this works as expected, although, I haven’t tested it on Julia 1.0.5.
I do not know why I receive this error
I think the option -t
or --threads
was introduced later. What you want to to is
export JULIA_NUM_THREADS=4
julia
i.e. define JULIA_NUM_THREADS
as an environment variable, not in a running julia session. Otherwise I can also recommend to use a newer version of Julia, unless you really have to use 1.0.
$ JULIA_NUM_THREADS=4 julia
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.7.2 (2022-02-06)
_/ |\__'_|_|_|\__'_| | Fedora 36 build
|__/ |
julia> Threads.nthreads()
4
This is because prior to v1.3 IO was not thread-safe. Another reason to update to the latest Julia version!
this works also thank you
#SBATCH -t 00:20:00
#SBATCH -N 4
#SBATCH -A tud01
#SBATCH -p DevQ
#SBATCH --mail-user=***********@**********
#SBATCH --mail-type=BEGIN,END
# This job's working directory
cd $SLURM_SUBMIT_DIR
module load julia/1.0.5
JULIA_NUM_THREADS=20
julia /ichec/home/users/JuliaCodes/FCode_ICH.jl
do you think this is correct sequence?
No it needs to be on one line:
$ JULIA_NUM_THREADS=4 julia
You might have limited control over what’s on the cluster, but fwiw I’d think twice about working with multithreaded code using a three year old version of Julia that predates the introduction of the current threading infrastructure in version 1.3.
If it’s on the cluster because 1.0.5 used to be the LTS version you could let your admin know that the current LTS is 1.6.6.
I sent an email to him
thank you
it is really a problem the server only include old versions
it caused many errors in other codes also
now I know
If you install a local version of Julia for yourself you’ll need ~450MB of storage. Maybe that doesn’t eat too much of your quota? And in terms of files it’s ~2500, if there’s a limitation on number of files on your cluster.
I did that
could you please tell me the correct way to call the new version not the old one
Depends on your setup, but on Linux the easiest is usually to just create a symlink from somewhere on your path to julia-1.7.3/bin/julia
If you are using a SLURM cluster, you may be interested in taking a look at Distributed.jl (gives you pmap which can parallelise across different processes using @distributed for reductions and pmap for parallel maps - these are the bread and butter of parallel programming). ClusterManagers.jl also provides a way of interacting with SLURM to create the processes in the first place without having to manually create the processes.
Also, you will find a lot of benefit upgrading (or asking the sysadmin to upgrade) the Julia version.
IT admin already updated to latest version and I have already ran my first code with threads “@threads”
I will start apply distributed
thank you