Preliminary patch for formatted I/O

Jerry DeLisle jvdelisle@verizon.net
Sun Jan 18 07:28:00 GMT 2009


Here is a patch for others to test if they so choose.  After Daniel and Janne 
get their patches (float read and low level I/O respectively) committed, I will 
merge this one in.  So I will submit for formal approval later after I adjust it 
for the merge. This will be for 4.5

What this patch does:

1) Splits formatted_transfer_scalar into two functions, 
formatted_transfer_scalar_read and formatted_transfer_scalar_write.  This 
factors all the conditionals out of the loop that traverses the parsed format 
list and places that test for reading or writing one level up, significantly 
improving performance.

2) After parsing a format string, the parsed format data is cached into a simple 
array structure added to gfc_unit.  This structure can hold pointers for up to 
16 different format strings depending on how well they hash in.  I use a very 
simple XOR hashing function on the format string to determine the cache address.

Any collisions are just ignored and I overwrite the previously saved parse data. 
  This is simply probabalistic.  If you are lucky, you get a unique location and 
you might save time later. Most likely I will make some improvements on this 
while waiting for 4.5 o happen.

The lookup function checks string length first to see if there is a match and if 
so, moves on to check that the string matches.  Its simple.  For highly 
repetitious formatted I/O re-parsing the format string more than once is 
avoided. Saving a lot of cycles.

3) Simplified the output_float format calculation somewhat.  It gives a few 
percent improvement at best, but is low hanging fruit.

This has been NIST tested, regression tested, and valgrind tested.  I checked 
performance using two test cases, countlines.f from pr37754 and mixed-test.f 
(attached).  Here are results I see on one machine.  I am sure results will vary.

mixed-test.f (5 runs)

No-patch: 21.000  22.424  19.666  20.766  21.673   avg=21.106

Patched : 17.509  17.692  16.531  16.150  16.207   avg=16.818

Improvement: 20.3%

countlines.f (5 runs)

No-patch:  4.328  3.853  3.819  3.987  3.829  avg=3.963

Patched :  3.206  3.313  3.210  3.168  3.168  avg=3.213

Improvement: 18.9%


Regards,

Jerry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: final_format_patch.diff
Type: text/x-diff
Size: 37426 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20090118/e930edb4/attachment.bin>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: mixed-test.f
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20090118/e930edb4/attachment.ksh>


More information about the Fortran mailing list