#!/usr/bin/env python
from flipper import *
import time

from mpi4py import MPI


comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()

print rank, size

p = flipperDict.flipperDict()
p.readFromFile(sys.argv[1])
patchNum = sys.argv[2]
iStart = p['iStart']
iStop = p['iStop']

delta = (iStop - iStart)/(size-1)

if delta == 0:
    raise ValueError, 'Too many processors for too small a  loop!'

print "delta=", delta

iMin = iStart+rank*delta

iMax = iStart+(rank+1)*delta



if iMax>iStop:
    iMax = iStop
elif (iMax > (iStop - delta)) and iMax <iStop:
    iMax = iStop
    

print "iMin,iMax,rank", iMin,iMax,rank


for i in xrange(iMin,iMax):
    print "lmcAnnularFilt in iteration %03d"%i
    os.system("lmcAnnularFilt %s %03d %s %s %s %s %s"%(sys.argv[1],i,patchNum,'all','all',sys.argv[3],sys.argv[4]))
    
    
