#!/usr/bin/env perl use 5.016; use warnings; use MCE; my @percentages = qw{0 20 25 33.333 40 50 60 66.667 75 80 100 200}; for my $specified_percentage (@percentages) { say "Specified percentage of logical cores to use: $specified_percentage%"; my $modified_percentage = $specified_percentage <= 0 ? 1 : $specified_percentage >= 100 ? 100 : $specified_percentage; say "Modified percentage of logical cores to use: $modified_percentage%"; say 'Total number of logical cores ', MCE::Util::get_ncpu(); my $max_workers = int(0.5 + MCE::Util::get_ncpu() * $modified_percentage / 100) || 1; say "Maximum workers to use: $max_workers"; my @wids; my $mce = MCE::->new( max_workers => $max_workers, gather => \@wids, user_func => sub { my ($mce) = @_; MCE->gather($mce->wid); }, ); $mce->run(); say "Worker ID(s): @{[sort { $a <=> $b } @wids]}"; }