Skip to content

Commit

Permalink
Refactor all source-allocations
Browse files Browse the repository at this point in the history
Refactor all source-allocations by mold-allocations and assigments.

Why:

Soucer-allocation generates memory leaks that must be avoided.
Hopefully, mold-allocation/assignment should not.

Side effects:

Nothing (apparently), memory leaks occurences must still be checked.
  • Loading branch information
szaghi committed Apr 20, 2017
1 parent 8331c49 commit 69f8c35
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
12 changes: 8 additions & 4 deletions src/lib/factories/wenoof_interpolator_factory.f90
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ subroutine create_constructor(interpolator_type, S, interpolations_constructor,
call constructor%create(S=S)
select type(constructor)
type is(interpolator_js_constructor)
allocate(constructor%interpolations_constructor, source=interpolations_constructor)
allocate(constructor%weights_constructor, source=weights_constructor)
allocate(constructor%interpolations_constructor, mold=interpolations_constructor)
constructor%interpolations_constructor = interpolations_constructor
allocate(constructor%weights_constructor, mold=weights_constructor)
constructor%weights_constructor = weights_constructor
type is(reconstructor_js_constructor)
allocate(constructor%interpolations_constructor, source=interpolations_constructor)
allocate(constructor%weights_constructor, source=weights_constructor)
allocate(constructor%interpolations_constructor, mold=interpolations_constructor)
constructor%interpolations_constructor = interpolations_constructor
allocate(constructor%weights_constructor, mold=weights_constructor)
constructor%weights_constructor = weights_constructor
endselect
endsubroutine create_constructor
endmodule wenoof_interpolator_factory
3 changes: 2 additions & 1 deletion src/lib/factories/wenoof_kappa_factory.f90
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ subroutine create_constructor_int(interpolator_type, S, stencil, x_target, inter
constructor%stencil = stencil
constructor%x_target = x_target
call constructor%create(S=S)
allocate(constructor%interpolations_constructor, source=interpolations_constructor)
allocate(constructor%interpolations_constructor, mold=interpolations_constructor)
constructor%interpolations_constructor = interpolations_constructor
endselect
endsubroutine create_constructor_int
endmodule wenoof_kappa_factory
18 changes: 12 additions & 6 deletions src/lib/factories/wenoof_weights_factory.f90
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,19 @@ subroutine create_constructor(interpolator_type, S, alpha_constructor, beta_cons
call constructor%create(S=S)
select type(constructor)
type is(weights_int_js_constructor)
allocate(constructor%alpha_constructor, source=alpha_constructor)
allocate(constructor%beta_constructor, source=beta_constructor)
allocate(constructor%kappa_constructor, source=kappa_constructor)
allocate(constructor%alpha_constructor, mold=alpha_constructor)
constructor%alpha_constructor = alpha_constructor
allocate(constructor%beta_constructor, mold=beta_constructor)
constructor%beta_constructor = beta_constructor
allocate(constructor%kappa_constructor, mold=kappa_constructor)
constructor%kappa_constructor = kappa_constructor
type is(weights_rec_js_constructor)
allocate(constructor%alpha_constructor, source=alpha_constructor)
allocate(constructor%beta_constructor, source=beta_constructor)
allocate(constructor%kappa_constructor, source=kappa_constructor)
allocate(constructor%alpha_constructor, mold=alpha_constructor)
constructor%alpha_constructor = alpha_constructor
allocate(constructor%beta_constructor, mold=beta_constructor)
constructor%beta_constructor = beta_constructor
allocate(constructor%kappa_constructor, mold=kappa_constructor)
constructor%kappa_constructor = kappa_constructor
endselect
endsubroutine create_constructor
endmodule wenoof_weights_factory
3 changes: 2 additions & 1 deletion src/tests/wenoof_test_linear_advection.f90
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ subroutine advection_assign_advection(lhs, rhs)
if (allocated(rhs%BC_R)) lhs%BC_R = rhs%BC_R
if (allocated(rhs%interpolator)) then
if (allocated(lhs%interpolator)) deallocate(lhs%interpolator)
allocate(lhs%interpolator, source=rhs%interpolator)
allocate(lhs%interpolator, mold=rhs%interpolator)
lhs%interpolator = rhs%interpolator
endif
endselect
endsubroutine advection_assign_advection
Expand Down

0 comments on commit 69f8c35

Please sign in to comment.