pingpongtest.py :  » Development » MPI-Python » pyMPI-2.5b0 » scaling » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » MPI Python 
MPI Python » pyMPI 2.5b0 » scaling » pingpongtest.py
import sys
from time import sleep,asctime
import mpi
from mpi import time
import copy

import pingpong

def PRINTF(fd,fmt,*args):
     if args:
          s = fmt%args
     else:
          s = fmt
     fd.write(s)
     #sys.stdout.write(s)
     return


"""
set logscale x 2
set logscale y

plot "pingpong.plt" using 1:2 title "pyMPI" with linespoints, "pingpong.plt" using 1:4 title "C" with linespoints
"""

# Randomly split into senders and receivers
if mpi.rank == 0:
     import random
     ranks = list(range(mpi.size))
     random.shuffle(ranks)
     half = mpi.size/2
     senders = ranks[:half]
     receivers = ranks[half:half*2]
     dead = ranks[half*2:]
     sendmap = dict(zip(senders,receivers))
     recvmap = dict(zip(receivers,senders))

     mpi.bcast(sendmap)
     mpi.bcast(recvmap)
     mpi.bcast(dead)
else:
     sendmap = mpi.bcast()
     recvmap = mpi.bcast()
     dead = mpi.bcast()


runs = 10
k = 25

# Log file
fd = open('pingpong_%d.plt'%mpi.size,'w')
fd.write('# %s\n'%asctime())
fd.write('# %d processors\n'%mpi.size)

# Run various size messages
for power in range(k):
     mpi.barrier()
     n = 2 ** power
     msg = 'a'*n

     python = []
     c = []
     # I am a sender
     if mpi.rank in sendmap.keys():
          dst = sendmap[mpi.rank]
          for run in range(runs):
               mpi.barrier()
               t0 = time()
               x = mpi.send(msg,dst)
               y,status = mpi.recv(dst)
               python.append( time()-t0 )
               del t0
               del x

               mpi.barrier()
               t0 = time()
               x = pingpong.send(n,dst)
               y = pingpong.recv(n,dst)
               c.append( time()-t0 )

               del t0
               del x
               del y
               

     # I am a receiver
     elif mpi.rank in recvmap.keys():
          src = recvmap[mpi.rank]
          for run in range(runs):
               mpi.barrier()
               msg,status = mpi.recv()
               x = mpi.send(msg,src)

               mpi.barrier()
               y = pingpong.recv(n,src)
               z = pingpong.send(n,src)

               del msg
               del status
               del x
               del y
               del z

     # I am the odd one out
     else:
          for run in range(runs):
               mpi.barrier()
               mpi.barrier()

     # Get from all processes
     all_python = mpi.reduce(python,mpi.SUM)
     all_c = mpi.reduce(c,mpi.SUM)

     if all_python and all_c and mpi.rank == 0:
          if half:
               divisor = half
          else:
               divisor = 1

          if runs > 1:
               all_python = all_python[1:]
               all_c = all_c[1:]
               
          best_python = min(all_python)
          worst_python = max(all_python)
          avg_python = reduce(lambda x,y: x+y, all_python)/runs

          best_c = min(all_c)
          worst_c = max(all_c)
          avg_c = reduce(lambda x,y: x+y, all_c)/runs

          PRINTF(fd,'%8d ',n)
          for t in [best_python,best_c,worst_python,worst_c,avg_python,avg_c]:
               try:
                    bps = n/t
               except:
                    bps = 0
               PRINTF(fd,' %8.6f %8.0f',t,bps)
          PRINTF(fd,'\n')
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.