~ubuntu-branches/ubuntu/utopic/nwchem/utopic

« back to all changes in this revision

Viewing changes to src/tools/ga-5-2/python/tutorial/pi.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
#!/usr/bin/env python
 
2
"""
 
3
THIS CODE WAS TAKEN FROM mpi4py-1.2.2/demo/compute-pi and converted to use
 
4
Global Arrays and ga.acc().  Thanks Lisandro!
 
5
 
 
6
Parallel PI computation using Remote Memory Access (RMA)
 
7
within Python objects exposing memory buffers (requires NumPy).
 
8
 
 
9
usage::
 
10
 
 
11
  $ mpiexec -n <nprocs> python pi.py
 
12
 
 
13
"""
 
14
from mpi4py import MPI
 
15
from ga4py import ga
 
16
 
 
17
from math   import pi as PI
 
18
from numpy  import ndarray
 
19
import sys
 
20
 
 
21
def get_n():
 
22
    prompt  = "Enter the number of intervals: (0 quits) "
 
23
    try:
 
24
        n = int(raw_input(prompt));
 
25
        if n < 0: n = 0
 
26
    except:
 
27
        n = 0
 
28
    return n
 
29
 
 
30
def comp_pi(n, myrank=0, nprocs=1):
 
31
    h = 1.0 / n;
 
32
    s = 0.0;
 
33
    for i in xrange(myrank + 1, n + 1, nprocs):
 
34
        x = h * (i - 0.5);
 
35
        s += 4.0 / (1.0 + x**2);
 
36
    return s * h
 
37
 
 
38
def prn_pi(pi, PI):
 
39
    message = "pi is approximately %.16f, error is %.16f"
 
40
    print  (message % (pi, abs(pi - PI)))
 
41
 
 
42
nprocs = ga.nnodes()
 
43
myrank = ga.nodeid()
 
44
 
 
45
g_pi = ga.create(ga.C_DBL, [1])
 
46
 
 
47
one_time = False
 
48
if len(sys.argv) == 2:
 
49
    n = int(sys.argv[1])
 
50
    one_time = True
 
51
 
 
52
while True:
 
53
    if not one_time:
 
54
        if myrank == 0:
 
55
            n = get_n()
 
56
            n = ga.brdcst(n)
 
57
        else:
 
58
            n = ga.brdcst(0)
 
59
        if n == 0:
 
60
            break
 
61
    ga.zero(g_pi)
 
62
    mypi = comp_pi(n, myrank, nprocs)
 
63
    ga.acc(g_pi, mypi)
 
64
    ga.sync()
 
65
    if myrank == 0:
 
66
        pi = ga.get(g_pi)[0]
 
67
        prn_pi(pi, PI)
 
68
    if one_time:
 
69
        break
 
70
 
 
71
ga.destroy(g_pi)