The Pi.pds Example
This example works by running an executable that can be built from [Gridserver SDK dir]\examples\pdriver. Build and deploy the executable using the supplied script.
A single script, pi.pds, runs several tasks, each with a different seed and multiple iterations.
The beginning of pi.pds starts the job block by defining the number of tasks and an output directory for the tasks.
# pi.pds
#
# performs a distributed monte carlo pi calculation.
#
job pijob
tasks = 50
outputdir = "pijob.example.out"
seed = begin 200 count $tasks step 3
iterations = 500000
Next, a task block must be written to run the executable. However, the task must run one of two different binaries, depending on the operating system of the Engine. A conditional is used to check the status of the $DSOS variable. If it is win32, the PdriverPiCalc.exe binary is run, otherwise, pdriverPicalc is run from the $DSOS resources directory. The program takes two parameters: the seed, and the number of iterations. The standard output and standard error from the program is redirected to the work directory. After each task is completed, the output and error output is copied back to the staging directory.
task $tasks
onerror retry
shell "none"
if ( $DSOS == "win32" ) then
execute stdout="$DSWORKDIR/pijob.$DSTASKID.out"
stderr="$DSWORKDIR/error.$DSTASKID"
"${gridLibraryDirWin}\commands\PdriverPiCalc.exe $seed $iterations"
else
execute stdout="$DSWORKDIR/pijob.$DSTASKID.out"
stderr="$DSWORKDIR/error.$DSTASKID"
"${gridLibraryDirUnix}/$DSOS/commands/PdriverPiCalc $seed $iterations"
end
copy "$DSWORKDIR/pijob.$DSTASKID.out" "$DSSTAGEDIR"
copy "$DSWORKDIR/error.$DSTASKID" "$DSSTAGEDIR"
end
After the task block has run 50 times, the postjob block is run. It processes the output of each task with a pi-average-win32.bat or pi-average-unix.sh script.
postjob
onerror ignore
mkdir "$outputdir"
copy "$DSSTAGEDIR/pijob.*" "$outputdir"
if ( $DSOS == "win32" ) then
execute stdout="PIVALUE.OUT"
"""%DS_SDK_DIR%\examples\pdriver\pi-average-win32.bat"" $outputdir"
else
execute stdout="PIVALUE.OUT"
"$$DS_SDK_DIR/examples/pdriver/pi-average-unix.sh $outputdir $tasks"
end
end
end job