source: gs2-extensions/parallel-building/trunk/src/perllib/ParallelInexport.pm@ 24839

Last change on this file since 24839 was 24839, checked in by jmt12, 12 years ago

If the filelist is already present in tmp don't regenerate (just for testing) and make the mpi launch in a pipe so we can continually trap output (rather than waiting until a system() call had completed

File size: 3.0 KB
RevLine 
[24626]1###########################################################################
2#
3# ParallelInexport.pm -- useful class to support parallel_import.pl
4# A component of the Greenstone digital library software
5# from the New Zealand Digital Library Project at the
6# University of Waikato, New Zealand.
7#
8# Copyright (C) 1999 New Zealand Digital Library Project
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23#
24###########################################################################
25
26package ParallelInexport;
27
28use strict;
29
30
31# index the files in parallel using MPI farmer to farm off multiple processes
32# [hs, 1 july 2010]
33sub farm_out_processes
34{
35 my ($jobs, $epoch, $importdir, $block_hash, $collection, $site) = @_;
36
[24698]37 my $tmp_dir_path = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, 'tmp');
38 if (!-d $tmp_dir_path)
39 {
40 mkdir($tmp_dir_path, 0777);
41 }
[24626]42
[24839]43 # create the list of files to import
[24698]44 my $tmp_filelist = &util::filename_cat($tmp_dir_path, "filelist.txt");
[24839]45 # - if the file is already there (which is should be during testing) then
46 # don't regenerate. This is especially important for imports of 1 million
47 # documents as just the directory scan can take several hours.
48 if (!-f $tmp_filelist)
[24626]49 {
[24839]50 open (my $filelist, ">$tmp_filelist");
51 foreach my $filename (sort keys %{$block_hash->{'all_files'}})
52 {
[24626]53 my $full_filename = &util::filename_cat($importdir,$filename);
54 if ((! exists $block_hash->{'file_blocks'}->{$full_filename})
55 && ($filename !~ m/metadata\.xml$/))
56 {
[24839]57 print $filelist "$filename\n";
[24626]58 }
[24839]59 }
60 close ($filelist);
[24626]61 }
[24684]62
[24626]63 # invoke the farmer to start processing the files
[24684]64 $site = "" if (!defined $site);
[24626]65 my $gsdlhome = $ENV{'GSDLHOME'};
[24684]66 my $farmer_exe = 'mpiimport'; # will be on PATH
[24839]67 my $mpi_cmd = "mpirun -n $jobs $farmer_exe $tmp_filelist $epoch $gsdlhome $collection $site";
68# my $mpi_cmd = "mpirun --show-progress --timestamp-output --verbose --report-bindings --tag-output -n $jobs $farmer_exe $tmp_filelist $epoch $gsdlhome $collection $site";
69 print STDERR "MPI Command: \"" . $mpi_cmd . "\"\n";
70# system ($mpi_cmd);
71 open(MPI, $mpi_cmd . " |") or die("Couldn't Execute MPI");
72 while ( defined( my $line = <MPI> ) )
73 {
74 chomp($line);
75 print "$line\n";
76 }
77 close(MPI);
[24626]78}
79
801;
Note: See TracBrowser for help on using the repository browser.