Skip to content

Commit 99a8c56

Browse files
committed
Revert "Use overload in examples"
This reverts commit 990b33a.
1 parent 9b8bb7b commit 99a8c56

File tree

7 files changed

+66
-29
lines changed

7 files changed

+66
-29
lines changed

examples/10_streaming_write.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ int main()
2626
constexpr unsigned long length = 10ul;
2727
Extent global_extent = {length};
2828
Dataset dataset = Dataset(datatype, global_extent);
29-
std::shared_ptr<position_t[]> local_data(new position_t[length]);
29+
std::shared_ptr<position_t> local_data(
30+
new position_t[length], [](position_t const *ptr) { delete[] ptr; });
3031

3132
WriteIterations iterations = series.writeIterations();
3233
for (size_t i = 0; i < 100; ++i)

examples/13_write_dynamic_configuration.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ chunks = "auto"
7272
constexpr unsigned long length = 10ul;
7373
Extent global_extent = {length};
7474
Dataset dataset = Dataset(datatype, global_extent);
75-
std::shared_ptr<position_t[]> local_data(new position_t[length]);
75+
std::shared_ptr<position_t> local_data(
76+
new position_t[length], [](position_t const *ptr) { delete[] ptr; });
7677

7778
WriteIterations iterations = series.writeIterations();
7879
for (size_t i = 0; i < 100; ++i)

examples/7_extended_write_serial.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ int main()
9393
// data is assumed to reside behind a pointer as a contiguous
9494
// column-major array shared data ownership during IO is indicated with
9595
// a smart pointer
96-
std::shared_ptr<double[]> partial_mesh(new double[5]);
96+
std::shared_ptr<double> partial_mesh(
97+
new double[5], [](double const *p) {
98+
delete[] p;
99+
p = nullptr;
100+
});
97101

98102
// before storing record data, you must specify the dataset once per
99103
// component this describes the datatype and shape of data as it should
@@ -126,12 +130,20 @@ int main()
126130
io::ParticleSpecies electrons = cur_it.particles["electrons"];
127131

128132
io::Extent mpiDims{4};
129-
std::shared_ptr<float[]> partial_particlePos(new float[2]);
133+
std::shared_ptr<float> partial_particlePos(
134+
new float[2], [](float const *p) {
135+
delete[] p;
136+
p = nullptr;
137+
});
130138
dtype = io::determineDatatype(partial_particlePos);
131139
d = io::Dataset(dtype, mpiDims);
132140
electrons["position"]["x"].resetDataset(d);
133141

134-
std::shared_ptr<uint64_t[]> partial_particleOff(new uint64_t[2]);
142+
std::shared_ptr<uint64_t> partial_particleOff(
143+
new uint64_t[2], [](uint64_t const *p) {
144+
delete[] p;
145+
p = nullptr;
146+
});
135147
dtype = io::determineDatatype(partial_particleOff);
136148
d = io::Dataset(dtype, mpiDims);
137149
electrons["positionOffset"]["x"].resetDataset(d);

examples/8a_benchmark_write_parallel.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,10 @@ class Timer
180180
*/
181181

