sgeenviron.pl
#!/usr/bin/perl
# * Copyright 2010. The Regents of the University of California.
# * All Rights Reserved.
# * @author Prakashan Korambath
# *
# * Purpose: Make use of scheduler TMPDIR variable for File I/O. The scratch space
# * defined in SGE is often has a faster I/O than NFS file system. So your codes
# * may run faster if you use TMPDIR to write scratch files which are not needed
# * at the end of a run. The scheduler used on Hoffman2 is Oracle Grid Engine.
# * In place of TMPDIR any other faster SCRATCH space can be substituted.
# *
# * This software program and documentation are copyrighted by The Regents
# * of the University of California. The software program and documentation
# * are supplied "as is", without any accompanying services from The Regents.
# * The Regents does not warrant that the operation of the program will be
# * uninterrupted or error-free. The end-user understands that the program
# * was developed for research purposes and is advised not to rely exclusively
# * on the program for any reason.
#
# * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
# * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
# * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
# * EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY
# * OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY
# * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED
# * HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO
# * OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
# * MODIFICATIONS.
# *
# *
use strict;
my $index;
# Get SGE environment variable TMPDIR
my $tmpdir=$ENV{TMPDIR};
# define a scratchfile
my $scratch1 ='/scratchxxx';
if (!defined($tmpdir)) {
print "Failed to get environment variable TMPDIR \n";
$tmpdir='/work';
}
print "TMPDIR is $tmpdir \n";
# This is the full file path for scratch
my $filepath=$tmpdir . $scratch1;
print "Scratch file path is $filepath \n";
# Now Open the file for writing
open (OUTFILE, ">$filepath") || die ("Can't open $filepath for writing\n");
for ($index = 1; $index <= 10; $index++) {
print OUTFILE " $index \n";
}
close (OUTFILE);
# Now Open the file for reading
open (INFILE, "<$filepath") || die ("Can't open $filepath for reading\n");
while (<INFILE>) {
print $_;
}
close (INFILE);
unlink($filepath);
exit;