~ubuntu-branches/ubuntu/vivid/adios/vivid-proposed

« back to all changes in this revision

Viewing changes to wrappers/numpy/tests/test_adios_mpi.py

  • Committer: Package Import Robot
  • Author(s): Alastair McKinstry
  • Date: 2014-06-16 23:06:38 UTC
  • mfrom: (15.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20140616230638-cxryhot6b8ge32l6
Tags: 1.7.0-1
* New upstream release.
* Add adios.pc pkgconfig file. adios_config now uses this.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
"""
 
3
Example:
 
4
 
 
5
$ mpiexec -n 4 python ./test_adios_mpi.py
 
6
"""
 
7
from __future__ import print_function
 
8
import adios_mpi as ad
 
9
import numpy as np
 
10
from mpi4py import MPI
 
11
 
 
12
## Init
 
13
comm = MPI.COMM_WORLD
 
14
rank = comm.Get_rank()
 
15
size = comm.Get_size()
 
16
 
 
17
## Writing
 
18
print ("\n>>> Writing ... (rank = %d)\n" % rank)
 
19
 
 
20
ad.init("config_mpi.xml", comm)
 
21
fd = ad.open("temperature", "adios_test_mpi.bp", "w", comm)
 
22
 
 
23
NX = 10
 
24
groupsize =  4 + 4 + 4 + 8 * 1 * NX
 
25
t = np.array(list(range(NX)), dtype=np.float64) + rank*NX
 
26
ad.set_group_size(fd, groupsize)
 
27
ad.write_int(fd, "NX", NX)
 
28
ad.write_int(fd, "rank", rank)
 
29
ad.write_int(fd, "size", size)
 
30
ad.write(fd, "temperature", t)
 
31
ad.close(fd)
 
32
 
 
33
ad.finalize()
 
34
 
 
35
## Reading
 
36
if rank == 0:
 
37
    print( "\n>>> Reading ...\n")
 
38
 
 
39
    f = ad.file("adios_test_mpi.bp", comm=MPI.COMM_SELF)
 
40
    f.printself()
 
41
 
 
42
    v = f.var['temperature']
 
43
    v.printself()
 
44
 
 
45
    val = v.read()
 
46
    print( val)
 
47
    assert (int(sum(sum(val))) == (size*NX-1)*(size*NX)/2)
 
48
    f.close()
 
49
 
 
50
print( "\n>>> Done.\n")
 
51
 
 
52
## Testing
 
53
if rank == 0:
 
54
    print( "\n>>> Test utility functions ...\n")
 
55
 
 
56
    print( "bpls:\n", ad.bpls('adios_test_mpi.bp'))
 
57
    print( "readvar:\n", ad.readvar("adios_test_mpi.bp", "temperature"))
 
58
 
 
59
    print( "\n>>> Done.\n")