Skip to content

Commit cf3483a

Browse files
committed
Reduce the memory usage for large inputted arrays:
move_alloc.
1 parent ec00dfe commit cf3483a

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/stdlib_math_diff.fypp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ contains
4747
work(1:size(work)-i) = work(2:size(work)-i+1) - work(1:size(work)-i)
4848
end do
4949

50-
y = work(1:size(work)-n_)
50+
call move_alloc(work, y)
51+
y = y(1:size(y)-n_)
5152

5253
end function diff_1_${k1}$
5354

@@ -92,11 +93,12 @@ contains
9293
if (size_prepend > 0) work(1:size_prepend, :) = prepend
9394
work(size_prepend+1:size_x+size_prepend, :) = x
9495
if (size_append > 0) work(size_x+size_prepend+1:, :) = append
95-
do i = 1, n_
96+
do concurrent (i = 1:n_)
9697
work(1:size(work,1)-i, :) = work(2:size(work)-i+1, :) - work(1:size(x, 1)-i, :)
9798
end do
9899

99-
y = work(1:size(work)-n_, :)
100+
call move_alloc(work, y)
101+
y = y(1:size(y)-n_, :)
100102

101103
elseif (dim_ == 2) then
102104
allocate(work(size(x, 1), size_x+size_prepend+size_append))
@@ -107,7 +109,8 @@ contains
107109
work(:, 1:size(work,2)-i) = work(:, 2:size(work,2)-i+1) - work(:, 1:size(work, 2)-i)
108110
end do
109111

110-
y = work(:, 1:size(work,2)-n_)
112+
call move_alloc(work, y)
113+
y = y(:, 1:size(y,2)-n_)
111114

112115
end if
113116

0 commit comments

Comments
 (0)