| 1 | program driver
|
|---|
| 2 |
|
|---|
| 3 | implicit none
|
|---|
| 4 |
|
|---|
| 5 | integer :: blockCount
|
|---|
| 6 | integer ::blockList(blockCount)
|
|---|
| 7 | real :: dt,time
|
|---|
| 8 |
|
|---|
| 9 | !! Allocated in amr_initialize.F90 Line 282
|
|---|
| 10 | real :: unk(NVAR,NXB+2*NGUARD,NYB+2*NGUARD*K2D,NZB+2*NGUARD*K3D,MAXBLOCKS)
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 | call Heat(blockCount, blockList, dt, time)
|
|---|
| 15 |
|
|---|
| 16 | end program
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 | subroutine Init()
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 | #include "Flash.h"
|
|---|
| 23 | #include "constants.h"
|
|---|
| 24 |
|
|---|
| 25 | implicit none
|
|---|
| 26 |
|
|---|
| 27 | integer :: pid
|
|---|
| 28 | real :: unk(:,:,:,:,:)
|
|---|
| 29 |
|
|---|
| 30 | integer :: gr_globalNumBlocks, alnblocks, io_meshNumProcs
|
|---|
| 31 | integer :: xx, yy, procBlocks, io_meshMe, localNumBlocks
|
|---|
| 32 | integer :: gr_nToLeft(0:NPROC)
|
|---|
| 33 |
|
|---|
| 34 | integer :: mblk
|
|---|
| 35 |
|
|---|
| 36 | mblk = MAXBLOCKS
|
|---|
| 37 | gr_globalNumBlocks = NBLOCK
|
|---|
| 38 | io_meshNumProcs = NPROC
|
|---|
| 39 | io_meshMe = pid
|
|---|
| 40 |
|
|---|
| 41 | !! src: source/IO/IOMain/hdf5/parallel/PM/io_readData.F90 #196--284
|
|---|
| 42 |
|
|---|
| 43 | !---------------------------------------------------------------------------
|
|---|
| 44 | ! compute the number of blocks on each processor -- this will be used to
|
|---|
| 45 | ! get the offset into the file for the parallel read
|
|---|
| 46 | !---------------------------------------------------------------------------
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | #ifndef _CIVL
|
|---|
| 50 | ! compute the approximate number of blocks per processor
|
|---|
| 51 | alnblocks = int(gr_globalNumBlocks/io_meshNumProcs) + 1
|
|---|
| 52 |
|
|---|
| 53 | ! check for error -- if the number of blocks we want to put on each
|
|---|
| 54 | ! processor is greater than maxblocks, then abort
|
|---|
| 55 | if (alnblocks .GT. MAXBLOCKS) then
|
|---|
| 56 |
|
|---|
| 57 | print *
|
|---|
| 58 | print *, '********** ERROR in READ_DATA ************'
|
|---|
| 59 | print *
|
|---|
| 60 | print *,' Number of blocks per processor exceeds maxblocks.'
|
|---|
| 61 | print *,' Suggest you reset maxblocks to a larger number or'
|
|---|
| 62 | print *,' run on a larger number of processors.'
|
|---|
| 63 | print *,' globalNumBlocks, io_meshNumProcs = ', gr_globalNumBlocks, io_meshNumProcs
|
|---|
| 64 | print *
|
|---|
| 65 |
|
|---|
| 66 | call Driver_abortFlash('[io_readData] ERROR: num blocks per proc exceeds maxblocks')
|
|---|
| 67 |
|
|---|
| 68 | end if
|
|---|
| 69 |
|
|---|
| 70 | #else
|
|---|
| 71 |
|
|---|
| 72 | alnblocks = gr_globalNumBlocks/io_meshNumProcs + 1
|
|---|
| 73 |
|
|---|
| 74 | !$ CIVL $assert(alnblocks <= mblk)
|
|---|
| 75 |
|
|---|
| 76 | #endif
|
|---|
| 77 | !! end ifndef _CIVL (the 1st one)
|
|---|
| 78 |
|
|---|
| 79 | ! figure out the excess blocks
|
|---|
| 80 | yy = (io_meshNumProcs*alnblocks) - gr_globalNumBlocks
|
|---|
| 81 | xx = io_meshNumProcs - yy
|
|---|
| 82 |
|
|---|
| 83 | ! loop over all the processor numbers and figure out how many blocks are
|
|---|
| 84 | ! stored to the left of the processor -- this is a little tricky
|
|---|
| 85 |
|
|---|
| 86 | gr_nToLeft(0) = 0
|
|---|
| 87 |
|
|---|
| 88 | do i = 0, io_meshNumProcs - 2
|
|---|
| 89 | if (i .LT. xx) then
|
|---|
| 90 | procBlocks = alnblocks
|
|---|
| 91 | else
|
|---|
| 92 | procBlocks = alnblocks - 1
|
|---|
| 93 | endif
|
|---|
| 94 |
|
|---|
| 95 | if (alnblocks .EQ. 0) then
|
|---|
| 96 | if (i .LT. gr_globalNumBlocks) then
|
|---|
| 97 | procBlocks = 1
|
|---|
| 98 | else
|
|---|
| 99 | procBlocks = 0
|
|---|
| 100 | end if
|
|---|
| 101 | end if
|
|---|
| 102 |
|
|---|
| 103 | ! we have the number of blocks on proc i, the number of blocks on i+1 is
|
|---|
| 104 | ! the number of blocks on i + the number of blocks left of i
|
|---|
| 105 | if (i .EQ. 0) then
|
|---|
| 106 | gr_nToLeft(i+1) = procBlocks
|
|---|
| 107 | else
|
|---|
| 108 | gr_nToLeft(i+1) = procBlocks + gr_nToLeft(i)
|
|---|
| 109 | endif
|
|---|
| 110 | enddo
|
|---|
| 111 |
|
|---|
| 112 | ! figure out how many blocks are on the current proc.
|
|---|
| 113 | if (io_meshMe < xx) then
|
|---|
| 114 | localNumBlocks = alnblocks
|
|---|
| 115 | else
|
|---|
| 116 | localNumBlocks = alnblocks - 1
|
|---|
| 117 | endif
|
|---|
| 118 |
|
|---|
| 119 | if (alnblocks .EQ. 0) then
|
|---|
| 120 | if (io_meshMe < gr_globalNumBlocks) then
|
|---|
| 121 | localNumBlocks = 1
|
|---|
| 122 | else
|
|---|
| 123 | localNumBlocks = 0
|
|---|
| 124 | end if
|
|---|
| 125 | end if
|
|---|
| 126 |
|
|---|
| 127 | ! compute the offset into the dataspace in the HDF5 file
|
|---|
| 128 | gr_globalOffset = gr_nToLeft(io_meshMe)
|
|---|
| 129 |
|
|---|
| 130 | #ifndef _CIVL
|
|---|
| 131 |
|
|---|
| 132 | call Grid_putLocalNumBlks(localNumBlocks)
|
|---|
| 133 |
|
|---|
| 134 | !find our offset into a potentially split file:
|
|---|
| 135 | if(io_outputSplitNum > 1) then
|
|---|
| 136 | call MPI_ALLREDUCE(gr_globalOffset, splitOffset,1,FLASH_INTEGER,&
|
|---|
| 137 | MPI_MIN, io_comm, ierr)
|
|---|
| 138 | localOffset = gr_globalOffset - splitOffset
|
|---|
| 139 |
|
|---|
| 140 | else
|
|---|
| 141 | localOffset = gr_globalOffset
|
|---|
| 142 | end if
|
|---|
| 143 |
|
|---|
| 144 | #else
|
|---|
| 145 |
|
|---|
| 146 | localOffset = gr_globalOffset
|
|---|
| 147 |
|
|---|
| 148 | #endif
|
|---|
| 149 | !! end ifndef _CIVL (the 2nd one)
|
|---|
| 150 |
|
|---|
| 151 | end subroutine Init
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 | subroutine Heat(blockCount, blockList, dt, time)
|
|---|
| 155 |
|
|---|
| 156 | #include "Flash.h"
|
|---|
| 157 | #include "constants.h"
|
|---|
| 158 |
|
|---|
| 159 | implicit none
|
|---|
| 160 |
|
|---|
| 161 | integer :: blockCount
|
|---|
| 162 | integer ::blockList(blockCount)
|
|---|
| 163 | real :: dt,time
|
|---|
| 164 |
|
|---|
| 165 | real, pointer :: solnData(:,:,:,:)
|
|---|
| 166 | integer :: blockID, i,j,k,n
|
|---|
| 167 |
|
|---|
| 168 | !$omp parallel default(shared) private(n,blockID,k,j,i,solnData)
|
|---|
| 169 | !$omp do
|
|---|
| 170 | do n = 1, blockCount
|
|---|
| 171 | blockID = blockList(n)
|
|---|
| 172 |
|
|---|
| 173 | solnData => unk(:,:,:,:,blockID)
|
|---|
| 174 |
|
|---|
| 175 | do k = 1, 1
|
|---|
| 176 | do j = 1, 1
|
|---|
| 177 | do i = NGUARD + 1, NGUARD + NXB
|
|---|
| 178 |
|
|---|
| 179 | solnData(1,i,j,k) = solnData(1,i,j,k) + 10.0*dt
|
|---|
| 180 |
|
|---|
| 181 | enddo
|
|---|
| 182 | enddo
|
|---|
| 183 | enddo
|
|---|
| 184 |
|
|---|
| 185 | nullify(solndata)
|
|---|
| 186 |
|
|---|
| 187 | enddo
|
|---|
| 188 | !$omp end do
|
|---|
| 189 | !$omp end parallel
|
|---|
| 190 |
|
|---|
| 191 | end subroutine Heat
|
|---|