RAM 디스크의 세부 정보로 이동하는 대신 ASCII 데이터베이스에서 이진 데이터베이스로 전환하는 것이 좋습니다. 여기
program writeArr
use,intrinsic :: ISO_Fortran_env, only: REAL64
implicit none
real(REAL64),allocatable :: tmp(:,:)
integer :: uFile, i
allocate(tmp(10000,10000))
! Formatted read
open(unit=uFile, file='ASCII.txt',form='formatted', &
status='replace',action='write')
do i=1,size(tmp,1)
write(uFile,*) tmp(:,i)
enddo !i
close(uFile)
! Unformatted read
open(unit=uFile, file='binary.bin',form='unformatted', &
status='replace',action='write')
write(uFile) tmp
close(uFile)
end program
크기의 관점에서 그 결과는 : 여기 아주 단순한 예 ... ASCII (ASCII.txt)로 저장된 난수의 배열, 및 이진 된 날짜 (binary.bin)입니다
:> ls -lah ASCII.txt binary.bin
-rw-rw-r--. 1 elias elias 2.5G Feb 20 20:59 ASCII.txt
-rw-rw-r--. 1 elias elias 763M Feb 20 20:59 binary.bin
따라서 저장시 약 3.35 배를 절약 할 수 있습니다. 이제 재미있는 부분을 제공 :에 ...
program readArr
use,intrinsic :: ISO_Fortran_env, only: REAL64
implicit none
real(REAL64),allocatable :: tmp(:,:)
integer :: uFile, i
integer :: count_rate, iTime1, iTime2
allocate(tmp(10000,10000))
! Get the count rate
call system_clock(count_rate=count_rate)
! Formatted write
open(unit=uFile, file='ASCII.txt',form='formatted', &
status='old',action='read')
call system_clock(iTime1)
do i=1,size(tmp,1)
read(uFile,*) tmp(:,i)
enddo !i
call system_clock(iTime2)
close(uFile)
print *,'ASCII read ',real(iTime2-iTime1,REAL64)/real(count_rate,REAL64)
! Unformatted write
open(unit=uFile, file='binary.bin',form='unformatted', &
status='old',action='read')
call system_clock(iTime1)
read(uFile) tmp
call system_clock(iTime2)
close(uFile)
print *,'Binary read ',real(iTime2-iTime1,REAL64)/real(count_rate,REAL64)
end program
다시 읽기 결과는 그래서
ASCII read 37.250999999999998
Binary read 1.5460000000000000
> (24)의 요인이다!
그래서 다른 것을 생각하지 않고 먼저 이진 파일 형식으로 전환하십시오.
내가 선택한 답변에 더 일치하도록 제목을 약간 변경했습니다. 그 대답은 원래 대답 100 % (RAM에 파티션을 수행하는 방법에 대한 단서 없음)에 맞지 않지만 녹색 태그를 부여하지 않으면 너무 유용합니다. 나는 특별히 RAM 디렉토리에 관한 다른 질문을 게시 할 것이다. – Mephisto
몇 가지 실제 측정을 했습니까? 예를 들어 ASCII 데이터 형식을 구문 분석하는 것보다 병목 현상이 디스크 입출력이라는 것을 추측하고 있습니까? 램 디스크에 충분한 RAM이 있다고 가정하면 디스크 캐시를 충분히 사용할 수 있기 때문에 이미 어쨌든 메모리에서 대부분 읽는 것이 좋습니다. 이에 대한 대답은 받아 들여지고있다. –
@ DanMašek 당신이 제안한 내용을 무시했지만 연속 로그인보다 코드가 처음 실행될 때 동일한 시간이 걸린다고 생각합니다. 또한 파일을 읽는 동안 TOP 명령은 100 % CPU 활동을 표시하지 않으므로 아마도 하드 드라이브 읽기에 문제가있는 것입니다. – Mephisto