Last active
November 17, 2019 19:21
-
-
Save keichi/b9888afcf32443a916266540e9bde38d to your computer and use it in GitHub Desktop.
ADIOS2 Multi-block write test
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
cmake_minimum_required(VERSION 3.10) | |
set(CMAKE_CXX_STANDARD 11) | |
project(test C CXX) | |
find_package(MPI REQUIRED) | |
find_package(ADIOS2 REQUIRED) | |
# We are not using the C++ API of MPI, this will stop the compiler look for it | |
add_definitions(-DOMPI_SKIP_MPICXX -DMPICH_SKIP_MPICXX) | |
add_executable(writer writer.cpp) | |
target_link_libraries(writer adios2::adios2 MPI::MPI_C) | |
add_executable(reader reader.cpp) | |
target_link_libraries(reader adios2::adios2 MPI::MPI_C) |
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
#include <iostream> | |
#include <vector> | |
#include <mpi.h> | |
#include <adios2.h> | |
int main(int argc, char **argv) | |
{ | |
MPI_Init(&argc, &argv); | |
int rank, procs, wrank; | |
MPI_Comm_rank(MPI_COMM_WORLD, &wrank); | |
const unsigned int color = 2; | |
MPI_Comm comm; | |
MPI_Comm_split(MPI_COMM_WORLD, color, wrank, &comm); | |
MPI_Comm_rank(comm, &rank); | |
MPI_Comm_size(comm, &procs); | |
adios2::ADIOS adios(comm, adios2::DebugON); | |
adios2::IO io = adios.DeclareIO("SimulationOutput"); | |
// io.SetEngine("BPFile"); | |
// io.SetEngine("SST"); | |
io.SetEngine("InSituMPI"); | |
// io.SetParameter("verbose", "5"); | |
adios2::Engine reader = io.Open("a.bp", adios2::Mode::Read); | |
std::vector<double> u(12); | |
reader.BeginStep(); | |
adios2::Variable<double> var = io.InquireVariable<double>("u"); | |
std::cout << "Shape: " << var.Shape()[0] << std::endl; | |
std::cout << "Count: " << var.Count()[0] << std::endl; | |
for (size_t i = 0; i < 4; i++) { | |
var.SetSelection({{i * 3}, {3}}); | |
reader.Get(var, u.data() + i * 3); | |
} | |
reader.EndStep(); | |
std::cout << "Received u is: "; | |
for (size_t i = 0; i < u.size(); i++) { | |
std::cout << u[i] << " "; | |
} | |
std::cout << std::endl; | |
reader.Close(); | |
MPI_Finalize(); | |
} |
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
#include <vector> | |
#include <mpi.h> | |
#include <adios2.h> | |
int main(int argc, char **argv) | |
{ | |
MPI_Init(&argc, &argv); | |
int rank, procs, wrank; | |
MPI_Comm_rank(MPI_COMM_WORLD, &wrank); | |
const unsigned int color = 1; | |
MPI_Comm comm; | |
MPI_Comm_split(MPI_COMM_WORLD, color, wrank, &comm); | |
MPI_Comm_rank(comm, &rank); | |
MPI_Comm_size(comm, &procs); | |
adios2::ADIOS adios(comm, adios2::DebugON); | |
adios2::IO io = adios.DeclareIO("SimulationOutput"); | |
// io.SetEngine("BPFile"); | |
// io.SetEngine("SST"); | |
io.SetEngine("InSituMPI"); | |
// io.SetParameter("verbose", "5"); | |
adios2::Variable<double> var = io.DefineVariable<double>("u", {12}, {0}, {12}); | |
adios2::Engine writer = io.Open("a.bp", adios2::Mode::Write); | |
// Create a 1D array u with 12 elements | |
// Initialize each element with its index | |
std::vector<double> u(12); | |
for (int i = 0; i < 12; i++) { | |
u[i] = i; | |
} | |
// Start time step | |
writer.BeginStep(); | |
// Divide u into four blocks and send them to the reader | |
// Block 0: u[0:2] | |
// Block 1: u[3:5] | |
// Block 2: u[6:8] | |
// Block 3: u[9:11] | |
for (size_t i = 0; i < 4; i++) { | |
var.SetSelection({{i * 3}, {3}}); | |
writer.Put(var, u.data() + i * 3); | |
} | |
writer.EndStep(); | |
writer.Close(); | |
MPI_Finalize(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment