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