Get the number of cores in Erlang using Linux

I am writing a parallel program, and I need to know the number of system cores, so the program will know how many processes need to be opened. Is there a command to get this inside Erlang code?

Thnx.

+7
source share
3 answers

you can use

erlang:system_info(logical_processors_available) 

to get the number of cores that can be used by the erlang runtime system.

+10
source

There is also:

 erlang:system_info(schedulers_online) 

which tells you how many scheduler threads are actually running.

+10
source

How this information will be disclosed will be very specific to the operating system (unless you are writing an operating system , of course).

You did not say which operating system you are running on. In the case of Linux, you can get data from / proc / cpuinfo, however, there are subtleties with the value of hyperthreading and a problem with multiple cores on the same matrix using a common L2 cache (in fact, you have the NUMA architecture).

0
source

All Articles