Skip to content

Commit

Permalink
Add a simple pdi example and remove pdi from other examples (#717)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpadioleau authored Dec 28, 2024
1 parent 95e949b commit 64da3dd
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 72 deletions.
8 changes: 2 additions & 6 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ add_executable(non_uniform_heat_equation non_uniform_heat_equation.cpp)
target_link_libraries(non_uniform_heat_equation PUBLIC DDC::core)

if("${DDC_BUILD_PDI_WRAPPER}")
target_compile_definitions(heat_equation PUBLIC "DDC_EXAMPLE_WITH_PDI")
target_compile_definitions(uniform_heat_equation PUBLIC "DDC_EXAMPLE_WITH_PDI")
target_compile_definitions(non_uniform_heat_equation PUBLIC "DDC_EXAMPLE_WITH_PDI")
target_link_libraries(heat_equation PUBLIC DDC::pdi)
target_link_libraries(uniform_heat_equation PUBLIC DDC::pdi)
target_link_libraries(non_uniform_heat_equation PUBLIC DDC::pdi)
add_executable(pdi_event pdi_event.cpp)
target_link_libraries(pdi_event PUBLIC DDC::core DDC::pdi)
endif()

if("${DDC_BUILD_KERNELS_FFT}")
Expand Down
22 changes: 0 additions & 22 deletions examples/heat_equation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
#include <ddc/ddc.hpp>

#include <Kokkos_Core.hpp>
#if defined(DDC_EXAMPLE_WITH_PDI)
#include <ddc/pdi.hpp>

#include <paraconf.h>
#include <pdi.h>
#endif
//! [includes]


Expand Down Expand Up @@ -80,24 +74,13 @@ void display(double time, ChunkType temp)
std::cout << std::setw(6) << temp_slice(ix);
});
std::cout << " }\n" << std::flush;

#if defined(DDC_EXAMPLE_WITH_PDI)
ddc::PdiEvent("display")
.with("temp", temp)
.and_with("mean_temp", mean_temp)
.and_with("temp_slice", temp_slice);
#endif
}
//! [display]


//! [main-start]
int main(int argc, char** argv)
{
#if defined(DDC_EXAMPLE_WITH_PDI)
auto pdi_conf = PC_parse_string("");
PDI_init(pdi_conf);
#endif
Kokkos::ScopeGuard const kokkos_scope(argc, argv);
ddc::ScopeGuard const ddc_scope(argc, argv);

Expand Down Expand Up @@ -338,9 +321,4 @@ int main(int argc, char** argv)
display(ddc::coordinate(time_domain.back()), ghosted_temp[x_domain][y_domain]);
}
//! [final output]

#if defined(DDC_EXAMPLE_WITH_PDI)
PDI_finalize();
PC_tree_destroy(&pdi_conf);
#endif
}
22 changes: 0 additions & 22 deletions examples/non_uniform_heat_equation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
#include <ddc/ddc.hpp>

#include <Kokkos_Core.hpp>
#if defined(DDC_EXAMPLE_WITH_PDI)
#include <ddc/pdi.hpp>

#include <paraconf.h>
#include <pdi.h>
#endif
//! [includes]

//! [vector_generator]
Expand Down Expand Up @@ -142,22 +136,11 @@ void display(double time, ChunkType temp)
std::cout << std::setw(6) << temp_slice(ix);
});
std::cout << " }\n" << std::flush;

#if defined(DDC_EXAMPLE_WITH_PDI)
ddc::PdiEvent("display")
.with("temp", temp)
.and_with("mean_temp", mean_temp)
.and_with("temp_slice", temp_slice);
#endif
}
//! [display]

int main(int argc, char** argv)
{
#if defined(DDC_EXAMPLE_WITH_PDI)
PC_tree_t pdi_conf = PC_parse_string("");
PDI_init(pdi_conf);
#endif
Kokkos::ScopeGuard const kokkos_scope(argc, argv);
ddc::ScopeGuard const ddc_scope(argc, argv);

Expand Down Expand Up @@ -376,9 +359,4 @@ int main(int argc, char** argv)
ghosted_temp[ddc::DiscreteDomain<DDimX, DDimY>(x_domain, y_domain)]);
}
//! [final output]

