fixed memory leak on () operator for stencil class
This commit is contained in:
20
stencil.hpp
20
stencil.hpp
@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user