fixed memory leak on () operator for stencil class

This commit is contained in:
elvis
2023-08-29 17:25:54 +02:00
parent 00e921f219
commit 5d8348b42a
2 changed files with 14 additions and 8 deletions

View File

@ -208,7 +208,7 @@ int main(int argc, char *argv[]) {
vector<pair<int, int>> neig = {make_pair(-1, 1), make_pair(-1, 0), vector<pair<int, int>> neig = {make_pair(-1, 1), make_pair(-1, 0),
make_pair(-1, -1), make_pair(0, 1), make_pair(-1, -1), make_pair(0, 1),
make_pair(0, -1), make_pair(1, 1), make_pair(0, -1), make_pair(1, 1),
make_pair(1, 0), make_pair(1, -1)}; make_pair(1, 0), make_pair(1, -1)};
ofstream csvfile; ofstream csvfile;
csvfile.open("performance.csv"); csvfile.open("performance.csv");

View File

@ -35,7 +35,7 @@ template <typename T> class Stencil : public ff::ff_Map<Task<T>> {
std::vector<std::promise<Task<T> *> *> *OutputVector); std::vector<std::promise<Task<T> *> *> *OutputVector);
private: private:
Task<T> *svc_helper(Task<T> *t); Task<T> *svc_helper(Task<T> *t, int iterations);
void constructor_helper(std::vector<std::pair<int, int>> neighborhood); void constructor_helper(std::vector<std::pair<int, int>> neighborhood);
std::function<T(std::vector<T>)> Convolution; std::function<T(std::vector<T>)> Convolution;
@ -100,7 +100,7 @@ void Stencil<T>::constructor_helper(
// svc function for fastflow library // svc function for fastflow library
template <typename T> Task<T> *Stencil<T>::svc(Task<T> *task) { template <typename T> Task<T> *Stencil<T>::svc(Task<T> *task) {
task = svc_helper(task); task = svc_helper(task, this->Iterations);
ff::ff_node::ff_send_out(task); ff::ff_node::ff_send_out(task);
return this->GO_ON; return this->GO_ON;
} }
@ -112,9 +112,15 @@ Stencil<T>::operator()(std::vector<std::vector<T>> *matrix, int iterations) {
if ((*matrix).size() == 0 || (*matrix)[0].size() == 0) { if ((*matrix).size() == 0 || (*matrix)[0].size() == 0) {
return matrix; return matrix;
} }
Task<T> *task = new Task<T>(matrix, (*matrix).size(), (*matrix)[0].size()); std::vector<std::vector<T>> * arena = new std::vector<std::vector<T>>();
task = svc_helper(task); *arena = *matrix;
return task->VectorData;
Task<T> *task = new Task<T>(arena, (*arena).size(), (*arena)[0].size());
task = svc_helper(task, iterations);
*matrix = *task->VectorData;
delete task;
return matrix;
} }
// function for std thread // function for std thread
@ -243,8 +249,8 @@ void Stencil<T>::sequential(
} }
} }
template <typename T> Task<T> *Stencil<T>::svc_helper(Task<T> *task) { template <typename T> Task<T> *Stencil<T>::svc_helper(Task<T> *task, int iterations) {
int niter = Iterations; int niter = iterations;
std::vector<std::vector<T>> *arena = new std::vector<std::vector<T>>(0); std::vector<std::vector<T>> *arena = new std::vector<std::vector<T>>(0);
*arena = *(task->VectorData); *arena = *(task->VectorData);