-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
858 additions
and
451 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 [email protected] | ||
# Norbert Podhorszki [email protected] | ||
# | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,12 @@ | |
# | ||
# Created on: Dec 5th, 2017 | ||
# Author: William F Godoy [email protected] | ||
# Norbert Podhorszki [email protected] | ||
# | ||
|
||
from mpi4py import MPI | ||
import numpy | ||
import adios2 | ||
from adios2 import Stream | ||
|
||
# MPI | ||
comm = MPI.COMM_WORLD | ||
|
@@ -26,57 +27,27 @@ | |
start = [rank * Nx, 0] | ||
shape = [size * Nx, Ny] | ||
|
||
temperatures = numpy.zeros(Nx * Ny, dtype=numpy.int) | ||
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.bp", adios2.Mode.Write) | ||
obpStream.BeginStep() | ||
obpStream.Put(varTemperature, temperatures) | ||
obpStream.EndStep() | ||
obpStream.Close() | ||
# print(str(i) + "," + str(j) + " " + str(value)) | ||
|
||
with Stream("HeatMap2D_py.bp", "w", comm) as obpStream: | ||
obpStream.write("temperature2D", temperatures, shape, start, count) | ||
|
||
if rank == 0: | ||
ioRead = adios.DeclareIO("ioReader") | ||
|
||
ibpStream = ioRead.Open("HeatMap2D_py.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(inSize, dtype=numpy.int) | ||
|
||
ibpStream.Get(var_inTemperature, inTemperatures, adios2.Mode.Sync) | ||
|
||
print("Incoming temperature map") | ||
|
||
for i in range(0, inTemperatures.size): | ||
print(str(inTemperatures[i]) + " ") | ||
|
||
if (i + 1) % 4 == 0: | ||
print() | ||
|
||
ibpStream.EndStep() | ||
ibpStream.Close() | ||
with Stream("HeatMap2D_py.bp", "r", MPI.COMM_SELF) as ibpStream: | ||
for _ in ibpStream.steps(): | ||
var_inTemperature = ibpStream.inquire_variable("temperature2D") | ||
if var_inTemperature is not None: | ||
var_inTemperature.set_selection([[2, 2], [4, 4]]) | ||
inTemperatures = ibpStream.read(var_inTemperature) | ||
|
||
print("Incoming temperature map") | ||
for i in range(0, inTemperatures.shape[1]): | ||
print(str(inTemperatures[i]) + " ") |
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 [email protected] | ||
# Norbert Podhorszki [email protected] | ||
# | ||
# 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,12 @@ | |
# | ||
# bpWriter.py : only works with MPI version | ||
# Created on: Feb 2, 2017 | ||
# Author: William F Godoy [email protected] | ||
# Authors: William F Godoy [email protected] | ||
# Norbert Podhorszki [email protected] | ||
# | ||
# We use adios2.Adios and adios2.IO classes to set up the IO parameters. | ||
# For default IO, it is sufficient to use the adios2.Stream class alone. | ||
|
||
from mpi4py import MPI | ||
import numpy | ||
import adios2 | ||
|
@@ -16,32 +21,30 @@ | |
|
||
# 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 = adios2.Adios(config_file=None, comm=comm) | ||
|
||
# ADIOS IO | ||
bpIO = adios.DeclareIO("BPFile_N2N") | ||
bpIO.SetEngine("BPFile") | ||
# bpIO.SetParameters( {"Threads" : "2", "ProfileUnits" : "Microseconds", | ||
# "InitialBufferSize" : "17Kb"} ) | ||
bpIO = adios.declare_io("BPFile_N2N") | ||
|
||
bpIOParams = {} | ||
bpIOParams["Threads"] = "2" | ||
bpIOParams["ProfileUnits"] = "Microseconds" | ||
bpIOParams["InitialBufferSize"] = "17Kb" | ||
bpIO.SetParameters(bpIOParams) | ||
bpIO.set_parameters(bpIOParams) | ||
|
||
fileID = bpIO.AddTransport("File", {"Library": "fstream"}) | ||
bpIO.add_transport("File", {"Library": "fstream"}) | ||
bpIO.set_engine("BPFile") | ||
a = bpIO.adios() | ||
|
||
# ADIOS Variable name, shape, start, offset, constant dims | ||
ioArray = bpIO.DefineVariable( | ||
"bpArray", myArray, [size * Nx], [rank * Nx], [Nx], adios2.ConstantDims | ||
) | ||
# ADIOS output stream | ||
with adios2.Stream(bpIO, "bpWriter-py.bp", "w", comm) as fh: | ||
fh.write("bpArray", myArray, [size * Nx], [rank * Nx], [Nx]) | ||
|
||
# ADIOS Engine | ||
bpFileWriter = bpIO.Open("npArray.bp", adios2.Mode.Write) | ||
bpFileWriter.BeginStep() | ||
bpFileWriter.Put(ioArray, myArray, adios2.Mode.Sync) | ||
bpFileWriter.EndStep() | ||
bpFileWriter.Close() | ||
# Read content: | ||
# bpls -la bpWriter-py.bp | ||
# bpls -la bpWriter-py.bp -d bpArray -n 10 | ||
# bpls -la bpWriter-py.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
Oops, something went wrong.