E. Yin E. Yin - 1 year ago 94
Linux Question

How to avoid programs in status D

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

check write speed in my system, that is about 1.8G/s.

enter image description here

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

Answer Source

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.


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)

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

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

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

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

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download