Version 2 (modified by trackstand, 10 years ago) (diff) 

Discussion of coding approach/style for dynamic memory
As a basis for the discussion, here's how I've currently coded NEMO (v.3.2) to use dynamic memory.
Highestlevel changes are in OPA_SRC/opa.F90 and the routine opa_init():
#if defined key_mpp_dyndist ! Decide on size of grid now that we have our communicator size ! If we're not using dynamic memory then mpp_partition does nothing. #if defined key_mpp_mpi  defined key_mpp_shmem CALL opa_partition() #else jpni = 1 jpnj = 1 jpnij = jpni*jpnj #endif ! Calculate domain dimensions given calculated jpi and jpj jpi = ( jpiglo2*jpreci + (jpni1) ) / jpni + 2*jpreci !: first dim. jpj = ( jpjglo2*jprecj + (jpnj1) ) / jpnj + 2*jprecj !: second dim. jpim1 = jpi1 !: inner domain indices jpjm1 = jpj1 !: " " jpkm1 = jpk1 !: " " jpij = jpi*jpj !: jpi x j ! Now we know the dimensions of the grid, allocate arrays CALL opa_alloc() #endif
The inclusion of the new code is currently controlled by the cpp key 'key_mpp_dyndist' but it would greatly improve the cleanliness of the code if we make a complete break from the staticmemory version and thus can drop the use of this cpp key. My understanding of the conclusion of the meeting in Southampton was that this is what we're going to do.
This addition to opa_init() calls two further new routines, opa_partition() and opa_alloc():
SUBROUTINE opa_partition USE par_oce IMPLICIT none INTEGER, PARAMETER :: nfactmax = 20 INTEGER :: nfact ! The no. of factors returned INTEGER :: ierr ! Error flag INTEGER :: i INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are ! closest in value INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors ierr = 0 #if ! defined key_mpp_dyndist RETURN ! If we aren't using dynamic memory then jpnj and jpni are set ! at compile time #else CALL factorise(ifact, nfactmax, nfact, mppsize, ierr) IF(nfact <= 1)THEN WRITE (numout, *) 'WARNING: factorisation of number of PEs failed' WRITE (numout, *) ' : using grid of ',mppsize,' x 1' jpnj = 1 jpni = mppsize ELSE ! Search through factors for the pair that are closest in value mindiff = 1000000 imin = 1 DO i=1,nfact1,2 idiff = ABS(ifact(i)  ifact(i+1)) IF(idiff < mindiff)THEN mindiff = idiff imin = i END IF END DO jpnj = ifact(imin) jpni = ifact(imin + 1) ENDIF jpnij = jpni*jpnj WRITE(*,*) 'ARPDBG: jpni = ',jpni,'jpnj = ',jpnj,'jpnij = ',jpnij #endif END SUBROUTINE opa_partition
where factorise() returns the prime factors of its argument.
Attachments (1)

Dynamic_Memory_in_NEMO.pdf
(75.5 KB) 
added by rblod 10 years ago.
Andrew Porter Presentation
Download all attachments as: .zip