Index: main/trunk/greenstone2/perllib/ParallelInexport.pm
===================================================================
--- main/trunk/greenstone2/perllib/ParallelInexport.pm	(revision 22445)
+++ main/trunk/greenstone2/perllib/ParallelInexport.pm	(revision 22445)
@@ -0,0 +1,62 @@
+###########################################################################
+#
+# ParallelInexport.pm -- useful class to support parallel_import.pl
+# A component of the Greenstone digital library software
+# from the New Zealand Digital Library Project at the 
+# University of Waikato, New Zealand.
+#
+# Copyright (C) 1999 New Zealand Digital Library Project
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#
+###########################################################################
+
+package ParallelInexport;
+
+use strict;
+
+
+# index the files in parallel using MPI farmer to farm off multiple processes
+# [hs, 1 july 2010]
+sub farm_out_processes
+{
+   my ($jobs, $epoch, $importdir, $block_hash, $collection, $site) = @_;
+
+   my $tmp_filelist = &util::filename_cat($ENV{'GSDLHOME'}, "tmp", "filelist.txt");
+
+   # create the list of files to import
+   open (my $filelist, ">$tmp_filelist");
+   foreach my $filename (sort keys %{$block_hash->{'all_files'}})
+   {
+       my $full_filename = &util::filename_cat($importdir,$filename);
+       if ((! exists $block_hash->{'file_blocks'}->{$full_filename}) 
+	   && ($filename !~ m/metadata\.xml$/))
+       {
+	   print $filelist "$filename\n";
+       }
+   }
+   close ($filelist); 
+   
+   # invoke the farmer to start processing the files
+   $site = "localsite" if ((!defined $site) || ($site eq ""));
+   my $gsdlhome = $ENV{'GSDLHOME'};
+   my $farmer_exe = &util::filename_cat($gsdlhome,"bin",$ENV{'GSDLOS'},"farmer".&util::get_os_exe());
+
+   my $mpi_cmd = "mpirun -np $jobs $farmer_exe $tmp_filelist $epoch $gsdlhome $site $collection";
+
+   system ($mpi_cmd);
+}
+
+1;
Index: main/trunk/greenstone2/perllib/inexport.pm
===================================================================
--- main/trunk/greenstone2/perllib/inexport.pm	(revision 22444)
+++ main/trunk/greenstone2/perllib/inexport.pm	(revision 22445)
@@ -118,4 +118,8 @@
     $self->{'collection'} = shift @$argv;
 
+    if ((defined $self->{'jobs'}) && ($self->{'jobs'}>1)) {
+	require ParallelInexport;
+    }
+
     return bless $self, $class;
 }
@@ -350,4 +354,7 @@
 
     my $gli          = $self->{'gli'};
+
+    my $jobs         = $self->{'jobs'};
+    my $epoch        = $self->{'epoch'};
 
     # related to export
@@ -566,9 +573,29 @@
 	    
 	    # Play it safe, and run through the entire folder, only processing new or edited files
-	    &plugin::read ($pluginfo, $importdir, "", $block_hash, $metadata, $processor, $maxdocs, 0, $gli);
-
+	    
+            if ((defined $jobs) && ($jobs > 1))
+            { 
+		# if jobs are set to >1, run in parallel using MPI helper
+		# [hs, 1 july 2010]
+		&ParallelInexport::farm_out_processes($jobs, $epoch, $importdir, $block_hash, 
+						      $self->{'collection'}, $self->{'site'}); 
+            }
+            else
+            {
+	       &plugin::read ($pluginfo, $importdir, "", $block_hash, $metadata, $processor, $maxdocs, 0, $gli);
+            }
 	}
 	else {
-	    &plugin::read ($pluginfo, $importdir, "", $block_hash, $metadata, $processor, $maxdocs, 0, $gli);
+            if ((defined $jobs) && ($jobs > 1))
+            { 
+		# if jobs are set to >1, run in parallel using MPI helper
+		# [hs, 1 july 2010]
+		&ParallelInexport::farm_out_processes($jobs, $epoch, $importdir, $block_hash, 
+						      $self->{'collection'}, $self->{'site'}); 
+            }
+            else
+            {
+		&plugin::read ($pluginfo, $importdir, "", $block_hash, $metadata, $processor, $maxdocs, 0, $gli);
+            }   
 	}
 
@@ -685,30 +712,38 @@
     my $inexport_mode = $self->{'mode'};
 
-    my $statsfile = $self->{'statsfile'};
-    my $out       = $self->{'out'};
+    my $statsfile   = $self->{'statsfile'};
+    my $out         = $self->{'out'};
     my $faillogname = $self->{'faillogname'};
-    my $gli       = $self->{'gli'};
+    my $gli         = $self->{'gli'};
+    my $jobs        = $self->{'jobs'};
 
     # write out import stats
-    my $close_stats = 0;
-    if ($statsfile !~ /^(STDERR|STDOUT)$/i) {
-	if (open (STATS, ">$statsfile")) {
-	    $statsfile = 'import::STATS';
-	    $close_stats = 1;
-	} else {
-	    &gsprintf($out, "{import.cannot_open_stats_file}", $statsfile);
-	    &gsprintf($out, "{import.stats_backup}\n");
-	    $statsfile = 'STDERR';
-	}
-    }
-
-    &gsprintf($out, "\n");
-    &gsprintf($out, "*********************************************\n");
-    &gsprintf($out, "{$inexport_mode.complete}\n");
-    &gsprintf($out, "*********************************************\n");
-
-    &plugin::write_stats($pluginfo, $statsfile, $faillogname, $gli);
-    if ($close_stats) {
-	close STATS;
+
+    if ((!defined $jobs) || ($jobs == 1))
+    {
+	# only output statistics if there are multiple jobs
+	# [hs, 1 july 2010]
+
+	my $close_stats = 0;
+	if ($statsfile !~ /^(STDERR|STDOUT)$/i) {
+	    if (open (STATS, ">$statsfile")) {
+		$statsfile = 'import::STATS';
+		$close_stats = 1;
+	    } else {
+		&gsprintf($out, "{import.cannot_open_stats_file}", $statsfile);
+		&gsprintf($out, "{import.stats_backup}\n");
+		$statsfile = 'STDERR';
+	    }
+	}
+	
+	&gsprintf($out, "\n");
+	&gsprintf($out, "*********************************************\n");
+	&gsprintf($out, "{$inexport_mode.complete}\n");
+	&gsprintf($out, "*********************************************\n");
+	
+	&plugin::write_stats($pluginfo, $statsfile, $faillogname, $gli);
+	if ($close_stats) {
+	    close STATS;
+	}
     }
 
