10isitch has asked for the wisdom of the Perl Monks concerning the following question:
I have a script that splits a large 15Gb file into several smaller files. It only runs on single cpu core and takes over half an hour. Can I make it run on multiple cores so it runs faster? Here's a abbreviated version. Normally it would create 13 smaller files.
use strict; print "\nSTARTING $0...\n"; if (@ARGV != 3) { print "Usage: <BNH scenario file> <Equity scenario output> <IR + scenario output>\n"; exit -1; } my $infile = $ARGV[0]; my $eqfile = $ARGV[1]; my $irfile = $ARGV[2]; my (@arr,@arr2,$w1,$w2); unless (open(INFILE, "< $infile")) {print "Error: Can not open $infile +\n"; exit -1}; unless (open(EQFILE, "> $eqfile")) {print "Error: Can not open $eqfile +!\n"; exit -1}; unless (open(IRFILE, "> $irfile")) {print "Error: Can not open $irfile +!\n"; exit -1}; while (<INFILE>) { chomp $_; if ($_ =~ /ScenSet/) { print EQFILE "$_\n"; print IRFILE "$_\n";next; +} @arr = split/\,/; if ($arr[1]) { print EQFILE ",equity,Base Scenario,0,\n"; print IRFILE ",irate,Base Scenario,0,\n"; next; } if ($arr[2]) { my @arrn = split(/\_/,$arr[2]); print EQFILE ",,eq_".$arrn[1].",1,\n"; print IRFILE ",,ir_".$arrn[1].",1,\n"; next; } if ($arr[6]) {$w1 = 0;$w2 = 0;} # riskfactor contains the string "Index" will be identified as equity +riskfactor if ($_ =~ /Index/ && $_ !~ /Credit/) { $w1 = 1;} # Assumption for IR - there will be only riskfactor USDSWAP and USDTRE +A if ($_ =~ /USDSWAP/ || $_ =~ /USDTREA/) { $w2 = 1;} if ($w1) { print EQFILE "$_\n"; } if ($w2) { print IRFILE "$_\n"; } } close INFILE; close EQFILE; close IRFILE;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Multithreading a large file split to multiple files
by marioroy (Prior) on May 15, 2018 at 02:17 UTC | |
Re: Multithreading a large file split to multiple files
by BrowserUk (Patriarch) on May 14, 2018 at 22:07 UTC | |
by Marshall (Canon) on May 15, 2018 at 08:53 UTC | |
by 10isitch (Initiate) on May 15, 2018 at 14:53 UTC | |
Re: Multithreading a large file split to multiple files
by pwagyi (Monk) on May 15, 2018 at 01:38 UTC | |
Re: Multithreading a large file split to multiple files
by cavac (Prior) on May 16, 2018 at 12:43 UTC | |
by Anonymous Monk on May 16, 2018 at 18:11 UTC | |
A reply falls below the community's threshold of quality. You may see it by logging in. |