CSC352 gatherResultsMonteCarlo.py
--D. Thiebaut 00:55, 16 February 2010 (UTC)
#! /usr/bin/env python
# gatherResults.py
# D. Thiebaut
# Typical use
# for i in {1..N}; do
# xgrid -job submit montecarlo.py 10000 done | getXGridOutput.py | gatherResults.py
#
# Command to submit 15 jobs:
# for i in {1..N}; do xgrid -job submit montecarlo.py 10000; done | getXGridOutput.py
#
# Output:
# Job 862 stopped: Execution time: 0.000000 seconds
# ------------------------------
# N= 10000
# pi= 3.1232
# Job 863 stopped: Execution time: 0.000000 seconds
# ------------------------------
# ...
# Job 876 stopped: Execution time: 0.000000 seconds
# ------------------------------
# N= 10000
# pi= 3.1448
#
# Total execution time: 2.000000 seconds
#
# This program will take the output above and parse it and extract all the
# values of pi and will return the average.
import sys
pis = []
# get the lines generated by getXGridOutput.py
for line in sys.stdin:
print line, # print line for user to see
# look for pi
if line.find( "pi=" ) != -1:
pi = float( line.split( '=' )[-1] )
pis.append( pi )
continue
# get total execution time
if line.find( "Total execution" )!= -1:
totalExec = float( line.split( )[3] )
# we're done reading the output. Pring summary
print "Average pi = ", sum( pis )/len( pis )
print "Total Execution time = ", totalExec