Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions doc/source/programmingguide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,27 @@ It may also be useful to implement debug-only safeguards with custom logic that
fit `RUNTIME_CHECK_*` macros. This can be achieved by using the compiler directive
`#ifdef RUNTIME_CHECKS` directly.

Dump an array to a file
-----------------------

It is usually difficult to know what Idefix arrays effectively contains, especially when running on GPU.
To help with this difficulty, Idefix provides a global function ``DumpArray`` that can be used
to dump a ``IdefixArray`` to a numpy file (that can be read from python). This feature can be used
for debugging purpose as:


.. code-block:: c++

#include "idefix.hpp"

IdefixArray3D<real> myArray("debugMe",10,10,10);

idfx::DumpArray("myFilename.npy",myArray); // Dump the array content to a numpy file named "myFilename.npy"


Note that the array is automatically transfered from the GPU, if needed.


Minimal skeleton
================

Expand Down
15 changes: 15 additions & 0 deletions src/global.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <string>
#include <vector>
#include "arrays.hpp"
#include "npy.hpp"

namespace idfx {
int initialize(); // Initialisation routine for idefix
Expand Down Expand Up @@ -44,6 +45,20 @@ IdefixArray1D<T> ConvertVectorToIdefixArray(std::vector<T> &inputVector) {
return(outArr);
}

///< dump Idefix array to a numpy array on disk
template<typename ArrayType>
void DumpArray(std::string filename, ArrayType array) {
auto hArray = Kokkos::create_mirror(array);
Kokkos::deep_copy(hArray, array);

std::array<uint64_t, ArrayType::rank> shape;
bool fortran_order{false};
for (size_t i = 0; i < ArrayType::rank; ++i) {
shape[i] = array.extent(i);
}
npy::SaveArrayAsNumpy(filename, fortran_order, ArrayType::rank, shape.data(), hArray.data());
}

} // namespace idfx

class idfx::IdefixOutStream {
Expand Down