Example 1: (1 node, batch script)
Example 2: (1 node, perl script)
Example 3: (1 node, python script)
Example 4: (4 nodes, batch scripts, MPI job)
Example 1 (1 node, batch script)
| MyJob.xml |
<?xml version="1.0" ?>
<!-- Sample XML Job File -->
<job>
<nodes>1</nodes>
<minutes>5</minutes>
<type>batch</type>
<affiliation>vplustest</affiliation>
<run>\\tc.cornell.edu\tc\users\your_userid\MyJob.bat</run>
</job>
|
| MyJob.bat |
REM Create a clean local temp folder, T:\myuserid
call TDirCreate.bat
REM Change the current working directory
cd /d T:\%USERNAME%
REM Copy executable and data files to the current working directory
copy h:\users\%USERNAME%\quick.exe
REM Run the program
quick.exe 1>quick.out2>quick.err
REM Copy results back to fileserver
copy /Y quick.* h:\users\%USERNAME%
REM Delete the local temp folder and everything in it
call TDirDelete.bat
REM Release the nodes and end the job
vsched -cancel
|
Example 2 (1 node, perl script)
Note:
When you submit an xml job that runs a perl script, you will always get this warning message:
H:\users\userid > vsched -s quickjob.xml
Warning: Run statement cannot be verified
2073
| MyJob.xml |
<?xml version="1.0" ?>
<!-- Sample XML Job File -->
<job>
<nodes>1</nodes>
<minutes>5</minutes>
<type>batch</type>
<affiliation>vplustest</affiliation>
<run>perl \\tc.cornell.edu\tc\users\your_userid\MyJob.pl</run>
</job>
|
| MyJob.pl |
#Put your executable and data files on the local drive
#
use File::Copy;
$username = $ENV{"USERNAME"};
open(STDOUT, ">\\\\tc.cornell.edu\\tc\\users\\$username\\quickjob.out");
open(STDERR, ">\\\\tc.cornell.edu\\tc\\users\\$username\\quickjob.err");
chdir("T:\\");
$usert = "T:\\$username";
unlink($usert);
if(-d $usert) {
system("rmdir /S /Q $usert");
}
mkdir($usert);
chdir($usert);
copy("\\\\tc.cornell.edu\\tc\\users\\$username\\quick.exe",".");
system("quick.exe 1>quick.out 2>quick.err");
@quickfiles=;
foreach $f (@quickfiles){
copy($f,"\\\\tc.cornell.edu\\tc\\users\\$username\\$f");
}
# Clean the T: drive; if it fills, subsequent jobs will fail
chdir("T:\\");
system("rmdir /S /Q $usert");
# Release the nodes and end the job
system("vsched -cancel");
|
Example 3 (1 node, python script)
Note:
When you submit an xml job that runs a python script, you will always get this warning message:
H:\users\userid > vsched -s quickjob.xml
Warning: Run statement cannot be verified
2073
| MyJob.xml |
<?xml version="1.0" ?>
<!-- Sample XML Job File -->
<job>
<nodes>1</nodes>
<minutes>5</minutes>
<type>batch</type>
<affiliation>vplustest</affiliation>
<run>python \\tc.cornell.edu\tc\users\your_userid\MyJob.py</run>
</job>
|
| MyJob.py |
#Put your executable and data files on the local drive
#
import os, shutil, sys
from subprocess import *
username = os.environ["USERNAME"]
sys.stdout = file("\\\\tc.cornell.edu\\tc\\users\\"+username+"\\quickjob.out", "w")
sys.stderr = file("\\\\tc.cornell.edu\\tc\\users\\"+username+"\\quickjob.err", "w")
os.chdir("T:\\")
usert = "T:\\"+username
try:
os.unlink(usert)
except:
pass
if os.path.isdir(usert):
shutil.rmtree(usert, ignore_errors=True)
os.mkdir(usert)
os.chdir(usert)
shutil.copy("\\\\tc.cornell.edu\\tc\\users\\"+username+"\\quick.exe", ".")
qo = file("quick.out", "w")
qr = file("quick.err", "w")
quick = Popen(["quick.exe"], stdout=qo, stderr=qr)
quick.wait()
qo.close()
qr.close()
quickfiles = [x for x in os.listdir('.') if x.startswith("quick.")]
for f in quickfiles:
shutil.copy(f, "\\\\tc.cornell.edu\\tc\\users\\"+username+"\\"+f)
# Clean the T: drive; if it fills, subsequent jobs will fail
os.chdir("T:\\")
shutil.rmtree(usert, ignore_errors=True)
# Release the nodes and end the job
os.system("vsched -cancel")
|
Example 4 (4 nodes, batch scripts, MPI job)
| MyJob.xml |
<?xml version="1.0" ?>
<!-- Sample XML Job File -->
<job>
<nodes>4</nodes>
<minutes>60</minutes>
<type>batch</type>
<affiliation>vplustest</affiliation>
<run>\\tc.cornell.edu\tc\users\your_userid\your.bat</run>
</job>
|
| wave.bat |
REM Move to the T drive
cd /D T:\
REM Create a file called "machines" on the master node
vsched -m
REM Use mpirun to run the setup script on all nodes in this job
mpirun -np 4 \\tc.cornell.edu\tc\users\%USERNAME%\batch\setup.bat
REM Copy the input file to the master node
copy \\tc.cornell.edu\tc\users\%USERNAME%\batch\wave.in T:\%USERNAME%
REM - - - - At this point, all of the nodes in the job have
REM - - - - the necessary files.
REM Move the machines file from T: to T:\%USERNAME%
cd T:\%USERNAME%
move T:\machines T:\%USERNAME%
REM Run the MPI program with mpirun.
REM Set -np to the number of tasks.
REM -wd is the working directory used by mpirun.
mpirun -wd T:\%USERNAME% -np 8 wavesend.exe 1>waveOutput.txt 2>waveError.txt
REM Copy any output unique to the master task back to the H drive.
copy /y T:\%USERNAME%\wave*.* \\tc.cornell.edu\tc\users\%USERNAME%\batch
REM Use mpirun to run the cleanup script on all nodes in this job
mpirun -np 4 \\tc.cornell.edu\tc\users\%USERNAME%\batch\cleanup.bat
REM Release the nodes
vsched -cancel
|
| setup.bat |
REM setup.bat
REM Create a clean local temp folder, T:\myuserid, on each node
call TDirCreate.bat
REM Copy the executable (and data files, if necessary) to each node
copy \\tc.cornell.edu\tc\users\%USERNAME%\batch\wavesend.exe T:\%USERNAME%
|
| cleanup.bat |
REM cleanup.bat
REM Copy the output files to the H drive.
REM If data files are created on all nodes, be careful
REM to use unique files names, e.g. by naming them from
REM within the program making use of the task id.
REM Note: in this sample code, only the master node has output files.
copy /Y T:\%USERNAME%\wave*.* \\tc.cornell.edu\tc\users\%USERNAME%\batch
REM Delete the local temp folder and everything in it
call TDirDelete.bat
|