Skip to content

Commit 990b33a

Browse files
committed
Use overload in examples
1 parent 4f30f34 commit 990b33a

File tree

7 files changed

+29
-66
lines changed

7 files changed

+29
-66
lines changed

examples/10_streaming_write.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ 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(
30-
new position_t[length], [](position_t const *ptr) { delete[] ptr; });
29+
std::shared_ptr<position_t[]> local_data(new position_t[length]);
3130

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

examples/13_write_dynamic_configuration.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ 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(
76-
new position_t[length], [](position_t const *ptr) { delete[] ptr; });
75+
std::shared_ptr<position_t[]> local_data(new position_t[length]);
7776

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

examples/7_extended_write_serial.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@ 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(
97-
new double[5], [](double const *p) {
98-
delete[] p;
99-
p = nullptr;
100-
});
96+
std::shared_ptr<double[]> partial_mesh(new double[5]);
10197

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

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

142-
std::shared_ptr<uint64_t> partial_particleOff(
143-
new uint64_t[2], [](uint64_t const *p) {
144-
delete[] p;
145-
p = nullptr;
146-
});
134+
std::shared_ptr<uint64_t[]> partial_particleOff(new uint64_t[2]);
147135
dtype = io::determineDatatype(partial_particleOff);
148136
d = io::Dataset(dtype, mpiDims);
149137
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], [](T *d) { delete[] d; }};
186+
auto E = std::shared_ptr<T[]>{new T[size]};
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], [](T *d) { delete[] d; }};
181+
auto E = std::shared_ptr<T[]>{new T[size]};
182182

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

test/ParallelIOTest.cpp

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

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

test/SerialIOTest.cpp

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,7 @@ 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(
655-
new position_t[length], [](position_t const *ptr) { delete[] ptr; });
654+
std::shared_ptr<position_t[]> local_data(new position_t[length]);
656655

657656
std::unique_ptr<Iteration> iteration_ptr;
658657
for (size_t i = 0; i < 100; i += 10)
@@ -880,8 +879,7 @@ inline void constant_scalar(std::string file_ending)
880879
E_x.makeConstant(static_cast<float>(13.37));
881880
auto E_y = s.iterations[1].meshes["E"]["y"];
882881
E_y.resetDataset(Dataset(Datatype::UINT, {1, 2, 3}));
883-
std::shared_ptr<unsigned int> E(
884-
new unsigned int[6], [](unsigned int const *p) { delete[] p; });
882+
std::shared_ptr<unsigned int[]> E(new unsigned int[6]);
885883
unsigned int e{0};
886884
std::generate(E.get(), E.get() + 6, [&e] { return e++; });
887885
E_y.storeChunk(E, {0, 0, 0}, {1, 2, 3});
@@ -915,9 +913,7 @@ inline void constant_scalar(std::string file_ending)
915913
vel_x.makeConstant(static_cast<short>(-1));
916914
auto vel_y = s.iterations[1].particles["e"]["velocity"]["y"];
917915
vel_y.resetDataset(Dataset(Datatype::ULONGLONG, {3, 2, 1}));
918-
std::shared_ptr<unsigned long long> vel(
919-
new unsigned long long[6],
920-
[](unsigned long long const *p) { delete[] p; });
916+
std::shared_ptr<unsigned long long[]> vel(new unsigned long long[6]);
921917
unsigned long long v{0};
922918
std::generate(vel.get(), vel.get() + 6, [&v] { return v++; });
923919
vel_y.storeChunk(vel, {0, 0, 0}, {3, 2, 1});
@@ -1100,10 +1096,7 @@ TEST_CASE("flush_without_position_positionOffset", "[serial]")
11001096
RecordComponent weighting = e["weighting"][RecordComponent::SCALAR];
11011097
weighting.resetDataset(Dataset(Datatype::FLOAT, Extent{2, 2}));
11021098
weighting.storeChunk(
1103-
std::shared_ptr<float>(
1104-
new float[4](), [](float const *ptr) { delete[] ptr; }),
1105-
{0, 0},
1106-
{2, 2});
1099+
std::shared_ptr<float[]>(new float[4]()), {0, 0}, {2, 2});
11071100

11081101
s.flush();
11091102

