Archived
1
0

Multi-thread grades generation

This commit is contained in:
Mercier Pierre-Olivier 2014-01-17 01:52:20 +01:00
parent 8ddca7c49a
commit 2e5b2af4d8

View File

@ -2,6 +2,7 @@
use v5.10.1;
use strict;
use threads;
use warnings;
use Carp;
use Pod::Usage;
@ -98,7 +99,38 @@ sub grades_generate
my @trace_dirs = grep { ( ! /^\./ ) && -d "$basedir/$year/$project_id/traces/$_" } readdir($dh);
closedir $dh;
for my $login (@logins)
my @ths;
my $max_ths = 4;
my $login_by_threads = @logins / $max_ths;
for (my $i = 0; $i < $max_ths; $i++)
{
my @partlogin = @logins[($i*$login_by_threads) .. (($i+1)*$login_by_threads - 1)];
push @ths, threads->create(\&do_grade_generation, $grading, $year, $project_id, $groups, \@trace_dirs, @partlogin);
}
if ($login_by_threads * $max_ths < @logins)
{
my @partlogin = @logins[$login_by_threads * $max_ths .. $#logins];
push @ths, threads->create(\&do_grade_generation, $grading, $year, $project_id, $groups, \@trace_dirs, @partlogin);
}
for my $th (@ths) {
$th->join();
}
return 1;
}
sub do_grade_generation
{
my $grading = shift;
my $year = shift;
my $project_id = shift;
my $groups = shift;
my @trace_dirs = @{ shift() };
for my $login (@_)
{
my @files;
@ -157,8 +189,6 @@ sub grades_generate
$grading->reset();
}
return 1;
}
sub grades_new_bonus