gathers.py :  » Development » MPI-Python » pyMPI-2.5b0 » unittest » 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 » unittest » gathers.py
#**************************************************************************#
#* FILE   **************        gathers.py         ************************#
#**************************************************************************#
#* Author: Chris Murray  Martin Casado Tue Feb 19 18:15:03 PST 2002        # 
#**************************************************************************#
#* Test interface and expected behavior of mpi.gather/mpi.allgather        # 
#**************************************************************************#

import mpi
mpi.synchronizeQueuedOutput("/dev/null","/dev/null")
import unittest

#====================================================================
# test out gather()/allgather
#====================================================================
class gathers(unittest.TestCase):
    def testGather(self):

        #decide on targets
        tgts = [0,0,0]
        #tgts = [int(mpi.procs / 3), 0, int(mpi.procs / 2) ]
        
        #values to be gathered
        list1 = [ mpi.rank + 1 ]
        list2 = [0, mpi.rank, mpi.rank*mpi.rank, mpi.rank + 20]
        string1 = "S" + str(mpi.rank % 4) + "FOO"
        tuple1 = ("t")
        tuple2 = ( "fOo", [1,mpi.rank, 3], (0,1) )

        list3 = [] #Test gather where each process passes in a different count
        for x in range(mpi.rank+2):
          list3 += [x]
        longList = range(256)

        #do gathers
        results = [0,0,0, 0,0,0,     0,0]
        results[0] = mpi.gather( list1,   1,  tgts[0])
        results[1] = mpi.gather( list2,   3,  tgts[1])
        results[2] = mpi.gather( string1, 3,  tgts[2])
        results[3] = mpi.gather( tuple1,  1,  tgts[0])
        results[4] = mpi.gather( tuple2,  1,  tgts[1])
        results[5] = mpi.gather( tuple2,  3,  tgts[2])
        results[6] = mpi.gather( list3, mpi.rank+2, tgts[0] )
        results[7] = mpi.gather( longList, 256, tgts[0] )

        #correct answers
        correctAnswers = [0,0,0,      0,0,0,      0,0]
        for x in range(8):
            correctAnswers[x] = []

        for x in range(mpi.procs):
            correctAnswers[0] += [x + 1]
            correctAnswers[1] += [0, x, x*x]
            correctAnswers[2] += ["S", str(x%4), "F"]
            correctAnswers[3] += ["t"]
            correctAnswers[4] += [ "fOo" ]
            correctAnswers[5] += [ "fOo", [1, x, 3], (0,1) ]

            for i in range(x+2):
              correctAnswers[6] += [i]

            correctAnswers[7] = range(256)*mpi.procs
       
        for x in range(8):
            if mpi.rank == tgts[x%3] and results[x] != correctAnswers[x]:
                self.fail(" gather failed on test "+str(x))

            elif mpi.rank != tgts[x%3] and results[x] != None:
                errstr = "gather failed on off-target";
                errstr += "process on test " + str(x)
                self.fail( errstr)

    def testAllGather(self):
            
        #values to be allGathered
        list1 = [ mpi.rank + 1 ]
        list2 = [0, mpi.rank, mpi.rank*mpi.rank, mpi.rank + 20]
        string1 = "S" + str(mpi.rank % 4) + "FOO"
        tuple1 = ["t"]
        tuple2 = [ "fOo", [1,mpi.rank, 3], (0,1) ]
        item1 = str(mpi.rank%10) + "c"
        if mpi.rank%3 == 1:
            item1 = [ str(mpi.rank%10), "c" ]
        if mpi.rank%3 == 2:
            item1 = ( str(mpi.rank%10), "c" )

        #do gathers
        results = [0,0,0,      0,0,0,       0]
        results[0] = mpi.allgather( list1,   1)
        results[1] = mpi.allgather( list2,   3)
        results[2] = mpi.allgather( string1, 3)
        results[3] = mpi.allgather( tuple1,  1)
        results[4] = mpi.allgather( tuple2,  1)
        results[5] = mpi.allgather( tuple2,  3)
        results[6] = mpi.allgather( item1, 2 )

        #correct answers
        correctAnswers = [0,0,0,    0,0,0,    0]
        for x in range(7):
            correctAnswers[x] = []

        for x in range(mpi.procs):
            correctAnswers[0] += [x + 1]
            correctAnswers[1] += [0, x, x*x]
            correctAnswers[2] += ["S", str(x%4), "F"]
            correctAnswers[3] += ["t"]
            correctAnswers[4] += [ "fOo" ]
            correctAnswers[5] += [ "fOo", [1, x, 3], (0,1) ]
        
        for x in range(6):
            if results[x] != correctAnswers[x]:
                self.fail("AllGather failed on test "+str(x))

#====================================================================
# main
#====================================================================

if __name__ == '__main__':
    try:
        unittest.main()
    except:
        pass
    mpi.barrier() # Wait for everyone!
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.