20 integer(kind=intType),
dimension(:),
pointer ::
stack
48 type(
adttype),
intent(in) :: ADT
50 character(len=*),
intent(in) :: routineName
51 character(len=*),
intent(in) :: errorMessage
55 integer,
parameter :: maxCharLine = 55
59 integer :: ierr, len, i2
62 character(len=len_trim(errorMessage)) :: message
63 character(len=8) :: integerString
70 message = errormessage
76 print
"(a)",
"#=========================== !!! Error !!! &
77 &============================"
79 #ifndef SEQUENTIAL_MODE
80 write (integerstring,
"(i8)") adt%myID
81 integerstring = adjustl(integerstring)
83 print
"(2a)",
"#* adtTerminate called by processor ", &
87 print
"(2a)",
"#* Run-time error in procedure ", &
99 message = adjustl(message)
100 len = len_trim(message)
101 i2 = min(maxcharline, len)
103 if (i2 < len) i2 = index(message(:i2),
" ", .true.) - 1
104 if (i2 < 0) i2 = index(message,
" ") - 1
111 print
"(2a)",
"#* Error message: ", trim(message(:i2))
114 print
"(2a)",
"#* ", trim(message(:i2))
123 message = message(i2 + 1:)
130 print
"(a)",
"#* Now exiting"
131 print
"(a)",
"#==========================================&
132 &============================"
138 call mpi_abort(adt%comm, 1, ierr)
159 allocate (
adts(1), stat=ierr)
160 if (ierr /= 0) stop
"Allocation failure for ADTs"
164 nullify (
adts(1)%coor)
166 nullify (
adts(1)%triaConn)
167 nullify (
adts(1)%quadsConn)
168 nullify (
adts(1)%tetraConn)
169 nullify (
adts(1)%pyraConn)
170 nullify (
adts(1)%prismsConn)
171 nullify (
adts(1)%hexaConn)
173 nullify (
adts(1)%rootLeavesProcs)
174 nullify (
adts(1)%rootBBoxes)
176 nullify (
adts(1)%elementType)
177 nullify (
adts(1)%elementID)
178 nullify (
adts(1)%xBBox)
180 nullify (
adts(1)%ADTree)
197 character(len=*),
intent(in) :: adtID
203 integer(kind=intType) :: jj, nn, nAlloc, nAllocNew
205 type(
adttype),
dimension(:),
allocatable :: tmpADTs
211 if (
allocated(
adts))
then
212 nalloc = ubound(
adts, 1)
218 if (adtid ==
adts(jj)%adtID)
exit
223 if (jj > nalloc)
return
230 if (
adts(jj)%isActive)
then
232 deallocate (
adts(jj)%rootLeavesProcs,
adts(jj)%rootBBoxes, &
233 adts(jj)%elementType,
adts(jj)%elementID, &
238 "Deallocation failure for the ADT data")
243 adts(jj)%isActive = .false.
245 nullify (
adts(jj)%coor)
247 nullify (
adts(jj)%triaConn)
248 nullify (
adts(jj)%quadsConn)
249 nullify (
adts(jj)%tetraConn)
250 nullify (
adts(jj)%pyraConn)
251 nullify (
adts(jj)%prismsConn)
252 nullify (
adts(jj)%hexaConn)
254 nullify (
adts(jj)%rootLeavesProcs)
255 nullify (
adts(jj)%rootBBoxes)
257 nullify (
adts(jj)%elementType)
258 nullify (
adts(jj)%elementID)
259 nullify (
adts(jj)%xBBox)
261 nullify (
adts(jj)%ADTree)
265 do nn = nalloc, 1, -1
266 if (
adts(nn)%isActive)
exit
277 deallocate (
adts, stat=ierr)
278 if (ierr /= 0) stop
"Deallocation failure for ADTs"
280 else if (nn < nalloc)
then
288 allocate (tmpadts(nallocnew), stat=ierr)
291 "Memory allocation failure for tmpADTs")
296 tmpadts(nn) =
adts(nn)
305 deallocate (
adts, stat=ierr)
306 if (ierr /= 0) stop
"Deallocation failure for ADTs"
308 allocate (
adts(nallocnew), stat=ierr)
309 if (ierr /= 0) stop
"Allocation failure for ADTs"
315 adts(nn) = tmpadts(nn)
318 deallocate (tmpadts, stat=ierr)
319 if (ierr /= 0) stop
"Deallocation failure for tmpADTs"
351 type(
adttype),
intent(in) :: ADT
352 integer(kind=intType),
intent(in) :: nn, dir
354 integer(kind=intType),
dimension(:),
intent(inout) :: arr
358 integer(kind=intType),
parameter :: m = 7
362 integer(kind=intType) :: i, j, k, r, l, jStack
363 integer(kind=intType) :: a, tmp
365 real(kind=realtype) :: ra
366 real(kind=realtype),
dimension(:, :),
pointer :: xbbox
384 testinsertion:
if ((r - l) < m)
then
391 do i = (j - 1), l, -1
392 if (xbbox(dir, arr(i)) <= ra)
exit
401 if (jstack == 0)
exit sortloop
406 l =
stack(jstack - 1)
421 if (xbbox(dir, arr(r)) < xbbox(dir, arr(l)))
then
427 if (xbbox(dir, arr(r)) < xbbox(dir, arr(l + 1)))
then
433 if (xbbox(dir, arr(l + 1)) < xbbox(dir, arr(l)))
then
453 if (ra <= xbbox(dir, arr(i)))
exit
459 if (xbbox(dir, arr(j)) <= ra)
exit
464 if (j < i)
exit innerloop
488 if ((r - i + 1) >= (j - l))
then
491 stack(jstack - 1) = j
493 stack(jstack) = j - 1
494 stack(jstack - 1) = l
505 if (xbbox(dir, arr(i + 1)) < xbbox(dir, arr(i)))
then
507 "Array is not sorted correctly")
523 type(
adttype),
intent(in) :: adt
524 integer(kind=intType),
intent(in) :: nn
530 integer(kind=intType),
parameter :: m = 7
532 integer(kind=intType) :: i, j, k, r, l, jStack
548 testinsertion:
if ((r - l) < m)
then
554 do i = (j - 1), l, -1
555 if (arr(i) <= a)
exit
564 if (jstack == 0)
exit sortloop
569 l =
stack(jstack - 1)
584 if (arr(r) < arr(l))
then
590 if (arr(r) < arr(l + 1))
then
596 if (arr(l + 1) < arr(l))
then
615 if (a <= arr(i))
exit
621 if (arr(j) <= a)
exit
626 if (j < i)
exit innerloop
650 if ((r - i + 1) >= (j - l))
then
653 stack(jstack - 1) = j
655 stack(jstack) = j - 1
656 stack(jstack - 1) = l
667 if (arr(i + 1) < arr(i)) &
669 "Array is not sorted correctly")
693 character(len=*),
intent(in) :: adtID
694 integer(kind=intType),
intent(out) :: jj
700 integer(kind=intType) :: nn, nAlloc
702 type(
adttype),
dimension(:),
allocatable :: tmpADTs
709 nalloc = ubound(
adts, 1)
712 if (
adts(nn)%isActive)
then
713 if (adtid ==
adts(nn)%adtID)
exit
714 else if (jj > nalloc)
then
723 if (nn <= nalloc)
then
724 if (
adts(nn)%myID == 0) &
726 "Given ID corresponds to an already &
728 call mpi_barrier(
adts(nn)%comm, ierr)
733 checkreallocate:
if (jj > nalloc)
then
742 allocate (tmpadts(nalloc), stat=ierr)
743 if (ierr /= 0) stop
"Allocation failure for tmpADTs"
748 tmpadts(nn) =
adts(nn)
754 deallocate (
adts, stat=ierr)
755 if (ierr /= 0) stop
"Deallocation failure for ADTs"
757 allocate (
adts(jj), stat=ierr)
758 if (ierr /= 0) stop
"Allocation failure for ADTs"
763 adts(nn) = tmpadts(nn)
768 deallocate (tmpadts, stat=ierr)
769 if (ierr /= 0) stop
"Deallocation failure for tmpADTs"
773 nullify (
adts(jj)%coor)
775 nullify (
adts(jj)%triaConn)
776 nullify (
adts(jj)%quadsConn)
777 nullify (
adts(jj)%tetraConn)
778 nullify (
adts(jj)%pyraConn)
779 nullify (
adts(jj)%prismsConn)
780 nullify (
adts(jj)%hexaConn)
782 nullify (
adts(jj)%rootLeavesProcs)
783 nullify (
adts(jj)%rootBBoxes)
785 nullify (
adts(jj)%elementType)
786 nullify (
adts(jj)%elementID)
787 nullify (
adts(jj)%xBBox)
789 nullify (
adts(jj)%ADTree)
791 end if checkreallocate
815 type(
adttype),
intent(in) :: ADT
816 integer,
intent(in) :: nInc
817 integer(kind=intType),
intent(inout) :: nSize
824 integer(kind=intType) :: i, nOld
837 allocate (arr(nsize), stat=ierr)
840 "Memory allocation failure for arr.")
844 nold = min(nold, nsize)
852 deallocate (tmp, stat=ierr)
855 "Deallocation failure for tmp.")
879 type(
adttype),
intent(in) :: ADT
880 integer,
intent(in) :: nInc
881 integer(kind=intType),
intent(inout) :: nSize
883 integer(kind=intType),
dimension(:),
pointer :: arr
888 integer(kind=intType) :: i, nOld
890 integer(kind=intType),
dimension(:),
pointer :: tmp
901 allocate (arr(nsize), stat=ierr)
904 "Memory allocation failure for arr.")
908 nold = min(nold, nsize)
916 deallocate (tmp, stat=ierr)
919 "Deallocation failure for tmp.")
type(adttype), dimension(:), allocatable, target adts
subroutine deallocateadts(adtID)
subroutine qsortbboxes(arr, nn, ADT, dir)
subroutine qsortbboxtargets(arr, nn, ADT)
subroutine reallocbboxtargettypeplus(arr, nSize, nInc, ADT)
subroutine reallocplus(arr, nSize, nInc, ADT)
integer(kind=inttype) nstack
subroutine reallocateadts(adtID, jj)
integer(kind=inttype), dimension(:), pointer stack
subroutine adtterminate(ADT, routineName, errorMessage)