From c21ec60b4839526ad628102040f42c04f472add3 Mon Sep 17 00:00:00 2001 From: Marcel Stimberg Date: Fri, 13 Sep 2024 15:59:26 +0200 Subject: [PATCH] Re-add write sizes of dynamic arrays to disk Changes from commit fe0add72821 got lost in merge --- .../cpp_standalone/templates/objects.cpp | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/brian2/devices/cpp_standalone/templates/objects.cpp b/brian2/devices/cpp_standalone/templates/objects.cpp index fab6bf3a0..411a29500 100644 --- a/brian2/devices/cpp_standalone/templates/objects.cpp +++ b/brian2/devices/cpp_standalone/templates/objects.cpp @@ -277,15 +277,21 @@ void _write_arrays() outfile_{{varname}}.open(results_dir + "{{get_array_filename(var)}}", ios::binary | ios::out); if(outfile_{{varname}}.is_open()) { - if (! {{varname}}.empty() ) - { - outfile_{{varname}}.write(reinterpret_cast(&{{varname}}[0]), {{varname}}.size()*sizeof({{varname}}[0])); - outfile_{{varname}}.close(); - } + outfile_{{varname}}.write(reinterpret_cast(&{{varname}}[0]), {{varname}}.size()*sizeof({{varname}}[0])); + outfile_{{varname}}.close(); } else { std::cout << "Error writing output file for {{varname}}." << endl; } + outfile_{{varname}}.open("{{get_array_filename(var) | replace('\\', '\\\\')}}_size", ios::out); + if (outfile_{{varname}}.is_open()) + { + outfile_{{varname}} << {{varname}}.size(); + outfile_{{varname}}.close(); + } else + { + std::cout << "Error writing size file for {{varname}}." << endl; + } {% endfor %} {% for var, varname in dynamic_array_2d_specs | dictsort(by='value') %} @@ -305,6 +311,15 @@ void _write_arrays() { std::cout << "Error writing output file for {{varname}}." << endl; } + outfile_{{varname}}.open("{{get_array_filename(var) | replace('\\', '\\\\')}}_size", ios::out); + if (outfile_{{varname}}.is_open()) { + outfile_{{varname}} << {{varname}}.n << " " << {{varname}}.m; + outfile_{{varname}}.close(); + } else + { + std::cout << "Error writing size file for {{varname}}." << endl; + } + {% endfor %} {% if profiled_codeobjects is defined and profiled_codeobjects %} // Write profiling info to disk