2007-09-15 | paulb | file changeset files shortlog | [project @ 2007-09-15 19:42:24 by paulb] Tidied up the examples. Added more sequential example programs and a program demonstrating usage of the Map class directly. |
paulb@106 | 1 | #!/usr/bin/env python |
paulb@106 | 2 | |
paulb@106 | 3 | """ |
paulb@106 | 4 | A simple example of a computation performed sequentially. |
paulb@106 | 5 | """ |
paulb@106 | 6 | |
paulb@106 | 7 | import time |
paulb@106 | 8 | |
paulb@106 | 9 | # Array size. |
paulb@106 | 10 | |
paulb@106 | 11 | N = 10 |
paulb@106 | 12 | delay = 1 |
paulb@106 | 13 | |
paulb@106 | 14 | # Main program. |
paulb@106 | 15 | |
paulb@106 | 16 | if __name__ == "__main__": |
paulb@106 | 17 | |
paulb@106 | 18 | t = time.time() |
paulb@106 | 19 | |
paulb@106 | 20 | # Initialise an array. |
paulb@106 | 21 | |
paulb@106 | 22 | results = [0] * N * N |
paulb@106 | 23 | |
paulb@106 | 24 | # Perform the work. |
paulb@106 | 25 | |
paulb@106 | 26 | print "Calculating..." |
paulb@106 | 27 | for i in range(0, N): |
paulb@106 | 28 | for j in range(0, N): |
paulb@106 | 29 | time.sleep(delay) |
paulb@106 | 30 | results[i*N+j] = i * N + j |
paulb@106 | 31 | |
paulb@106 | 32 | # Show the results. |
paulb@106 | 33 | |
paulb@106 | 34 | for i in range(0, N): |
paulb@106 | 35 | for result in results[i*N:i*N+N]: |
paulb@106 | 36 | print result, |
paulb@106 | 37 | print |
paulb@106 | 38 | |
paulb@109 | 39 | print "Time taken:", time.time() - t |
paulb@109 | 40 | |
paulb@106 | 41 | # vim: tabstop=4 expandtab shiftwidth=4 |