2
transpose of 1-d array.
3
e.g. (1 2 3 4 5 6 7 8 9 10) => (10 9 8 7 6 5 4 3 2 1)
10
# Find local processor ID and number of processors.
19
if not np.all(a[::-1] == b):
20
print "Mismatch: a[::-1] is not equal to b"
21
ga.error("verify failed")
25
# Configure array dimensions. Force an unequal data distribution.
26
dims = [nprocs*TOTALELEMS + nprocs/2]
27
chunk = [TOTALELEMS] # minimum data on each process
29
# create a global array g_a and duplicate it to get g_b
30
g_a = ga.create(ga.C_INT, dims, "array A", chunk)
31
if not g_a: ga.error("create failed: A")
32
if not me: print "Created Array A"
34
g_b = ga.duplicate(g_a, "array B")
35
if not g_b: ga.error("duplicate failed")
36
if not me: print "Created Array B"
38
# initialize data in g_a
40
print "Initializing matrix A"
41
ga.put(g_a, np.arange(dims[0], dtype=np.int32))
43
# Synchronize all processors to guarantee that everyone has data
44
# before proceeding to the next step.
47
# Start initial phase of inversion by inverting the data held locally on
48
# each processor. Start by finding out which data each processor owns.
49
lo,hi = ga.distribution(g_a)
51
# Get locally held data and copy it into local buffer a
52
a = ga.get(g_a, lo, hi)
57
# Invert data globally by copying locally inverted blocks into
58
# their inverted positions in the GA
59
ga.put(g_b, b, dims[0]-hi[0], dims[0]-lo[0])
61
# Synchronize all processors to make sure inversion is complete
64
# Check to see if inversion is correct
65
if not me: verify(g_a, g_b)
72
if __name__ == '__main__':
74
print "Using %d processes\n" % nprocs
79
print "\nTerminating ..."