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;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.