aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWojtek Kosior <kwojtus@protonmail.com>2019-06-30 22:09:14 +0200
committerWojtek Kosior <kwojtus@protonmail.com>2019-06-30 22:09:14 +0200
commit560e148807b688d20275985646225423a8ee8733 (patch)
tree83e7c28c655c67544a8a66a4a3915ea75b44d813 /src
parent1b97abf11f40e5d1570ee2e72c15958602bbc517 (diff)
downloadfortran-assignment3-560e148807b688d20275985646225423a8ee8733.tar.gz
fortran-assignment3-560e148807b688d20275985646225423a8ee8733.zip
sum values in a smarter order
Diffstat (limited to 'src')
-rw-r--r--src/quadratures.f9023
1 files changed, 20 insertions, 3 deletions
diff --git a/src/quadratures.f90 b/src/quadratures.f90
index c2be860..35b28c4 100644
--- a/src/quadratures.f90
+++ b/src/quadratures.f90
@@ -46,10 +46,11 @@ CONTAINS
procedure(funint) :: fun
procedure(quadrature) :: quad
- real(kind=8) :: val, subinterval_width, qbeg, qend
+ real(kind=8) :: val, subinterval_width, qbeg, qend, partsums(48)
+ logical :: partsums_mask(48) = .true.
real(kind=8), allocatable :: partval[:]
- integer(kind=8) :: min_i, max_i, i, subintervals_per_thread
+ integer(kind=8) :: min_i, max_i, i, j, subintervals_per_thread
integer(kind=4) :: im
allocate(partval[*])
@@ -68,9 +69,25 @@ CONTAINS
DO i = min_i, max_i
qend = ibeg + i * subinterval_width
qbeg = ibeg + (i - 1) * subinterval_width
- partval = partval + quad(qbeg, qend, fun)
+ val = quad(qbeg, qend, fun)
+
+ DO j = 1, 48
+ IF (partsums_mask(j)) THEN
+ partsums_mask(j) = .false.
+ partsums(j) = val
+ EXIT
+ END IF
+
+ val = val + partsums(j)
+ partsums_mask(j) = .true.
+ END DO
END DO
+ partval = 0
+ DO j = 1, 48
+ IF (.not. partsums_mask(j)) partval = partval + partsums(j)
+ END DO
+
IF (this_image() == 1 .and. num_images() > 1) THEN
sync images([(im, im = 2, num_images())])
partval = partval + sum([(partval[im], im = 2, num_images())])