From 990b33ac2c824f9ae8b9725a57a937b8f3a20fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Tue, 28 Jun 2022 15:03:29 +0200 Subject: [PATCH] Use overload in examples --- examples/10_streaming_write.cpp | 3 +- examples/13_write_dynamic_configuration.cpp | 3 +- examples/7_extended_write_serial.cpp | 18 ++----- examples/8a_benchmark_write_parallel.cpp | 10 ++-- examples/8b_benchmark_read_parallel.cpp | 2 +- test/ParallelIOTest.cpp | 7 ++- test/SerialIOTest.cpp | 52 ++++++--------------- 7 files changed, 29 insertions(+), 66 deletions(-) diff --git a/examples/10_streaming_write.cpp b/examples/10_streaming_write.cpp index 1c12e034f1..f114534727 100644 --- a/examples/10_streaming_write.cpp +++ b/examples/10_streaming_write.cpp @@ -26,8 +26,7 @@ int main() constexpr unsigned long length = 10ul; Extent global_extent = {length}; Dataset dataset = Dataset(datatype, global_extent); - std::shared_ptr local_data( - new position_t[length], [](position_t const *ptr) { delete[] ptr; }); + std::shared_ptr local_data(new position_t[length]); WriteIterations iterations = series.writeIterations(); for (size_t i = 0; i < 100; ++i) diff --git a/examples/13_write_dynamic_configuration.cpp b/examples/13_write_dynamic_configuration.cpp index 06ef1e8e77..2f0f883d24 100644 --- a/examples/13_write_dynamic_configuration.cpp +++ b/examples/13_write_dynamic_configuration.cpp @@ -72,8 +72,7 @@ chunks = "auto" constexpr unsigned long length = 10ul; Extent global_extent = {length}; Dataset dataset = Dataset(datatype, global_extent); - std::shared_ptr local_data( - new position_t[length], [](position_t const *ptr) { delete[] ptr; }); + std::shared_ptr local_data(new position_t[length]); WriteIterations iterations = series.writeIterations(); for (size_t i = 0; i < 100; ++i) diff --git a/examples/7_extended_write_serial.cpp b/examples/7_extended_write_serial.cpp index 62d8752a6e..662772badf 100644 --- a/examples/7_extended_write_serial.cpp +++ b/examples/7_extended_write_serial.cpp @@ -93,11 +93,7 @@ int main() // data is assumed to reside behind a pointer as a contiguous // column-major array shared data ownership during IO is indicated with // a smart pointer - std::shared_ptr partial_mesh( - new double[5], [](double const *p) { - delete[] p; - p = nullptr; - }); + std::shared_ptr partial_mesh(new double[5]); // before storing record data, you must specify the dataset once per // component this describes the datatype and shape of data as it should @@ -130,20 +126,12 @@ int main() io::ParticleSpecies electrons = cur_it.particles["electrons"]; io::Extent mpiDims{4}; - std::shared_ptr partial_particlePos( - new float[2], [](float const *p) { - delete[] p; - p = nullptr; - }); + std::shared_ptr partial_particlePos(new float[2]); dtype = io::determineDatatype(partial_particlePos); d = io::Dataset(dtype, mpiDims); electrons["position"]["x"].resetDataset(d); - std::shared_ptr partial_particleOff( - new uint64_t[2], [](uint64_t const *p) { - delete[] p; - p = nullptr; - }); + std::shared_ptr partial_particleOff(new uint64_t[2]); dtype = io::determineDatatype(partial_particleOff); d = io::Dataset(dtype, mpiDims); electrons["positionOffset"]["x"].resetDataset(d); diff --git a/examples/8a_benchmark_write_parallel.cpp b/examples/8a_benchmark_write_parallel.cpp index f28676e143..d6cddb6650 100644 --- a/examples/8a_benchmark_write_parallel.cpp +++ b/examples/8a_benchmark_write_parallel.cpp @@ -180,10 +180,10 @@ class Timer */ template -std::shared_ptr +std::shared_ptr createDataCPU(const unsigned long &size, const T &val, const T &increment) { - auto E = std::shared_ptr{new T[size], [](T *d) { delete[] d; }}; + auto E = std::shared_ptr{new T[size]}; for (unsigned long i = 0ul; i < size; i++) { @@ -197,7 +197,7 @@ createDataCPU(const unsigned long &size, const T &val, const T &increment) #if openPMD_HAVE_CUDA_EXAMPLES template -std::shared_ptr +std::shared_ptr createDataGPU(const unsigned long &size, const T &val, const T &increment) { auto myCudaMalloc = [](size_t mySize) { @@ -206,7 +206,7 @@ createDataGPU(const unsigned long &size, const T &val, const T &increment) return ptr; }; auto deleter = [](T *ptr) { cudaFree(ptr); }; - auto E = std::shared_ptr{(T *)myCudaMalloc(size * sizeof(T)), deleter}; + auto E = std::shared_ptr{(T *)myCudaMalloc(size * sizeof(T)), deleter}; T *data = new T[size]; for (unsigned long i = 0ul; i < size; i++) @@ -222,7 +222,7 @@ createDataGPU(const unsigned long &size, const T &val, const T &increment) #endif template -std::shared_ptr +std::shared_ptr createData(const unsigned long &size, const T &val, const T &increment) { #if openPMD_HAVE_CUDA_EXAMPLES diff --git a/examples/8b_benchmark_read_parallel.cpp b/examples/8b_benchmark_read_parallel.cpp index 3809707a72..f5695cefc9 100644 --- a/examples/8b_benchmark_read_parallel.cpp +++ b/examples/8b_benchmark_read_parallel.cpp @@ -178,7 +178,7 @@ template std::shared_ptr createData(const unsigned long &size, const T &val, bool increment = false) { - auto E = std::shared_ptr{new T[size], [](T *d) { delete[] d; }}; + auto E = std::shared_ptr{new T[size]}; for (unsigned long i = 0ul; i < size; i++) { diff --git a/test/ParallelIOTest.cpp b/test/ParallelIOTest.cpp index 4f9c2acb3c..b3989385a1 100644 --- a/test/ParallelIOTest.cpp +++ b/test/ParallelIOTest.cpp @@ -154,8 +154,7 @@ void write_test_zero_extent( position_global.begin(), position_global.end(), [&pos] { return pos++; }); - std::shared_ptr position_local( - new double[rank], [](double const *p) { delete[] p; }); + std::shared_ptr position_local(new double[rank]); uint64_t offset; if (rank != 0) offset = ((rank - 1) * (rank - 1) + (rank - 1)) / 2; @@ -171,8 +170,8 @@ void write_test_zero_extent( positionOffset_global.begin(), positionOffset_global.end(), [&posOff] { return posOff++; }); - std::shared_ptr positionOffset_local( - new uint64_t[rank], [](uint64_t const *p) { delete[] p; }); + std::shared_ptr positionOffset_local( + new uint64_t[rank]); e["positionOffset"]["x"].resetDataset( Dataset(determineDatatype(positionOffset_local), {num_cells})); diff --git a/test/SerialIOTest.cpp b/test/SerialIOTest.cpp index 6846ee0f14..83387788c1 100644 --- a/test/SerialIOTest.cpp +++ b/test/SerialIOTest.cpp @@ -651,8 +651,7 @@ void close_and_copy_attributable_test(std::string file_ending) constexpr unsigned long length = 10ul; Extent global_extent = {length}; Dataset dataset = Dataset(datatype, global_extent); - std::shared_ptr local_data( - new position_t[length], [](position_t const *ptr) { delete[] ptr; }); + std::shared_ptr local_data(new position_t[length]); std::unique_ptr iteration_ptr; for (size_t i = 0; i < 100; i += 10) @@ -880,8 +879,7 @@ inline void constant_scalar(std::string file_ending) E_x.makeConstant(static_cast(13.37)); auto E_y = s.iterations[1].meshes["E"]["y"]; E_y.resetDataset(Dataset(Datatype::UINT, {1, 2, 3})); - std::shared_ptr E( - new unsigned int[6], [](unsigned int const *p) { delete[] p; }); + std::shared_ptr E(new unsigned int[6]); unsigned int e{0}; std::generate(E.get(), E.get() + 6, [&e] { return e++; }); E_y.storeChunk(E, {0, 0, 0}, {1, 2, 3}); @@ -915,9 +913,7 @@ inline void constant_scalar(std::string file_ending) vel_x.makeConstant(static_cast(-1)); auto vel_y = s.iterations[1].particles["e"]["velocity"]["y"]; vel_y.resetDataset(Dataset(Datatype::ULONGLONG, {3, 2, 1})); - std::shared_ptr vel( - new unsigned long long[6], - [](unsigned long long const *p) { delete[] p; }); + std::shared_ptr vel(new unsigned long long[6]); unsigned long long v{0}; std::generate(vel.get(), vel.get() + 6, [&v] { return v++; }); vel_y.storeChunk(vel, {0, 0, 0}, {3, 2, 1}); @@ -1100,10 +1096,7 @@ TEST_CASE("flush_without_position_positionOffset", "[serial]") RecordComponent weighting = e["weighting"][RecordComponent::SCALAR]; weighting.resetDataset(Dataset(Datatype::FLOAT, Extent{2, 2})); weighting.storeChunk( - std::shared_ptr( - new float[4](), [](float const *ptr) { delete[] ptr; }), - {0, 0}, - {2, 2}); + std::shared_ptr(new float[4]()), {0, 0}, {2, 2}); s.flush(); @@ -1114,10 +1107,7 @@ TEST_CASE("flush_without_position_positionOffset", "[serial]") RecordComponent rc = e[key][dim]; rc.resetDataset(Dataset(Datatype::FLOAT, Extent{2, 2})); rc.storeChunk( - std::shared_ptr( - new float[4](), [](float const *ptr) { delete[] ptr; }), - {0, 0}, - {2, 2}); + std::shared_ptr(new float[4]()), {0, 0}, {2, 2}); } } } @@ -2086,11 +2076,8 @@ inline void sample_write_thetaMode(std::string file_ending) unsigned int const N_r = 20; unsigned int const N_z = 64; - std::shared_ptr E_r_data( - new float[num_fields * N_r * N_z], [](float const *p) { delete[] p; }); - std::shared_ptr E_t_data( - new double[num_fields * N_r * N_z], - [](double const *p) { delete[] p; }); + std::shared_ptr E_r_data(new float[num_fields * N_r * N_z]); + std::shared_ptr E_t_data(new double[num_fields * N_r * N_z]); float e_r{0}; std::generate( E_r_data.get(), E_r_data.get() + num_fields * N_r * N_z, [&e_r] { @@ -4818,9 +4805,7 @@ void variableBasedParticleData() Datatype datatype = determineDatatype(); Extent global_extent = {length}; Dataset dataset = Dataset(datatype, global_extent); - std::shared_ptr local_data( - new position_t[length], - [](position_t const *ptr) { delete[] ptr; }); + std::shared_ptr local_data(new position_t[length]); WriteIterations iterations = series.writeIterations(); for (size_t i = 0; i < 10; ++i) @@ -4918,16 +4903,14 @@ TEST_CASE("automatically_deactivate_span", "[serial][adios2]") E_uncompressed.storeChunk( {0}, {10}, [&spanWorkaround](size_t size) { spanWorkaround = true; - return std::shared_ptr( - new int[size]{}, [](auto *ptr) { delete[] ptr; }); + return std::shared_ptr(new int[size]{}); }); REQUIRE(!spanWorkaround); E_compressed.storeChunk({0}, {10}, [&spanWorkaround](size_t size) { spanWorkaround = true; - return std::shared_ptr( - new int[size]{}, [](auto *ptr) { delete[] ptr; }); + return std::shared_ptr(new int[size]{}); }); REQUIRE(spanWorkaround); @@ -4969,8 +4952,7 @@ TEST_CASE("automatically_deactivate_span", "[serial][adios2]") E_uncompressed.storeChunk( {0}, {10}, [&spanWorkaround](size_t size) { spanWorkaround = true; - return std::shared_ptr( - new int[size]{}, [](auto *ptr) { delete[] ptr; }); + return std::shared_ptr(new int[size]{}); }); REQUIRE(!spanWorkaround); @@ -4980,8 +4962,7 @@ TEST_CASE("automatically_deactivate_span", "[serial][adios2]") E_compressed.storeChunk( {0}, {10}, [&spanWorkaround](size_t size) { spanWorkaround = true; - return std::shared_ptr( - new int[size]{}, [](auto *ptr) { delete[] ptr; }); + return std::shared_ptr(new int[size]{}); }); } catch (std::invalid_argument const &e) @@ -5033,8 +5014,7 @@ TEST_CASE("automatically_deactivate_span", "[serial][adios2]") E_uncompressed.storeChunk( {0}, {10}, [&spanWorkaround](size_t size) { spanWorkaround = true; - return std::shared_ptr( - new int[size]{}, [](auto *ptr) { delete[] ptr; }); + return std::shared_ptr(new int[size]{}); }); REQUIRE(spanWorkaround); @@ -5042,8 +5022,7 @@ TEST_CASE("automatically_deactivate_span", "[serial][adios2]") spanWorkaround = false; E_compressed.storeChunk({0}, {10}, [&spanWorkaround](size_t size) { spanWorkaround = true; - return std::shared_ptr( - new int[size]{}, [](auto *ptr) { delete[] ptr; }); + return std::shared_ptr(new int[size]{}); }); REQUIRE(spanWorkaround); @@ -5091,8 +5070,7 @@ void iterate_nonstreaming_series( */ [&taskSupportedByBackend](size_t size) { taskSupportedByBackend = false; - return std::shared_ptr{ - new int[size], [](auto *ptr) { delete[] ptr; }}; + return std::shared_ptr{new int[size]}; }); if (writeSeries.backend() == "ADIOS2") {