1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/simple.py Sat Sep 15 15:57:34 2007 +0000
1.3 @@ -0,0 +1,40 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +A simple example of a computation performed sequentially.
1.8 +"""
1.9 +
1.10 +import time
1.11 +
1.12 +# Array size.
1.13 +
1.14 +N = 10
1.15 +delay = 1
1.16 +
1.17 +# Main program.
1.18 +
1.19 +if __name__ == "__main__":
1.20 +
1.21 + t = time.time()
1.22 +
1.23 + # Initialise an array.
1.24 +
1.25 + results = [0] * N * N
1.26 +
1.27 + # Perform the work.
1.28 +
1.29 + print "Calculating..."
1.30 + for i in range(0, N):
1.31 + for j in range(0, N):
1.32 + time.sleep(delay)
1.33 + results[i*N+j] = i * N + j
1.34 +
1.35 + # Show the results.
1.36 +
1.37 + print "Time taken:", time.time() - t
1.38 + for i in range(0, N):
1.39 + for result in results[i*N:i*N+N]:
1.40 + print result,
1.41 + print
1.42 +
1.43 +# vim: tabstop=4 expandtab shiftwidth=4