#!/usr/bin/perl -w # # pbsdcp -- Distributed copy command for the PBS environment # Copyright 2006 Ohio Supercomputer Center # Revision info: # $HeadURL$ # $Revision$ # $Date$ # # Usage: pbsdcp [-g|-s] [options] srcfile [...srcfiles...] target # # Options: # -g gather mode # -s scatter mode (default) # # -h print a help message # -p preserve modification times and permissions # -r recursive copy if ( ! $ENV{"PBS_ENVIRONMENT"} || ( $ENV{"PBS_ENVIRONMENT"} ne "PBS_BATCH" && $ENV{"PBS_ENVIRONMENT"} ne "PBS_INTERACTIVE" ) || $ARGV[0] eq "-h" || $#ARGV < 1 ) { if ( ! $ENV{"PBS_ENVIRONMENT"} || ( $ENV{"PBS_ENVIRONMENT"} ne "PBS_BATCH" && $ENV{"PBS_ENVIRONMENT"} ne "PBS_INTERACTIVE" ) ) { warn "$0: Not running withing a PBS job, exiting.\n\n"; } print </dev/null`; chomp($mpiexec); $scatter = `which pbsdcp-scatter 2>/dev/null`; chomp($scatter); # use pbsdcp-scatter if available if ( length($mpiexec)>0 && length($scatter)>0 ) { exec("mpiexec -pernode pbsdcp-scatter @ARGV $target"); } # if pbsdcp-scatter is not available but there's a node file, use rcp elsif ( defined($ENV{'PBS_NODEFILE'}) && -s $ENV{'PBS_NODEFILE'} ) { open(NODES,"uniq ".$ENV{'PBS_NODEFILE'}." |"); @node=; chop(@node); if ( $#node>0 ) { for ( $i=0 ; $i<=$#node; $i++ ) { if ( ($pid[$i]=fork)==0 ) { exec("rcp @ARGV $node[$i]:$target\n"); } } for ( $i=0 ; $i<=$#node; $i++ ) { waitpid($pid[$i],0); } } else { exec("cp @ARGV $target"); } } # if all else fails, just use cp else { exec("cp @ARGV $target"); } } } }