@@ -1114,10 +1107,7 @@ TEST_CASE("flush_without_position_positionOffset", "[serial]")
11141107
RecordComponent rc = e[key][dim];
11151108
rc.resetDataset(Dataset(Datatype::FLOAT, Extent{2, 2}));
11161109
rc.storeChunk(
1117-
std::shared_ptr<float>(
1118-
new float[4](), [](float const *ptr) { delete[] ptr; }),
1119-
{0, 0},
1120-
{2, 2});
1110+
std::shared_ptr<float[]>(new float[4]()), {0, 0}, {2, 2});
11211111
}
11221112
}
11231113
}
@@ -2086,11 +2076,8 @@ inline void sample_write_thetaMode(std::string file_ending)
20862076
unsigned int const N_r = 20;
20872077
unsigned int const N_z = 64;
20882078

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; });
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]);
20942081
float e_r{0};
20952082
std::generate(
20962083
E_r_data.get(), E_r_data.get() + num_fields * N_r * N_z, [&e_r] {
@@ -4818,9 +4805,7 @@ void variableBasedParticleData()
48184805
Datatype datatype = determineDatatype<position_t>();
48194806
Extent global_extent = {length};
48204807
Dataset dataset = Dataset(datatype, global_extent);
4821-
std::shared_ptr<position_t> local_data(
4822-
new position_t[length],
4823-
[](position_t const *ptr) { delete[] ptr; });
4808+
std::shared_ptr<position_t[]> local_data(new position_t[length]);
48244809

48254810
WriteIterations iterations = series.writeIterations();
48264811
for (size_t i = 0; i < 10; ++i)
@@ -4918,16 +4903,14 @@ TEST_CASE("automatically_deactivate_span", "[serial][adios2]")
49184903
E_uncompressed.storeChunk<int>(
49194904
{0}, {10}, [&spanWorkaround](size_t size) {
49204905
spanWorkaround = true;
4921-
return std::shared_ptr<int>(
4922-
new int[size]{}, [](auto *ptr) { delete[] ptr; });
4906+
return std::shared_ptr<int[]>(new int[size]{});
49234907
});
49244908

49254909
REQUIRE(!spanWorkaround);
49264910

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

49334916
REQUIRE(spanWorkaround);
@@ -4969,8 +4952,7 @@ TEST_CASE("automatically_deactivate_span", "[serial][adios2]")
49694952
E_uncompressed.storeChunk<int>(
49704953
{0}, {10}, [&spanWorkaround](size_t size) {
49714954
spanWorkaround = true;
4972-
return std::shared_ptr<int>(
4973-
new int[size]{}, [](auto *ptr) { delete[] ptr; });
4955+
return std::shared_ptr<int[]>(new int[size]{});
49744956
});
49754957

49764958
REQUIRE(!spanWorkaround);
@@ -4980,8 +4962,7 @@ TEST_CASE("automatically_deactivate_span", "[serial][adios2]")
49804962
E_compressed.storeChunk<int>(
49814963
{0}, {10}, [&spanWorkaround](size_t size) {
49824964
spanWorkaround = true;
4983-
return std::shared_ptr<int>(
4984-
new int[size]{}, [](auto *ptr) { delete[] ptr; });
4965+
return std::shared_ptr<int[]>(new int[size]{});
49854966
});
49864967
}
49874968
catch (std::invalid_argument const &e)
@@ -5033,17 +5014,15 @@ TEST_CASE("automatically_deactivate_span", "[serial][adios2]")
50335014
E_uncompressed.storeChunk<int>(
50345015
{0}, {10}, [&spanWorkaround](size_t size) {
50355016
spanWorkaround = true;
5036-
return std::shared_ptr<int>(
5037-
new int[size]{}, [](auto *ptr) { delete[] ptr; });
5017+
return std::shared_ptr<int[]>(new int[size]{});
50385018
});
50395019

50405020
REQUIRE(spanWorkaround);
50415021

50425022
spanWorkaround = false;
50435023
E_compressed.storeChunk<int>({0}, {10}, [&spanWorkaround](size_t size) {
50445024
spanWorkaround = true;
5045-
return std::shared_ptr<int>(
5046-
new int[size]{}, [](auto *ptr) { delete[] ptr; });
5025+
return std::shared_ptr<int[]>(new int[size]{});
50475026
});
50485027

50495028
REQUIRE(spanWorkaround);
@@ -5091,8 +5070,7 @@ void iterate_nonstreaming_series(
50915070
*/
50925071
[&taskSupportedByBackend](size_t size) {
50935072
taskSupportedByBackend = false;
5094-
return std::shared_ptr<int>{
5095-
new int[size], [](auto *ptr) { delete[] ptr; }};
5073+
return std::shared_ptr<int[]>{new int[size]};
50965074
});
50975075
if (writeSeries.backend() == "ADIOS2")
50985076
{

0 commit comments

Comments
 (0)