1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
BEGIN {
use_ok 'MCE::Child';
}
{
no warnings 'redefine';
sub MCE::Util::get_ncpu { return 16; }
}
{
# When max_workers is specified... (default undef, unlimited)
# Going higher than the HW ncpu limit is possible. Simply specify the
# number of workers desired. The minimum number of workers is 1.
MCE::Child->init(max_workers => 0);
is(MCE::Child->max_workers(), 1, "check that max_workers=>0 is 1");
MCE::Child->max_workers(5);
is(MCE::Child->max_workers(), 5, "check that max_workers=>5 is 5");
MCE::Child->max_workers(20);
is(MCE::Child->max_workers(), 20, "check that max_workers=>20 is 20");
}
{
# 'auto' is the number of logical processors.
MCE::Child->init(max_workers => 'auto');
is(MCE::Child->max_workers(), 16,
"check that max_workers=>'auto' is 16 logical cores"
);
}
{
# One may specify a percentage starting with MCE::Child 1.876.
# The minimum number of workers is 1.
MCE::Child->init(max_workers => '0%');
is(MCE::Child->max_workers(), 1,
"check that max_workers=>'0%' is 1 on HW with 16 logical cores"
);
MCE::Child->max_workers('1%');
is(MCE::Child->max_workers(), 1,
"check that max_workers=>'1%' is 1 on HW with 16 logical cores"
);
MCE::Child->max_workers('25%');
is(MCE::Child->max_workers(), 4,
"check that max_workers=>'25%' is 4 on HW with 16 logical cores"
);
MCE::Child->max_workers('37.5%');
is(MCE::Child->max_workers(), 6,
"check that max_workers=>'37.5%' is 6 on HW with 16 logical cores"
);
MCE::Child->max_workers('100%');
is(MCE::Child->max_workers(), 16,
"check that max_workers=>'100%' is 16 on HW with 16 logical cores"
);
MCE::Child->max_workers('200%');
is(MCE::Child->max_workers(), 32,
"check that max_workers=>'200%' is 32 on HW with 16 logical cores"
);
}
done_testing;
|