Scrambler
1
|
00001 !######################################################################### 00002 ! 00003 ! Copyright (C) 2003-2012 Department of Physics and Astronomy, 00004 ! University of Rochester, 00005 ! Rochester, NY 00006 ! 00007 ! io_control.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 !######################################################################### 00025 00028 00031 00035 00040 MODULE IOControl 00041 00042 USE GlobalDeclarations 00043 USE CommunicationDeclarations 00044 USE IODeclarations 00045 USE HDF5Declarations 00046 USE IOChombo 00047 USE IOComms 00048 USE IOOkc 00049 USE DataDeclarations 00050 USE Timing 00051 IMPLICIT NONE 00052 PRIVATE 00053 00054 ! INCLUDE 'mpif.h' 00055 00056 PUBLIC IOInit, WriteDataFrame, IORestartInit, IORestartFinalize, IOReloadLevel, IOClose, PostIO 00057 00058 CONTAINS 00059 00060 00061 SUBROUTINE PostIO(frame) 00062 INTEGER :: frame 00063 CHARACTER(21) :: syscmd 00064 LOGICAL :: ex 00065 IF (MPI_ID == 0) THEN 00066 Inquire(file="postprocess.s", exist=ex) 00067 IF (ex) THEN 00068 write(syscmd,'(A16,I5.5)') './postprocess.s ', frame 00069 CALL System(syscmd) 00070 END IF 00071 END IF 00072 END SUBROUTINE PostIO 00073 00075 SUBROUTINE IOInit 00076 00077 INTEGER :: iErr 00078 00079 ! Read in scheme value. 00080 ! READ(GLOBAL_DATA_HANDLE,NML=IOData,IOStat=iErr) 00081 00082 ! IF(iErr/=0) THEN 00083 ! PRINT *, "IOInit() error: unable to read ", GLOBAL_DATA_FILE, "." 00084 ! STOP 00085 ! END IF 00086 00087 iDataFileType=IO_CHOMBO 00088 00089 SELECT CASE (iDataFileType) 00090 CASE (IO_CHOMBO) 00091 CALL HDF5Init() 00092 t_io_cumulative = 0.d0 00093 00094 CASE (IO_BOV) 00095 PRINT *, "WriteDataFrame() error: BOV output format not yet implemented." 00096 STOP 00097 00098 CASE DEFAULT 00099 PRINT "('WriteDataFrame() error: invalid data file output ', i2, '.')", iDataFileType 00100 STOP 00101 00102 END SELECT 00103 00104 END SUBROUTINE IOInit 00105 00107 SUBROUTINE IOClose 00108 00109 SELECT CASE (iDataFileType) 00110 CASE (IO_CHOMBO) 00111 CALL HDF5Finalize() 00112 00113 CASE (IO_BOV) 00114 PRINT *, "IOClose() error: BOV output format not yet implemented." 00115 STOP 00116 00117 CASE DEFAULT 00118 PRINT "('IOClose() error: invalid data file output ', i2, '.')", iDataFileType 00119 STOP 00120 00121 END SELECT 00122 00123 END SUBROUTINE IOClose 00124 00127 SUBROUTINE WriteDataFrame(nframe) 00128 00129 USE MessageDeclarations, ONLY: TERMINATION_BOX_BYTES 00130 USE ChomboDeclarations, ONLY: CHOMBO_DOMAIN_LEVEL 00131 00132 INTEGER :: nframe 00133 00134 INTEGER :: level, n 00135 INTEGER :: finest_level 00136 INTEGER, DIMENSION(IO_LEVEL_STAT_COUNT) :: data_sizes 00137 INTEGER :: buffer_size 00138 00139 CALL StartTimer(iWriteData, -2) 00140 00141 IF (MPI_ID == 0) t_io_start = MPI_Wtime() 00142 00143 ! The iDataFileType variable is read in from the GlobalData namelist. 00144 SELECT CASE (iDataFileType) 00145 00146 CASE (IO_CHOMBO) 00147 00148 ! finest_level = GetFinestLevel() 00149 finest_level = MaxLevel 00150 00151 IF (MPI_id == Master) THEN 00152 00153 ! Write the chombo file (timing the process). 00154 00155 CALL MakeChomboFile(nframe) 00156 CALL MakeOKCFile(nframe) 00157 ! t_end = MPI_Wtime() 00158 00159 ! t_io_cumulative = t_io_cumulative + t_end - t_start 00160 00161 ELSE 00162 ! Non-master processors send their data to the master level-by-level; 00163 ! first the tree data, then the grid data. 00164 00165 data_sizes = 0 00166 00167 DO level = -2, finest_level 00168 00169 ! Add the overhead for a Chombo level transmission to the cost of the next level's data. 00170 IF (level > CHOMBO_DOMAIN_LEVEL) buffer_size = data_sizes(IO_NEXTLEVELCOST) + & 00171 TERMINATION_BOX_BYTES + & 00172 IO_LEVEL_STAT_BYTES 00173 00174 CALL IO_GetDatasetSizes(level, finest_level, data_sizes) 00175 00176 IF (level > CHOMBO_DOMAIN_LEVEL) THEN 00177 CALL IO_ScheduleSendFrameData(level, finest_level, buffer_size, data_sizes) 00178 ELSE IF (level == CHOMBO_DOMAIN_LEVEL) THEN 00179 CALL IO_ScheduleSendDomainData(data_sizes) 00180 END IF 00181 END DO 00182 END IF 00183 00184 CASE (IO_BOV) 00185 PRINT *, "WriteDataFrame() error: BOV output format not yet implemented." 00186 STOP 00187 00188 CASE DEFAULT 00189 PRINT "('WriteDataFrame() error: invalid data file output ', i2, '.')", iDataFileType 00190 STOP 00191 00192 END SELECT 00193 00194 ! print statistics on how much time is spent writing output. 00195 IF (MPI_id == Master) THEN 00196 t_io_end=MPI_WTime() 00197 t_io_cumulative=t_io_end-t_io_start 00198 PRINT "('Time to make output file ', i4, ': ', f8.4, ' seconds.')", nframe, t_io_end - t_io_start 00199 ! PRINT "('Cumulative output file time: ', f11.4, ' seconds.')", t_io_cumulative 00200 END IF 00201 00202 CALL StopTimer(iWriteData, -2) 00203 END SUBROUTINE WriteDataFrame 00204 00207 SUBROUTINE IORestartInit(nframe) 00208 00209 INTEGER :: nframe 00210 00211 00212 00213 IF (MPI_id == Master) t_io_start=MPI_WTIME() 00214 00215 ! The iDataFileType variable is read in from the GlobalData namelist. 00216 SELECT CASE (iDataFileType) 00217 CASE (IO_CHOMBO) 00218 CALL ChomboRestartInit(nframe) 00219 00220 CASE (IO_BOV) 00221 PRINT *, "IORestartInit() error: BOV output format not yet implemented." 00222 STOP 00223 00224 CASE DEFAULT 00225 PRINT "('IORestartInit() error: invalid data file output ', i2, '.')", iDataFileType 00226 STOP 00227 00228 END SELECT 00229 00230 END SUBROUTINE IORestartInit 00231 00232 00233 00236 SUBROUTINE IORestartFinalize(nframe) 00237 00238 INTEGER :: nframe 00239 00240 ! The iDataFileType variable is read in from the GlobalData namelist. 00241 SELECT CASE (iDataFileType) 00242 CASE (IO_CHOMBO) 00243 00244 CALL ChomboRestartFinalize(nframe) 00245 00246 CASE (IO_BOV) 00247 PRINT *, "IORestartFinalize() error: BOV output format not yet implemented." 00248 STOP 00249 00250 CASE DEFAULT 00251 PRINT "('IORestartFinalize() error: invalid data file output ', i2, '.')", iDataFileType 00252 STOP 00253 00254 END SELECT 00255 00256 ! print statistics on how much time is spent restarting. 00257 IF (MPI_id == 0) THEN 00258 t_io_end=MPI_WTime() 00259 t_io_cumulative=t_io_end-t_io_start 00260 PRINT "('Time to restart from output file ', i4, ': ', f8.4, ' seconds.')", restart_frame, t_io_end - t_io_start 00261 ! PRINT "('Cumulative output file time: ', f8.4, ' seconds.')", t_io_cumulative 00262 END IF 00263 00264 END SUBROUTINE IORestartFinalize 00265 00268 SUBROUTINE IOReloadLevel(n) 00269 00270 INTEGER :: n 00271 00272 REAL(KIND=qPrec) :: t_start, t_end 00273 00274 00275 ! The iDataFileType variable is read in from the GlobalData namelist. 00276 SELECT CASE (iDataFileType) 00277 CASE (IO_CHOMBO) 00278 00279 CALL ChomboReloadLevel(n) 00280 00281 CASE (IO_BOV) 00282 PRINT *, "ReLoadLevel() error: BOV output format not yet implemented." 00283 STOP 00284 00285 CASE DEFAULT 00286 PRINT "('ReLoadLevel() error: invalid data file output ', i2, '.')", iDataFileType 00287 STOP 00288 00289 END SELECT 00290 00291 00292 END SUBROUTINE IOReloadLevel 00293 00294 00295 00296 00297 00298 END MODULE IOControl 00299