如何避免状态D的程序 [英] How to avoid programs in status D

查看:153
本文介绍了如何避免状态D的程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个正在读/写数据的程序(打开一个infile和一个outfile,读取infile的一部分,然后处理,然后写入outfile,然后重复这个循环),I / O值约为200M / s总。然而,大部分的运行时间,他们在状态D,这意味着等待I / O(如图所示)



我的程序效率低下吗?
或者我的硬盘有问题?
如何处理它?<​​/ p>

解决方案

如果使用ifort,则必须明确使用缓冲的I / O。标记为 -assume buffered_io 编译或设置 buffered ='yes'在中打开语句。

如果你使用的是gfortran,这是默认的,那么肯定还有其他一些问题。

编辑

我可以根据您的读写方式数据,大部分时间都可以解析,即解码ASCII等字符,并将基数从10变为2,直到它是机器可读的数据;写时则相反。如果你这样构造你的代码,就是这种情况:

  real :: vector1(10)


read(5,*)vector1!line有10个值
write(6,*)vector1
enddo

如果您改为执行以下操作,速度会更快:

 字符(1000):: line1! (5,'(A)')line1 
write(6,'(A)')line1 $ b $使用足够的字符,所以整行符合


read b enddo

现在,您只需在程序中抽取ascii,而不必知道其数字或ääåö (=)& %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%注意,大多数驱动器中都有一个写入缓存,它比磁盘的读写速度快,这意味着你可能首先受到读取速度的限制,并且在填充写入缓存之后,被写速度,通常低于读取速度。

I wrote a program that are reading/writing data (open one infile and one outfile, read part of infile, then process, then write to outfile, and that cycle repeats), with I/O value about 200M/s in total. However, most of the running time, they are in status D, which means waiting for I/O (As shown in the figure)1. I used dd check write speed in my system, that is about 1.8G/s.

Are my programs inefficient? Or my harddisk have problems? How can I deal with it?

解决方案

If using ifort, you must explicitly use buffered I/O. Flag with -assume buffered_io when compiling or set buffered='yes' in the openstatement.

If you are using gfortran this is the default, so then there must be some other problem.

Edit

I can add that depending on how you read and write the data, most time can be spent parsing it, i.e. decoding ascii characters 123 etc and changing the basis from 10 to 2 until it is machine readable data; then doing the opposite when writing. This is the case if you construct your code like this:

real :: vector1(10)

do
  read(5,*) vector1 !line has 10 values
  write(6,*) vector1
enddo

If you instead do the following, it will be much faster:

character(1000) :: line1 ! use enough characters so the whole line fits

do
  read(5,'(A)') line1 
  write(6,'(A)') line1
enddo

Now you are just pumping ascii through the program without even knowing if its digits or maybe "ääåö(=)&/&%/(¤%/&Rhgksbks---31". With these modifications I think you should reach the max of your disk speed.

Notice also that there is a write cache in most drives, which is faster than the disk read/write speeds, meaning that you might first be throttled by the read speed, and after filling up the write cache, be throttled by the write speed, which is usually lower than the read speed.

这篇关于如何避免状态D的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