4

I am running a program that does numeric ODE integration in Julia. I am running Windows 10 (64bit), with Intel Core i7-4710MQ @ 2.50Ghz (8 logical processors).

I noticed that when my code was running on julia, only max 30% of CPU is in usage. Going into the parallelazation documentation, I started Julia using: C:\Users\*****\AppData\Local\Julia-0.4.5\bin\julia.exe -p 8 and expected to see improvements. I did not see them however.

Therefore my question is the following: Is there a special way I have to write my code in order for it to use CPU more efficiently? Is this maybe a limitation posed by my operating system (windows 10)?

I submit my code in the julia console with the command: include("C:\\Users\\****\\AppData\\Local\\Julia-0.4.5\\13. Fast Filesaving Format.jl").

Within this code I use some additional packages with: using ODE; using PyPlot; using JLD.

I measure the CPU usage with windows' "Task Manager".

George Datseris
  • 411
  • 4
  • 14
  • 3
    You need to make adjustments to your code for parallel computing manually. Here is the reference for parallel computing http://docs.julialang.org/en/release-0.4/manual/parallel-computing/ . I am no expert but you usually can make compute laden loops parallel with `@parallel` macro and there is `pmap` for equilvalance for map in parallization. – Lutfullah Tomak Jun 28 '16 at 12:06
  • 1
    yes, my example was but a vain attempt to see whether there is a "shortcut" for raising cpu usage. I will have to look into parallelizing my code some time in the future. Thank you. – George Datseris Jun 28 '16 at 12:28
  • 1
    You can also check out these two SO posts [here](http://stackoverflow.com/questions/37287020/how-and-when-to-use-async-and-sync-in-julia/37287021#37287021) and [here](http://stackoverflow.com/questions/37846838/what-exactly-is-the-difference-between-parallel-and-pmap/37849587#37849587) for some additional guidance on parallelism in Julia – Michael Ohlrogge Jun 28 '16 at 14:13
  • Wow, these are actually very helpful! Thank you! – George Datseris Jun 28 '16 at 15:03

1 Answers1

12

The -p 8 option to julia starts 8 worker processes, and disables multithreading in libraries like BLAS and FFTW so that the workers don't oversubscribe the physical threads on the system – since this kills performance in well-balanced distributed workloads. If you want to get more speed out of -p 8 then you need to distribute work between those workers, e.g. by having each of them do an independent computation, or by having the collaborate on a computation via SharedArrays. You can't just add workers and not change the program. If you are using BLAS (doing lots of matrix multiplies) or FFTW (doing lots of Fourier transforms), then if you don't use the -p flag, you'll automatically get multithreading from those libraries. Otherwise, there is no (non-experimental) user-level threading in Julia yet. There is experimental threading support and version 1.0 will support threading, but I wouldn't recommend that yet unless you're an expert.

StefanKarpinski
  • 32,404
  • 10
  • 86
  • 111
  • Ah, thank you for the good reply once again. I do use some FFTs, so therefore I shouldn't use the `-p` flag. But then, my question remains: Is it possible to "raise" the CPU usage? Or this does not have something to do with Julia bit the way the processor is structured? p.s.: I am not an expert of course, therefore if the processes to make "more usage of CPU" possible are too complicated, then I will leave it be. Thank you once again! – George Datseris Jun 28 '16 at 12:21
  • 2
    @George: This is a good answer. If I can just add a generality, since I don't know Julia, parallelism serves two different purposes. One is performance, if you can figure out how to structure your program so it can utilize more than one CPU at the same time. The other has nothing to do with performance. If your program must handle independent I/O from multiple different streams, it can simplify things to dedicate a separate thread to each stream. Whether it does this with multiple CPUs or one CPU is completely beside the point. – Mike Dunlavey Jun 28 '16 at 13:25
  • Okay, good. I think your answers are pretty much satisfactory: I have to learn how to structure a program in an way so that it uses "parallel computing". I thank you both, I will start with the documentation at Julia website. – George Datseris Jun 28 '16 at 14:11