#!/usr/bin/python

import os
import re
import string


import subprocess
import matplotlib.pyplot as plt



param = [100, 200, 300, 500]
retlist = []
for x in param:
  #param contains the number of intervals

  cmd = ['mpirun', '-np', '2', './cpi', str(x)]
  print cmd
  child = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

  exe_out = child.communicate()[0]

  ret = re.search('wall clock time = (.*)\n', exe_out)

  retlist.append(float(ret.group(1)))


plt.title('Exec. time by number of intervals')
plt.ylabel('Seconds')
plt.xlabel('Number of intervals')
p1 = plt.plot(param, retlist, 'ro-', label = 'Exec. time')
plt.legend([p1], ['Exec. time'], loc=2)
plt.savefig('plot.pdf', format='pdf')

