pi_examples icon indicating copy to clipboard operation
pi_examples copied to clipboard

Add Julia implementation using `OhMyThreads.jl`

Open giordano opened this issue 1 year ago • 0 comments

OhMyThreads.jl is a new-ish package which provides user-friendly threading constructs, for example it comes with a multithreaded map reduce, which is perfect for this program. Compare the implementation in this PR https://github.com/UCL-RITS/pi_examples/blob/bdd72c150a5f2b45465f4b5b2448296d9368c283/julia_ohmythreads_pi_dir/pi.jl#L11-L17 with the current multithreaded implementation: https://github.com/UCL-RITS/pi_examples/blob/fc92267c33b8ffb0e51e55083c71d5fb9926bfac/julia_threads_dir/pi.jl#L5-L21

Some benchmarks: on Nvidia Grace-Grace, with this implementation using Julia v1.11.1 I get

$ julia -t 144 pi.jl 1000000000000
  Activating project at `~/repo/pi_examples/julia_ohmythreads_dir`
  No Changes to `~/repo/pi_examples/julia_ohmythreads_dir/Project.toml`
  No Changes to `~/repo/pi_examples/julia_ohmythreads_dir/Manifest.toml`
  Warming up...done. [0.195s]

Calculating PI using:
  1000000000000 slices
  144 thread(s)
Obtained value of PI: 3.1415926535897936
Time taken: 5.458 seconds

With julia_threads_pi_dir (same version of Julia as above):

$ julia -t 144 pi.jl 1000000000000
  Warming up...done. [0.095s]

Calculating PI using:
  1000000000000 slices
  144 thread(s)
Obtained value of PI: 3.141592653588557
Time taken: 5.441 seconds

With c_omp_pi_dir:

$ make -B CC=gcc COPTS='-O2 -fopenmp -march=native' && OMP_NUM_THREADS=144 ./pi 1000000000000
gcc -O2 -fopenmp -march=native  -c pi.c -o pi.o
gcc -O2 -fopenmp -march=native  -o pi pi.o
Calculating PI using:
  1000000000000 slices
  144 thread(s)
Obtained value for PI: 3.14159265358896
Time taken:            5.77358439611271 seconds
$ gcc --version
gcc (GCC) 14.1.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

With fortran_omp_pi_dir:

$ make -Bf Makefile.gfortran FOPT='-O2 -fopenmp -march=native' && ./pi 1000000000000
gfortran -O2 -fopenmp -march=native -o pi pi.f90
Calculating PI using:
                     1000000000000 slices
                               144 OpenMP threads
Obtained value of PI: 3.1415926536
Time taken:                5.72090 seconds
$ gfortran --version
GNU Fortran (GCC) 14.1.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

giordano avatar Nov 27 '24 01:11 giordano