Skip to content

Commit

Permalink
Fix a dangling pointer expose to PDI
Browse files Browse the repository at this point in the history
Also use PDI in heat_equation to test it
Fix #234
  • Loading branch information
jbigot authored and tpadioleau committed Nov 24, 2023
1 parent 0f72c16 commit 30acebf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SPDX-License-Identifier: MIT

add_executable(heat_equation heat_equation.cpp)
target_link_libraries(heat_equation PUBLIC DDC::DDC)
target_link_libraries(heat_equation PUBLIC DDC::DDC DDC::PDI_Wrapper)
if("${BUILD_FFT_KERNEL}")
add_executable(heat_equation_spectral heat_equation_spectral.cpp)
target_link_libraries(heat_equation_spectral PUBLIC DDC::DDC)
Expand Down
8 changes: 8 additions & 0 deletions examples/heat_equation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,19 @@ void display(double time, ChunkType temp)
std::cout << std::setw(6) << temp_slice(ix);
});
std::cout << " }" << std::endl;

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


//! [main-start]
int main(int argc, char** argv)
{
PDI_init(PC_parse_string(""));
ddc::ScopeGuard scope(argc, argv);

// some parameters that would typically be read from some form of
Expand Down Expand Up @@ -331,4 +337,6 @@ int main(int argc, char** argv)
ghosted_temp[x_domain][y_domain]);
}
//! [final output]

PDI_finalize();
}
17 changes: 15 additions & 2 deletions include/ddc/pdi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

#pragma once

#include <memory_resource>
#include <string>
#include <type_traits>

#include <pdi.h>

#include "ddc/chunk_span.hpp"
#include "ddc/discrete_domain.hpp"

namespace ddc {

Expand All @@ -26,6 +28,9 @@ class PdiEvent

std::vector<std::string> m_names;

/// a memory buffer where temporary variables are stored until the class is destroyed
std::pmr::monotonic_buffer_resource m_metadata;

public:
PdiEvent(std::string const& event_name) : m_event(event_name) {}

Expand All @@ -42,10 +47,18 @@ class PdiEvent
!(access & PDI_IN) || (chunk_default_access_v<BorrowedChunk> & PDI_IN),
"Invalid access for constant data");
auto extents = detail::array(data.domain().extents());
size_t rank = extents.size();
size_t& rank = *std::pmr::polymorphic_allocator<size_t>(&m_metadata).allocate(1);
rank = data.domain().extents().size();
PDI_share((name + "_rank").c_str(), &rank, PDI_OUT);
m_names.push_back(name + "_rank");
PDI_share((name + "_extents").c_str(), extents.data(), PDI_OUT);
PDI_share(
(name + "_extents").c_str(),
std::
vector(extents.begin(),
extents.end(),
std::pmr::polymorphic_allocator<size_t>(&m_metadata))
.data(),
PDI_OUT);
m_names.push_back(name + "_extents");
PDI_share(
name.c_str(),
Expand Down

0 comments on commit 30acebf

Please sign in to comment.