Scrambler  1
layout_declarations.f90
Go to the documentation of this file.
00001 !#########################################################################
00002 !               
00003 !    Copyright (C) 2003-2012 Department of Physics and Astronomy,
00004 !                            University of Rochester,
00005 !                            Rochester, NY
00006 !
00007 !    layout.f90 is part of AstroBEAR.
00008 !
00009 !    AstroBEAR is free software: you can redistribute it and/or modify    
00010 !    it under the terms of the GNU General Public License as published by 
00011 !    the Free Software Foundation, either version 3 of the License, or    
00012 !    (at your option) any later version.
00013 !
00014 !    AstroBEAR is distributed in the hope that it will be useful, 
00015 !    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 !    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 !    GNU General Public License for more details.
00018 !
00019 !    You should have received a copy of the GNU General Public License
00020 !    along with AstroBEAR.  If not, see <http://www.gnu.org/licenses/>.
00021 !
00022 !#########################################################################
00023 MODULE LayoutDeclarations
00024   USE GlobalDeclarations
00025   IMPLICIT NONE
00026 
00027   TYPE LayoutDef
00028      INTEGER, ALLOCATABLE, DIMENSION(:,:,:) :: mB
00029      INTEGER :: level
00030   END TYPE LayoutDef
00031 
00032   TYPE pLayoutDef
00033      TYPE(LayoutDef), POINTER :: p
00034   END type pLayoutDef
00035 
00036 CONTAINS
00037   
00038   SUBROUTINE CreateLayout(mB, layout)
00039     TYPE(LayoutDef), POINTER :: layout
00040     INTEGER, DIMENSION(3,2) :: mB
00041     ALLOCATE(layout)
00042     ALLOCATe(layout%mB(0:MPI_NP-1, 3, 2))
00043     CALL split(mB, (/0,MPI_NP-1/), layout)
00044   END SUBROUTINE CreateLayout
00045 
00046   SUBROUTINE DestroyLayout(layout)
00047     TYPE(LayoutDef), POINTER :: layout
00048     DEALLOCATE(layout%mB)
00049     DEALLOCATE(layout)
00050     NULLIFY(layout)
00051   END SUBROUTINE DestroyLayout
00052   
00053 
00054 
00055   recursive subroutine split(mB, procs, layout)
00056     INTEGER, DIMENSION(3,2) :: mB, mBl, mBr
00057     INTEGER, DIMENSION(2) :: procs, procsL, procsR
00058     TYPE(LayoutDef) :: layout
00059     INTEGER :: nprocs, mx(3), split_point, split_dir
00060     REAL(8) :: split_weight
00061     mx=mB(:,2)-mB(:,1)+1
00062     nprocs=procs(2)-procs(1)+1
00063     IF (nprocs == 1) THEN
00064        IF (ALL(mB(:,2) >= mB(:,1))) THEN
00065           layout%mB(procs(1),:,:)=mB
00066        ELSE
00067           layout%mB(procs(1),:,:)=0
00068        END IF
00069        RETURN
00070     END IF
00071     split_weight=REAL((nprocs/2))/REAL(nprocs) !if procs is odd this is < ncells
00072     split_dir=sum(maxloc(mx))
00073     split_point=mB(split_dir,1)-1+nint(split_weight*mx(split_dir))
00074     mBL=mB
00075     mBR=mB
00076     mBL(split_dir,2)=split_point
00077     mBR(split_dir,1)=split_point+1
00078     procsl=procs
00079     procsr=procs
00080     procsl(2)=procs(1)-1+nprocs/2
00081     procsr(1)=procs(1)-1+nprocs/2+1
00082     CALL split(mBL, procsl, layout)
00083     CALL split(mBR, procsR, layout)
00084   END subroutine split
00085 
00086 
00087 
00088   SUBROUTINE StoreLayout(layout, data, name)
00089      TYPE(LayoutDef), POINTER :: layout
00090      REAL(KIND=qPREC), DIMENSION(:,:,:,:), POINTER :: data
00091      CHARACTER(LEN=*) :: name
00092      CHARACTER(LEN=80) :: myname
00093      INTEGER :: nfields
00094      INTEGER :: mB(3,2)
00095      nfields=size(data,4)
00096      WRITE(myname, '(A,I4.4,A)') TRIM(name), MPI_ID, '.dat'
00097      OPEN(UNIT=LAYOUT_DATA_HANDLE, FILE=myname, STATUS='replace')
00098      WRITE(LAYOUT_DATA_HANDLE, '(I4)') nfields
00099      WRITE(LAYOUT_DATA_HANDLE, '(6I10)') layout%mB
00100      WRITE(LAYOUT_DATA_HANDLE, '(16E25.16)') data
00101      CLOSE(LAYOUT_DATA_HANDLE)
00102   END SUBROUTINE StoreLayout
00103   
00104   SUBROUTINE LoadLayout(layout, data, name)
00105      TYPE(LayoutDef), POINTER :: layout
00106      REAL(KIND=qPREC), DIMENSION(:,:,:,:), POINTER :: data
00107      CHARACTER(LEN=*) :: name
00108      CHARACTER(LEN=80) :: myname
00109      INTEGER :: nfields
00110      INTEGER :: mB(3,2)
00111      WRITE(myname, '(A,I4.4,A)') TRIM(name), MPI_ID, '.dat'
00112      OPEN(UNIT=LAYOUT_DATA_HANDLE, FILE=myname, STATUS='replace')
00113      READ(LAYOUT_DATA_HANDLE, '(I4)') nfields
00114      READ(LAYOUT_DATA_HANDLE, '(6I10)') layout%mB
00115      mb=layout%mB(MPI_ID,:,:)
00116      ALLOCATE(data(mb(1,1):mb(1,2), mb(2,1):mb(2,2), mb(3,1):mb(3,2),nfields))
00117      READ(LAYOUT_DATA_HANDLE, '(16E25.16)') data
00118      CLOSE(LAYOUT_DATA_HANDLE)     
00119   END SUBROUTINE LoadLayout
00120 
00121 END MODULE LayoutDeclarations
 All Classes Files Functions Variables