1MCE::Util(3)          User Contributed Perl Documentation         MCE::Util(3)
2
3
4

NAME

6       MCE::Util - Utility functions
7

VERSION

9       This document describes MCE::Util version 1.874
10

SYNOPSIS

12        use MCE::Util;
13

DESCRIPTION

15       A utility module for MCE. Nothing is exported by default. Exportable is
16       get_ncpu.
17
18   get_ncpu()
19       Returns the number of logical (online/active/enabled) CPU cores; never
20       smaller than one.
21
22        my $ncpu = MCE::Util::get_ncpu();
23
24       Specifying 'auto' for max_workers calls MCE::Util::get_ncpu
25       automatically.  MCE 1.521 sets an upper-limit when specifying 'auto'.
26       The reason is mainly to safeguard apps from spawning 100 workers on a
27       box having 100 cores.  This is important for apps which are IO-bound.
28
29        use MCE;
30
31        ## 'Auto' is the total # of logical cores (lcores) (8 maximum, MCE 1.521).
32        ## The computed value will not exceed the # of logical cores on the box.
33
34        my $mce = MCE->new(
35
36        max_workers => 'auto',       ##  1 on HW with 1-lcores;  2 on  2-lcores
37        max_workers =>  16,          ## 16 on HW with 4-lcores; 16 on 32-lcores
38
39        max_workers => 'auto',       ##  4 on HW with 4-lcores;  8 on 16-lcores
40        max_workers => 'auto*1.5',   ##  4 on HW with 4-lcores; 12 on 16-lcores
41        max_workers => 'auto*2.0',   ##  4 on HW with 4-lcores; 16 on 16-lcores
42        max_workers => 'auto/2.0',   ##  2 on HW with 4-lcores;  4 on 16-lcores
43        max_workers => 'auto+3',     ##  4 on HW with 4-lcores; 11 on 16-lcores
44        max_workers => 'auto-1',     ##  3 on HW with 4-lcores;  7 on 16-lcores
45
46        max_workers => MCE::Util::get_ncpu,   ## run on all lcores
47        );
48
49       In summary:
50
51        1. Auto has an upper-limit of 8 in MCE 1.521 (# of lcores, 8 maximum)
52        2. Math may be applied with auto (*/+-) to change the upper limit
53        3. The computed value for auto will not exceed the total # of lcores
54        4. One can specify max_workers explicitly to a hard value
55        5. MCE::Util::get_ncpu returns the actual # of lcores
56

ACKNOWLEDGMENTS

58       The portable code for detecting the number of processors was adopted
59       from Test::Smoke::SysInfo.
60

INDEX

62       MCE, MCE::Core
63

AUTHOR

65       Mario E. Roy, <marioeroy AT gmail DOT com>
66
67
68
69perl v5.32.0                      2020-08-19                      MCE::Util(3)
Impressum