# Evolution
#------------------------------------------------------------------------------
if myid == 0 and verbose: print 'EVOLVE'

barrier()
t0 = time.time()
for t in domain.evolve(yieldstep=yieldstep, finaltime=finaltime):
    if myid == 0:
        domain.write_time()

barrier()

for p in range(numprocs):
    if myid == p:
        print 'Processor %g ' % myid
        print 'That took %.2f seconds' % (time.time() - t0)
        print 'Communication time %.2f seconds' % domain.communication_time
        print 'Reduction Communication time %.2f seconds' % domain.communication_reduce_time
        print 'Broadcast time %.2f seconds' % domain.communication_broadcast_time
    else:
        pass

    barrier()

#--------------------------------------------------
# Merge the individual sww files into one file
#--------------------------------------------------
domain.sww_merge(delete_old=False)

finalize()
    p.sort_stats('time').print_stats(25)

    #p.print_stats()

# Run evolve loop
#result = profiler.runctx(s, globals(), locals())

#result.dump_stats("profile." + str(numprocs) + "." + str(myid) + ".dat")
#profiler.close()

barrier()

for p in range(numprocs):
    if myid == p:
        print 'Process ID %g' %myid
        print 'Number of processors %g ' %numprocs
        print 'That took %.2f seconds' %(time.time()-t0)
        print 'Communication time %.2f seconds'%domain.communication_time
        print 'Reduction Communication time %.2f seconds'%domain.communication_reduce_time
        print 'Broadcast time %.2f seconds'%domain.communication_broadcast_time

    barrier()


finalize()