182182
template <typename T>
183-
std::shared_ptr<T[]>
183+
std::shared_ptr<T>
184184
createDataCPU(const unsigned long &size, const T &val, const T &increment)
185185
{
186-
auto E = std::shared_ptr<T[]>{new T[size]};
186+
auto E = std::shared_ptr<T>{new T[size], [](T *d) { delete[] d; }};
187187

188188
for (unsigned long i = 0ul; i < size; i++)
189189
{
@@ -197,7 +197,7 @@ createDataCPU(const unsigned long &size, const T &val, const T &increment)
197197

198198
#if openPMD_HAVE_CUDA_EXAMPLES
199199
template <typename T>
200-
std::shared_ptr<T[]>
200+
std::shared_ptr<T>
201201
createDataGPU(const unsigned long &size, const T &val, const T &increment)
202202
{
203203
auto myCudaMalloc = [](size_t mySize) {
@@ -206,7 +206,7 @@ createDataGPU(const unsigned long &size, const T &val, const T &increment)
206206
return ptr;
207207
};
208208
auto deleter = [](T *ptr) { cudaFree(ptr); };
209-
auto E = std::shared_ptr<T[]>{(T *)myCudaMalloc(size * sizeof(T)), deleter};
209+
auto E = std::shared_ptr<T>{(T *)myCudaMalloc(size * sizeof(T)), deleter};
210210

211211
T *data = new T[size];
212212
for (unsigned long i = 0ul; i < size; i++)
@@ -222,7 +222,7 @@ createDataGPU(const unsigned long &size, const T &val, const T &increment)
222222
#endif
223223

224224
template <typename T>
225-
std::shared_ptr<T[]>
225+
std::shared_ptr<T>
226226
createData(const unsigned long &size, const T &val, const T &increment)
227227
{
228228
#if openPMD_HAVE_CUDA_EXAMPLES

examples/8b_benchmark_read_parallel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ template <typename T>
178178
std::shared_ptr<T>
179179
createData(const unsigned long &size, const T &val, bool increment = false)
180180
{
181-
auto E = std::shared_ptr<T[]>{new T[size]};
181+
auto E = std::shared_ptr<T>{new T[size], [](T *d) { delete[] d; }};
182182

183183
for (unsigned long i = 0ul; i < size; i++)
184184
{

test/ParallelIOTest.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ void write_test_zero_extent(
154154
position_global.begin(), position_global.end(), [&pos] {
155155
return pos++;
156156
});
157-
std::shared_ptr<double[]> position_local(new double[rank]);
157+
std::shared_ptr<double> position_local(
158+
new double[rank], [](double const *p) { delete[] p; });
158159
uint64_t offset;
159160
if (rank != 0)
160161
offset = ((rank - 1) * (rank - 1) + (rank - 1)) / 2;
@@ -170,8 +171,8 @@ void write_test_zero_extent(
170171
positionOffset_global.begin(),
171172
positionOffset_global.end(),
172173
[&posOff] { return posOff++; });
173-
std::shared_ptr<uint64_t[]> positionOffset_local(
174-
new uint64_t[rank]);
174+
std::shared_ptr<uint64_t> positionOffset_local(
175+
new uint64_t[rank], [](uint64_t const *p) { delete[] p; });
175176

176177
e["positionOffset"]["x"].resetDataset(
177178
Dataset(determineDatatype(positionOffset_local), {num_cells}));

test/SerialIOTest.cpp

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,8 @@ void close_and_copy_attributable_test(std::string file_ending)
651651
constexpr unsigned long length = 10ul;
652652
Extent global_extent = {length};
653653
Dataset dataset = Dataset(datatype, global_extent);
654-
std::shared_ptr<position_t[]> local_data(new position_t[length]);
654+
std::shared_ptr<position_t> local_data(
655+
new position_t[length], [](position_t const *ptr) { delete[] ptr; });
655656

656657
std::unique_ptr<Iteration> iteration_ptr;
657658
for (size_t i = 0; i < 100; i += 10)
@@ -879,7 +880,8 @@ inline void constant_scalar(std::string file_ending)
879880
E_x.makeConstant(static_cast<float>(13.37));
880881
auto E_y = s.iterations[1].meshes["E"]["y"];
881882
E_y.resetDataset(Dataset(Datatype::UINT, {1, 2, 3}));
882-
std::shared_ptr<unsigned int[]> E(new unsigned int[6]);
883+
std::shared_ptr<unsigned int> E(
884+
new unsigned int[6], [](unsigned int const *p) { delete[] p; });
883885
unsigned int e{0};
884886
std::generate(E.get(), E.get() + 6, [&e] { return e++; });
885887
E_y.storeChunk(E, {0, 0, 0}, {1, 2, 3});
@@ -913,7 +915,9 @@ inline void constant_scalar(std::string file_ending)
913915
vel_x.makeConstant(static_cast<short>(-1));
914916
auto vel_y = s.iterations[1].particles["e"]["velocity"]["y"];
915917
vel_y.resetDataset(Dataset(Datatype::ULONGLONG, {3, 2, 1}));
916-
std::shared_ptr<unsigned long long[]> vel(new unsigned long long[6]);
918+
std::shared_ptr<unsigned long long> vel(
919+
new unsigned long long[6],
920+
[](unsigned long long const *p) { delete[] p; });
917921
unsigned long long v{0};
918922
std::generate(vel.get(), vel.get() + 6, [&v] { return v++; });
919923
vel_y.storeChunk(vel, {0, 0, 0}, {3, 2, 1});
@@ -1096,7 +1100,10 @@ TEST_CASE("flush_without_position_positionOffset", "[serial]")
10961100
RecordComponent weighting = e["weighting"][RecordComponent::SCALAR];
10971101
weighting.resetDataset(Dataset(Datatype::FLOAT, Extent{2, 2}));
10981102
weighting.storeChunk(
1099-
std::shared_ptr<float[]>(new float[4]()), {0, 0}, {2, 2});
1103+
std::shared_ptr<float>(
1104+
new float[4](), [](float const *ptr) { delete[] ptr; }),
1105+
{0, 0},
1106+
{2, 2});
11001107

11011108
s.flush();
11021109

@@ -1107,7 +1114,10 @@ TEST_CASE("flush_without_position_positionOffset", "[serial]")
11071114
RecordComponent rc = e[key][dim];
11081115
rc.resetDataset(Dataset(Datatype::FLOAT, Extent{2, 2}));
11091116
rc.storeChunk(
1110-
std::shared_ptr<float[]>(new float[4]()), {0, 0}, {2, 2});
1117+
std::shared_ptr<float>(
1118+
new float[4](), [](float const *ptr) { delete[] ptr; }),
1119+
{0, 0},
1120+
{2, 2});
11111121
}
11121122
}
11131123
}
@@ -2076,8 +2086,11 @@ inline void sample_write_thetaMode(std::string file_ending)
20762086
unsigned int const N_r = 20;
20772087
unsigned int const N_z = 64;
20782088

2079-
std::shared_ptr<float[]> E_r_data(new float[num_fields * N_r * N_z]);
2080-
std::shared_ptr<double[]> E_t_data(new double[num_fields * N_r * N_z]);
2089+
std::shared_ptr<float> E_r_data(
2090+
new float[num_fields * N_r * N_z], [](float const *p) { delete[] p; });
2091+
std::shared_ptr<double> E_t_data(
2092+
new double[num_fields * N_r * N_z],
2093+
[](double const *p) { delete[] p; });
20812094
float e_r{0};
20822095
std::generate(
20832096
E_r_data.get(), E_r_data.get() + num_fields * N_r * N_z, [&e_r] {
@@ -4805,7 +4818,9 @@ void variableBasedParticleData()
48054818
Datatype datatype = determineDatatype<position_t>();
48064819
Extent global_extent = {length};
48074820
Dataset dataset = Dataset(datatype, global_extent);
4808-
std::shared_ptr<position_t[]> local_data(new position_t[length]);
4821+
std::shared_ptr<position_t> local_data(
4822+
new position_t[length],
4823+
[](position_t const *ptr) { delete[] ptr; });
48094824

48104825
WriteIterations iterations = series.writeIterations();
48114826
for (size_t i = 0; i < 10; ++i)
@@ -4903,14 +4918,16 @@ TEST_CASE("automatically_deactivate_span", "[serial][adios2]")
49034918
E_uncompressed.storeChunk<int>(
49044919
{0}, {10}, [&spanWorkaround](size_t size) {
49054920
spanWorkaround = true;
4906-
return std::shared_ptr<int[]>(new int[size]{});
4921+
return std::shared_ptr<int>(
4922+
new int[size]{}, [](auto *ptr) { delete[] ptr; });
49074923
});
49084924

49094925
REQUIRE(!spanWorkaround);
49104926

49114927
E_compressed.storeChunk<int>({0}, {10}, [&spanWorkaround](size_t size) {
49124928
spanWorkaround = true;
4913-
return std::shared_ptr<int[]>(new int[size]{});
4929+
return std::shared_ptr<int>(
4930+
new int[size]{}, [](auto *ptr) { delete[] ptr; });
49144931
});
49154932

49164933
REQUIRE(spanWorkaround);
@@ -4952,7 +4969,8 @@ TEST_CASE("automatically_deactivate_span", "[serial][adios2]")
49524969
E_uncompressed.storeChunk<int>(
49534970
{0}, {10}, [&spanWorkaround](size_t size) {
49544971
spanWorkaround = true;
4955-
return std::shared_ptr<int[]>(new int[size]{});
4972+
return std::shared_ptr<int>(
4973+
new int[size]{}, [](auto *ptr) { delete[] ptr; });
49564974
});
49574975

49584976
REQUIRE(!spanWorkaround);
@@ -4962,7 +4980,8 @@ TEST_CASE("automatically_deactivate_span", "[serial][adios2]")
49624980
E_compressed.storeChunk<int>(
49634981
{0}, {10}, [&spanWorkaround](size_t size) {
49644982
spanWorkaround = true;
4965-
return std::shared_ptr<int[]>(new int[size]{});
4983+
return std::shared_ptr<int>(
4984+
new int[size]{}, [](auto *ptr) { delete[] ptr; });
49664985
});
49674986
}
49684987
catch (std::invalid_argument const &e)
@@ -5014,15 +5033,17 @@ TEST_CASE("automatically_deactivate_span", "[serial][adios2]")
50145033
E_uncompressed.storeChunk<int>(
50155034
{0}, {10}, [&spanWorkaround](size_t size) {
50165035
spanWorkaround = true;
5017-
return std::shared_ptr<int[]>(new int[size]{});
5036+
return std::shared_ptr<int>(
5037+
new int[size]{}, [](auto *ptr) { delete[] ptr; });
50185038
});
50195039

50205040
REQUIRE(spanWorkaround);
50215041

50225042
spanWorkaround = false;
50235043
E_compressed.storeChunk<int>({0}, {10}, [&spanWorkaround](size_t size) {
50245044
spanWorkaround = true;
5025-
return std::shared_ptr<int[]>(new int[size]{});
5045+
return std::shared_ptr<int>(
5046+
new int[size]{}, [](auto *ptr) { delete[] ptr; });
50265047
});
50275048

50285049
REQUIRE(spanWorkaround);
@@ -5070,7 +5091,8 @@ void iterate_nonstreaming_series(
50705091
*/
50715092
[&taskSupportedByBackend](size_t size) {
50725093
taskSupportedByBackend = false;
5073-
return std::shared_ptr<int[]>{new int[size]};
5094+
return std::shared_ptr<int>{
5095+
new int[size], [](auto *ptr) { delete[] ptr; }};
50745096
});
50755097
if (writeSeries.backend() == "ADIOS2")
50765098
{

0 commit comments

Comments
 (0)