Commit 05c44eca authored by Cristian Lalescu's avatar Cristian Lalescu
Browse files

partial fix

when using unique_ptr for arrays, they are cleaned up by calling
`delete[] bla.release()`.
At least, cppreference says that the release method
"returns a pointer to the managed object and releases the ownership ".
https://en.cppreference.com/w/cpp/memory/unique_ptr
parent 9471c4da
Pipeline #43843 failed with stage
...@@ -229,10 +229,9 @@ int NSVEcomplex_particles<rnumber>::do_stats() ...@@ -229,10 +229,9 @@ int NSVEcomplex_particles<rnumber>::do_stats()
this->ps->get_step_idx()-1); this->ps->get_step_idx()-1);
// deallocate temporary data array // deallocate temporary data array
// TODO: is it required/safe to call the release method here? delete[] pdata0.release();
pdata0.release(); delete[] pdata1.release();
pdata1.release(); delete[] pdata2.release();
pdata2.release();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
......
...@@ -105,7 +105,7 @@ int NSVEparticles<rnumber>::finalize(void) ...@@ -105,7 +105,7 @@ int NSVEparticles<rnumber>::finalize(void)
{ {
TIMEZONE("NSVEparticles::finalize"); TIMEZONE("NSVEparticles::finalize");
delete this->pressure; delete this->pressure;
this->ps.release(); delete this->ps.release();
delete this->particles_output_writer_mpi; delete this->particles_output_writer_mpi;
delete this->particles_sample_writer_mpi; delete this->particles_sample_writer_mpi;
this->NSVE<rnumber>::finalize(); this->NSVE<rnumber>::finalize();
...@@ -134,7 +134,7 @@ int NSVEparticles<rnumber>::do_stats() ...@@ -134,7 +134,7 @@ int NSVEparticles<rnumber>::do_stats()
// allocate temporary data array // allocate temporary data array
std::unique_ptr<double[]> pdata(new double[3*this->ps->getLocalNbParticles()]); std::unique_ptr<double[]> pdata(new double[3*this->ps->getLocalNbParticles()]);
// copy position data /// copy position data
/// sample position /// sample position
std::copy(this->ps->getParticlesState(), std::copy(this->ps->getParticlesState(),
...@@ -183,8 +183,7 @@ int NSVEparticles<rnumber>::do_stats() ...@@ -183,8 +183,7 @@ int NSVEparticles<rnumber>::do_stats()
this->ps->get_step_idx()-1); this->ps->get_step_idx()-1);
// deallocate temporary data array // deallocate temporary data array
// TODO: is it required/safe to call the release method here? delete[] pdata.release();
pdata.release();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
......
...@@ -92,7 +92,7 @@ int test_interpolation<rnumber>::finalize(void) ...@@ -92,7 +92,7 @@ int test_interpolation<rnumber>::finalize(void)
delete this->nabla_u; delete this->nabla_u;
delete this->velocity; delete this->velocity;
delete this->vorticity; delete this->vorticity;
this->ps.release(); delete this->ps.release();
delete this->kk; delete this->kk;
delete particles_output_writer_mpi; delete particles_output_writer_mpi;
delete particles_sample_writer_mpi; delete particles_sample_writer_mpi;
...@@ -198,7 +198,9 @@ int test_interpolation<rnumber>::do_work() ...@@ -198,7 +198,9 @@ int test_interpolation<rnumber>::do_work()
this->ps->getLocalNbParticles(), this->ps->getLocalNbParticles(),
this->ps->get_step_idx()-1); this->ps->get_step_idx()-1);
// no need to deallocate because we used "unique_ptr" // deallocate temporary arrays
delete[] p3data.release();
delete[] p9data.release();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
......
...@@ -213,6 +213,9 @@ std::string hdf5_tools::read_string( ...@@ -213,6 +213,9 @@ std::string hdf5_tools::read_string(
hid_t dset = H5Dopen(group, dset_name.c_str(), H5P_DEFAULT); hid_t dset = H5Dopen(group, dset_name.c_str(), H5P_DEFAULT);
hid_t space = H5Dget_space(dset); hid_t space = H5Dget_space(dset);
hid_t memtype = H5Dget_type(dset); hid_t memtype = H5Dget_type(dset);
// fsanitize complains unless I have a static array here
// but that doesn't actually work (data is read incorrectly).
// this is caught by bfps.test_NSVEparticles
char *string_data = (char*)malloc(256); char *string_data = (char*)malloc(256);
H5Dread(dset, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, &string_data); H5Dread(dset, memtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, &string_data);
std::string std_string_data = std::string(string_data); std::string std_string_data = std::string(string_data);
......
...@@ -137,15 +137,15 @@ public: ...@@ -137,15 +137,15 @@ public:
} }
void releaseMemory(){ void releaseMemory(){
buffer_indexes_send.release(); delete[] buffer_indexes_send.release();
buffer_particles_positions_send.release(); delete[] buffer_particles_positions_send.release();
size_buffers_send = 0; size_buffers_send = 0;
buffer_indexes_recv.release(); delete[] buffer_indexes_recv.release();
buffer_particles_positions_recv.release(); delete[] buffer_particles_positions_recv.release();
size_buffers_recv = 0; size_buffers_recv = 0;
for(int idx_rhs = 0 ; idx_rhs < nb_rhs ; ++idx_rhs){ for(int idx_rhs = 0 ; idx_rhs < nb_rhs ; ++idx_rhs){
buffer_particles_rhs_send[idx_rhs].release(); delete[] buffer_particles_rhs_send[idx_rhs].release();
buffer_particles_rhs_recv[idx_rhs].release(); delete[] buffer_particles_rhs_recv[idx_rhs].release();
} }
buffers_size_particle_rhs_send = 0; buffers_size_particle_rhs_send = 0;
buffers_size_particle_rhs_recv = 0; buffers_size_particle_rhs_recv = 0;
......
...@@ -625,7 +625,7 @@ public: ...@@ -625,7 +625,7 @@ public:
AssertMpi(MPI_Isend(descriptor.results.get(), int(NbParticlesToReceive*size_particle_rhs), AssertMpi(MPI_Isend(descriptor.results.get(), int(NbParticlesToReceive*size_particle_rhs),
particles_utils::GetMpiType(real_number()), destProc, TAG_RESULT_PARTICLES, particles_utils::GetMpiType(real_number()), destProc, TAG_RESULT_PARTICLES,
current_com, &mpiRequests.back())); current_com, &mpiRequests.back()));
descriptor.toCompute.release(); delete[] descriptor.toCompute.release();
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
/// Release memory that was sent back /// Release memory that was sent back
...@@ -634,7 +634,7 @@ public: ...@@ -634,7 +634,7 @@ public:
NeighborDescriptor& descriptor = neigDescriptors[releasedAction.second]; NeighborDescriptor& descriptor = neigDescriptors[releasedAction.second];
assert(descriptor.results != nullptr); assert(descriptor.results != nullptr);
assert(descriptor.isRecv); assert(descriptor.isRecv);
descriptor.results.release(); delete[] descriptor.results.release();
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
/// Merge /// Merge
...@@ -646,7 +646,7 @@ public: ...@@ -646,7 +646,7 @@ public:
assert(descriptor.toRecvAndMerge != nullptr); assert(descriptor.toRecvAndMerge != nullptr);
in_computer.template reduce_particles_rhs<size_particle_rhs>(&particles_current_rhs[particles_offset_layers[my_nb_cell_levels-descriptor.nbLevelsToExchange]*size_particle_rhs], in_computer.template reduce_particles_rhs<size_particle_rhs>(&particles_current_rhs[particles_offset_layers[my_nb_cell_levels-descriptor.nbLevelsToExchange]*size_particle_rhs],
descriptor.toRecvAndMerge.get(), descriptor.nbParticlesToExchange); descriptor.toRecvAndMerge.get(), descriptor.nbParticlesToExchange);
descriptor.toRecvAndMerge.release(); delete[] descriptor.toRecvAndMerge.release();
} }
} }
} }
......
...@@ -418,7 +418,7 @@ public: ...@@ -418,7 +418,7 @@ public:
if(releasedAction.first == RELEASE_BUFFER_PARTICLES){ if(releasedAction.first == RELEASE_BUFFER_PARTICLES){
NeighborDescriptor& descriptor = neigDescriptors[releasedAction.second]; NeighborDescriptor& descriptor = neigDescriptors[releasedAction.second];
assert(descriptor.toCompute != nullptr); assert(descriptor.toCompute != nullptr);
descriptor.toCompute.release(); delete[] descriptor.toCompute.release();
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
/// Merge /// Merge
...@@ -430,14 +430,14 @@ public: ...@@ -430,14 +430,14 @@ public:
TIMEZONE("reduce"); TIMEZONE("reduce");
assert(descriptor.toRecvAndMerge != nullptr); assert(descriptor.toRecvAndMerge != nullptr);
in_computer.template reduce_particles_rhs<size_particle_rhs>(&particles_current_rhs[0], descriptor.toRecvAndMerge.get(), descriptor.nbParticlesToSend); in_computer.template reduce_particles_rhs<size_particle_rhs>(&particles_current_rhs[0], descriptor.toRecvAndMerge.get(), descriptor.nbParticlesToSend);
descriptor.toRecvAndMerge.release(); delete[] descriptor.toRecvAndMerge.release();
} }
else { else {
TIMEZONE("reduce"); TIMEZONE("reduce");
assert(descriptor.toRecvAndMerge != nullptr); assert(descriptor.toRecvAndMerge != nullptr);
in_computer.template reduce_particles_rhs<size_particle_rhs>(&particles_current_rhs[(current_offset_particles_for_partition[current_partition_size]-descriptor.nbParticlesToSend)*size_particle_rhs], in_computer.template reduce_particles_rhs<size_particle_rhs>(&particles_current_rhs[(current_offset_particles_for_partition[current_partition_size]-descriptor.nbParticlesToSend)*size_particle_rhs],
descriptor.toRecvAndMerge.get(), descriptor.nbParticlesToSend); descriptor.toRecvAndMerge.get(), descriptor.nbParticlesToSend);
descriptor.toRecvAndMerge.release(); delete[] descriptor.toRecvAndMerge.release();
} }
} }
} }
...@@ -475,14 +475,14 @@ public: ...@@ -475,14 +475,14 @@ public:
TIMEZONE("reduce_later"); TIMEZONE("reduce_later");
assert(descriptor.toRecvAndMerge != nullptr); assert(descriptor.toRecvAndMerge != nullptr);
in_computer.template reduce_particles_rhs<size_particle_rhs>(&particles_current_rhs[0], descriptor.toRecvAndMerge.get(), descriptor.nbParticlesToSend); in_computer.template reduce_particles_rhs<size_particle_rhs>(&particles_current_rhs[0], descriptor.toRecvAndMerge.get(), descriptor.nbParticlesToSend);
descriptor.toRecvAndMerge.release(); delete[] descriptor.toRecvAndMerge.release();
} }
else { else {
TIMEZONE("reduce_later"); TIMEZONE("reduce_later");
assert(descriptor.toRecvAndMerge != nullptr); assert(descriptor.toRecvAndMerge != nullptr);
in_computer.template reduce_particles_rhs<size_particle_rhs>(&particles_current_rhs[(current_offset_particles_for_partition[current_partition_size]-descriptor.nbParticlesToSend)*size_particle_rhs], in_computer.template reduce_particles_rhs<size_particle_rhs>(&particles_current_rhs[(current_offset_particles_for_partition[current_partition_size]-descriptor.nbParticlesToSend)*size_particle_rhs],
descriptor.toRecvAndMerge.get(), descriptor.nbParticlesToSend); descriptor.toRecvAndMerge.get(), descriptor.nbParticlesToSend);
descriptor.toRecvAndMerge.release(); delete[] descriptor.toRecvAndMerge.release();
} }
} }
} }
......
...@@ -302,13 +302,13 @@ public: ...@@ -302,13 +302,13 @@ public:
my_particles_positions.reset(new real_number[exchanger.getTotalToRecv()*size_particle_positions]); my_particles_positions.reset(new real_number[exchanger.getTotalToRecv()*size_particle_positions]);
} }
exchanger.alltoallv<real_number>(split_particles_positions.get(), my_particles_positions.get(), size_particle_positions); exchanger.alltoallv<real_number>(split_particles_positions.get(), my_particles_positions.get(), size_particle_positions);
split_particles_positions.release(); delete[] split_particles_positions.release();
if(nb_particles_for_me){ if(nb_particles_for_me){
my_particles_indexes.reset(new partsize_t[exchanger.getTotalToRecv()]); my_particles_indexes.reset(new partsize_t[exchanger.getTotalToRecv()]);
} }
exchanger.alltoallv<partsize_t>(split_particles_indexes.get(), my_particles_indexes.get()); exchanger.alltoallv<partsize_t>(split_particles_indexes.get(), my_particles_indexes.get());
split_particles_indexes.release(); delete[] split_particles_indexes.release();
my_particles_rhs.resize(nb_rhs); my_particles_rhs.resize(nb_rhs);
for(int idx_rhs = 0 ; idx_rhs < int(nb_rhs) ; ++idx_rhs){ for(int idx_rhs = 0 ; idx_rhs < int(nb_rhs) ; ++idx_rhs){
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment