~ubuntu-branches/ubuntu/trusty/nwchem/trusty-proposed

« back to all changes in this revision

Viewing changes to src/tools/ga-5-2/python/tutorial/transp1D.answer.py

  • Committer: Package Import Robot
  • Author(s): Michael Banck, Daniel Leidert, Andreas Tille, Michael Banck
  • Date: 2013-07-04 12:14:55 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130704121455-5tvsx2qabor3nrui
Tags: 6.3-1
* New upstream release.
* Fixes anisotropic properties (Closes: #696361).
* New features include:
  + Multi-reference coupled cluster (MRCC) approaches
  + Hybrid DFT calculations with short-range HF 
  + New density-functionals including Minnesota (M08, M11) and HSE hybrid
    functionals
  + X-ray absorption spectroscopy (XAS) with TDDFT
  + Analytical gradients for the COSMO solvation model
  + Transition densities from TDDFT 
  + DFT+U and Electron-Transfer (ET) methods for plane wave calculations
  + Exploitation of space group symmetry in plane wave geometry optimizations
  + Local density of states (LDOS) collective variable added to Metadynamics
  + Various new XC functionals added for plane wave calculations, including
    hybrid and range-corrected ones
  + Electric field gradients with relativistic corrections 
  + Nudged Elastic Band optimization method
  + Updated basis sets and ECPs 

[ Daniel Leidert ]
* debian/watch: Fixed.

[ Andreas Tille ]
* debian/upstream: References

[ Michael Banck ]
* debian/upstream (Name): New field.
* debian/patches/02_makefile_flags.patch: Refreshed.
* debian/patches/06_statfs_kfreebsd.patch: Likewise.
* debian/patches/07_ga_target_force_linux.patch: Likewise.
* debian/patches/05_avoid_inline_assembler.patch: Removed, no longer needed.
* debian/patches/09_backported_6.1.1_fixes.patch: Likewise.
* debian/control (Build-Depends): Added gfortran-4.7 and gcc-4.7.
* debian/patches/10_force_gcc-4.7.patch: New patch, explicitly sets
  gfortran-4.7 and gcc-4.7, fixes test suite hang with gcc-4.8 (Closes:
  #701328, #713262).
* debian/testsuite: Added tests for COSMO analytical gradients and MRCC.
* debian/rules (MRCC_METHODS): New variable, required to enable MRCC methods.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
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)
 
4
 
 
5
"""
 
6
import mpi4py.MPI
 
7
from ga4py import ga
 
8
import numpy as np
 
9
 
 
10
# Find local processor ID and number of processors.
 
11
me = ga.nodeid()
 
12
nprocs = ga.nnodes()
 
13
 
 
14
TOTALELEMS = 197
 
15
 
 
16
def verify(g_a, g_b):
 
17
    a = ga.get(g_a)
 
18
    b = ga.get(g_b)
 
19
    if not np.all(a[::-1] == b):
 
20
        print "Mismatch: a[::-1] is not equal to b"
 
21
        ga.error("verify failed")
 
22
    print "Transpose OK"
 
23
 
 
24
def TRANSPOSE1D():
 
25
    # Configure array dimensions. Force an unequal data distribution.
 
26
    dims = [nprocs*TOTALELEMS + nprocs/2]
 
27
    chunk = [TOTALELEMS] # minimum data on each process
 
28
 
 
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"
 
33
 
 
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"
 
37
 
 
38
    # initialize data in g_a
 
39
    if not me:
 
40
        print "Initializing matrix A"
 
41
        ga.put(g_a, np.arange(dims[0], dtype=np.int32))
 
42
 
 
43
    # Synchronize all processors to guarantee that everyone has data
 
44
    # before proceeding to the next step.
 
45
    ga.sync()
 
46
 
 
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)
 
50
 
 
51
    # Get locally held data and copy it into local buffer a
 
52
    a = ga.get(g_a, lo, hi)
 
53
 
 
54
    # Invert data locally
 
55
    b = a[::-1]
 
56
 
 
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])
 
60
 
 
61
    # Synchronize all processors to make sure inversion is complete
 
62
    ga.sync()
 
63
 
 
64
    # Check to see if inversion is correct
 
65
    if not me: verify(g_a, g_b)
 
66
 
 
67
    # Deallocate arrays
 
68
    ga.destroy(g_a)
 
69
    ga.destroy(g_b)
 
70
 
 
71
 
 
72
if __name__ == '__main__':
 
73
    if not me:
 
74
        print "Using %d processes\n" % nprocs
 
75
 
 
76
    TRANSPOSE1D();
 
77
 
 
78
    if not me:
 
79
        print "\nTerminating ..."