-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4014 from pnorbert/update-python-examples
Python updates
- Loading branch information
Showing
39 changed files
with
848 additions
and
441 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# | ||
# Distributed under the OSI-approved Apache License, Version 2.0. See | ||
# accompanying file Copyright.txt for details. | ||
# | ||
# bpReaderHeatMap2D-bindings.py | ||
# | ||
# | ||
# Created on: Dec 5th, 2017 | ||
# Author: William F Godoy godoywf@ornl.gov | ||
# Norbert Podhorszki pnorbert@ornl.gov | ||
# | ||
|
||
from mpi4py import MPI | ||
import numpy | ||
import adios2.bindings as 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=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", temperatures, shape, start, count, adios2.ConstantDims | ||
) | ||
|
||
obpStream = ioWrite.Open("HeatMap2D_py_bindings.bp", adios2.Mode.Write) | ||
obpStream.BeginStep() | ||
obpStream.Put(varTemperature, temperatures) | ||
obpStream.EndStep() | ||
obpStream.Close() | ||
|
||
|
||
if rank == 0: | ||
ioRead = adios.DeclareIO("ioReader") | ||
|
||
ibpStream = ioRead.Open("HeatMap2D_py_bindings.bp", adios2.Mode.Read, MPI.COMM_SELF) | ||
|
||
ibpStream.BeginStep() | ||
|
||
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(var_inTemperature.Count(), dtype=int) | ||
|
||
ibpStream.Get(var_inTemperature, inTemperatures, adios2.Mode.Sync) | ||
|
||
print("Incoming temperature map") | ||
for i in range(0, inTemperatures.shape[1]): | ||
print(str(inTemperatures[i]) + " ") | ||
|
||
ibpStream.EndStep() | ||
ibpStream.Close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# | ||
# Distributed under the OSI-approved Apache License, Version 2.0. See | ||
# accompanying file Copyright.txt for details. | ||
# | ||
# bpWriter-bindings.py : Low-level Python API example | ||
# Created on: Feb 2, 2017 | ||
# Authors: William F Godoy godoywf@ornl.gov | ||
# Norbert Podhorszki pnorbert@ornl.gov | ||
# | ||
# adios2.bindings gives access to the low level classes that are compiled from the C++ classes | ||
# Only necessary to use this when the adios2 python API is insufficient for some reason | ||
# This example doesn't use anything that is missing from the python API though. | ||
|
||
from mpi4py import MPI | ||
import numpy | ||
import adios2.bindings as adios2 | ||
|
||
# MPI | ||
comm = MPI.COMM_WORLD | ||
rank = comm.Get_rank() | ||
size = comm.Get_size() | ||
|
||
# User data | ||
myArray = numpy.array([0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]) | ||
myArray = myArray + (rank * 10) | ||
Nx = myArray.size | ||
|
||
# ADIOS MPI Communicator | ||
adios = adios2.ADIOS(comm) | ||
|
||
# ADIOS IO | ||
bpIO = adios.DeclareIO("BPFile_N2N") | ||
bpIO.SetEngine("BPFile") | ||
# bpIO.SetParameters( {"Threads" : "2", "ProfileUnits" : "Microseconds", | ||
# "InitialBufferSize" : "17Kb"} ) | ||
bpIOParams = {} | ||
bpIOParams["Threads"] = "2" | ||
bpIOParams["ProfileUnits"] = "Microseconds" | ||
bpIOParams["InitialBufferSize"] = "17Kb" | ||
bpIO.SetParameters(bpIOParams) | ||
|
||
fileID = bpIO.AddTransport("File", {"Library": "fstream"}) | ||
|
||
# ADIOS Variable name, shape, start, offset, constant dims | ||
ioArray = bpIO.DefineVariable( | ||
"bpArray", myArray, [size * Nx], [rank * Nx], [Nx], adios2.ConstantDims | ||
) | ||
|
||
# ADIOS Engine | ||
bpFileWriter = bpIO.Open("bpWriter-py-bindings.bp", adios2.Mode.Write) | ||
bpFileWriter.BeginStep() | ||
bpFileWriter.Put(ioArray, myArray, adios2.Mode.Sync) | ||
bpFileWriter.EndStep() | ||
bpFileWriter.Close() | ||
|
||
# Read content: | ||
# bpls -la bpWriter-py-bindings.bp | ||
# bpls -la bpWriter-py-bindings.bp -d bpArray -n 10 | ||
# bpls -la bpWriter-py-bindings.bp -d bpArray -n 10 -D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.