#if defined(DDC_EXAMPLE_WITH_PDI)
PDI_finalize();
PC_tree_destroy(&pdi_conf);
#endif
}
77 changes: 77 additions & 0 deletions examples/pdi_event.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (C) The DDC development team, see COPYRIGHT.md file
//
// SPDX-License-Identifier: MIT

#include <string>

#include <ddc/ddc.hpp>
#include <ddc/pdi.hpp>

#include <Kokkos_Core.hpp>
#include <paraconf.h>
#include <pdi.h>

struct DDimX
{
};

struct DDimY
{
};

int main(int argc, char** argv)
{
Kokkos::ScopeGuard const kokkos_scope(argc, argv);
ddc::ScopeGuard const ddc_scope(argc, argv);

std::string const pdi_cfg = R"PDI_CFG(
metadata:
pdi_chunk_label_rank: size_t
pdi_chunk_label_extents:
type: array
subtype: size_t
size: $pdi_chunk_label_rank
data:
pdi_chunk_label:
type: array
subtype: int
size: [ '$pdi_chunk_label_extents[0]', '$pdi_chunk_label_extents[1]' ]
plugins:
decl_hdf5:
- file: 'output.h5'
on_event: some_event
collision_policy: replace_and_warn
write:
- pdi_chunk_label_rank
- pdi_chunk_label_extents
- pdi_chunk_label
)PDI_CFG";

PC_tree_t pdi_conf = PC_parse_string(pdi_cfg.c_str());
PDI_init(pdi_conf);

// Create a new scope to ensure the anonymous `ddc::PdiEvent` object
// will be destroyed before calling `PDI_finalize`
{
ddc::DiscreteDomain<DDimX, DDimY> const
ddom_xy(ddc::DiscreteElement<DDimX, DDimY>(7, 11),
ddc::DiscreteVector<DDimX, DDimY>(3, 5));

ddc::Chunk chunk("ddc_chunk_label", ddom_xy, ddc::HostAllocator<int>());

ddc::parallel_fill(chunk, 3);

// Use the DDC API to expose a read-only 2D `ddc::ChunkSpan`.
// It exposes three related variables:
// - `pdi_chunk_label_rank`, the number of dimensions
// - `pdi_chunk_label_extents`, the size of each dimension
// - `pdi_chunk_label`, the pointer to the raw data
// see `pdi_cfg` for the corresponding PDI types
ddc::PdiEvent("some_event").with("pdi_chunk_label", chunk.span_cview());
}

PDI_finalize();
PC_tree_destroy(&pdi_conf);
}
22 changes: 0 additions & 22 deletions examples/uniform_heat_equation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
#include <ddc/ddc.hpp>

#include <Kokkos_Core.hpp>
#if defined(DDC_EXAMPLE_WITH_PDI)
#include <ddc/pdi.hpp>

#include <paraconf.h>
#include <pdi.h>
#endif
//! [includes]

//! [X-dimension]
Expand Down Expand Up @@ -68,22 +62,11 @@ void display(double time, ChunkType temp)
std::cout << std::setw(6) << temp_slice(ix);
});
std::cout << " }\n" << std::flush;

#if defined(DDC_EXAMPLE_WITH_PDI)
ddc::PdiEvent("display")
.with("temp", temp)
.and_with("mean_temp", mean_temp)
.and_with("temp_slice", temp_slice);
#endif
}
//! [display]

int main(int argc, char** argv)
{
#if defined(DDC_EXAMPLE_WITH_PDI)
PC_tree_t pdi_conf = PC_parse_string("");
PDI_init(pdi_conf);
#endif
Kokkos::ScopeGuard const kokkos_scope(argc, argv);
ddc::ScopeGuard const ddc_scope(argc, argv);

Expand Down Expand Up @@ -281,9 +264,4 @@ int main(int argc, char** argv)
ghosted_temp[ddc::DiscreteDomain<DDimX, DDimY>(x_domain, y_domain)]);
}
//! [final output]

#if defined(DDC_EXAMPLE_WITH_PDI)
PDI_finalize();
PC_tree_destroy(&pdi_conf);
#endif
}

0 comments on commit 64da3dd

Please sign in to comment.