Erlang on multicore CPU

后端 未结 3 1525
感动是毒
感动是毒 2020-12-31 03:30

I am learning erlang and am quite impressed how easy it is to parallelize work. To practice a bit I dug up the good ole Fibanocci sequence. In the following code I try to ta

3条回答
  •  我在风中等你
    2020-12-31 04:29

    Erlang's default behavior has historically been to run one scheduler, which is basically a native OS thread, which chooses Erlang tasks to run from a queue. With the advent of multi-core and multi-processor systems, the runtime was extended to take advantage. Starting the runtime with -smp enabled will cause the runtime to create multiple schedulers, usually one per logical CPU. You can manually specify the number of schedulers with the -S flag e.g. -S 16.

    This is documented in the Erlang Run-Time System Reference Manual.

    A deeper discussion of SMP support can be found in this discussion thread.

    EDIT

    I should also point out that, as of R12B, SMP is enabled by default on platforms that support it (equivalent to the -smp auto flag). If you're curious about your own runtime, the following quote from the discussion thread will be of interest:

    You can see what was chosen at the first line of printout from the "erl" command. E.g. Erlang (BEAM) emulator version 5.6.4 [source] [smp:4] [asynch-threads:0] .....

    The "[smp:4]" above tells that the SMP VM is run and with 4 schedulers.

提交回复
热议问题