''' ========================================================================== Python for Parallelism in Introductory Computer Science Education SC '13 HPC Educators Program Steven Bogaerts, Wittenberg University Joshua Stough, Washington and Lee http://www.joshuastough.com/SC13 MIT License: see README_LICENSE.txt file: parallelHello.py author: stough Summary:A first program with parallelism, showing multiple processes saying hello, each with a different name. You cannot run this through IDLE. You have to go the command line and type $ python[3] parallelHello.py See: http://docs.python.org/library/multiprocessing.html http://docs.python.org/py3k/library/multiprocessing.html ========================================================================== ''' from multiprocessing import Pool #Dependencies defined below main() def main(): """ The main method: -Create a pool of processors -Have the processors run hello(name) for each name in a list of names. """ mypool = Pool(processes=4) #List of the various arguments to send to #the hello function. names = ['anna', 'bob', 'josh', 'ted', 'mia', \ 'john', 'sherry', 'angela', 'kate', 'sam'] #functions called with map here must accept only one #argument. See parallelIntegrate.py for how to #pack arguments. mypool.map(hello, names) #A simple function that prints the argument given. def hello(myname): """ hello: A simple function that prints the argument given. """ print("Hello, my name is " + myname) #Call the main method if run from the command line. if __name__ == '__main__': main()