Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#
# Distributed under the OSI-approved Apache License, Version 2.0. See
# accompanying file Copyright.txt for details.
#
# helloBPReaderHeatMap2D.py
#
#
# Created on: Dec 5th, 2017
# Author: William F Godoy godoywf@ornl.gov
#
from mpi4py import MPI
import numpy
import adios2
# MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()
# User data
Nx = 10
Ny = 10
count = [Nx, Ny]
start = [rank * Nx, 0]
shape = [size * Nx, Ny]
temperatures = numpy.zeros(Nx * Ny, dtype=numpy.int)
for i in range(0, Nx):
iGlobal = start[0] + i
for j in range(0, Ny):
value = iGlobal * shape[1] + j
temperatures[i * Nx + j] = value
print(str(i) + "," + str(j) + " " + str(value))
# ADIOS portion
adios = adios2.ADIOS(comm)
ioWrite = adios.DeclareIO("ioWriter")
varTemperature = ioWrite.DefineVariable("temperature2D", shape,
start, count, adios2.ConstantDims,
temperatures)
obpStream = ioWrite.Open('HeatMap2D_py.bp', adios2.Mode.Write)
obpStream.PutSync(varTemperature, temperatures)
obpStream.Close()
if rank == 0:
ioRead = adios.DeclareIO("ioReader")
ibpStream = ioRead.Open('HeatMap2D_py.bp', adios2.Mode.Read)
var_inTemperature = ioRead.InquireVariable("temperature2D")
if var_inTemperature is not None:
var_inTemperature.SetSelection([[2, 2], [4, 4]])
inSize = var_inTemperature.SelectionSize()
print('Incoming size ' + str(inSize))
inTemperatures = numpy.zeros(inSize, dtype=numpy.int)
ibpStream.GetSync(var_inTemperature, inTemperatures)
print('Incoming temperature map')
for i in range(0, inTemperatures.size):
print(str(inTemperatures[i]) + ' ')
if (i + 1) % 4 == 0:
print()
ibpStream.Close()