[Patch, Fortran] PR25829: Asynchronous I/O

Nicolas Koenig nk@koenigni.com
Sun Jun 3 19:00:00 GMT 2018


Hello everyone,

this patch adds asynchronous I/O support. Thomas and I finally finished 
a feature-complete and debugged version, so here it is. In order to use 
asynchronous I/O, it is still necessary to link against libpthread, 
libgomp or another library linked against any of the aforementioned two. 
While it might not be the nicest way, it at least keeps in line with the 
likes of ifort. Two of the test I send deal with asynchronous error 
handling, so they will fail if not linked accordingly.

Since the implementation relies on pthreads, it would be great if 
somebody could try the patch on non-linux targets, to see whether it 
causes any problems there.

Let the rain of regressions begin ;)

	Nicolas

P.S.: I would very much recommend removing the #undef DEBUG in async.h. 
I have to admit, I am quite proud of the debug printouts. They even 
build a data structure in the background telling you were a locked mutex 
was locked.


Regression tested cleanly on x86_64-pc-linux-gnu.

2018-06-03  Nicolas Koenig  <koenigni@gcc.gnu.org>
         Thomas Koenig <tkoenig@gcc.gnu.org>

         PR fortran/25829
         * trans-decl.c (gfc_finish_var_decl): Treat asynchronous variables
         as volatile.
         * trans-io.c (gfc_build_io_library_fndecls): Rename st_wait to
         st_wait_async and change argument spec from ".X" to ".w".
         (gfc_trans_wait): Pass ID argument via reference.

2018-06-03  Nicolas Koenig  <koenigni@gcc.gnu.org>
         Thomas Koenig <tkoenig@gcc.gnu.org>

         PR fortran/25829
         * Makefile.am: Add async.c to gfor_io_src.
         Add async.h to gfor_io_headers.
         * Makefile.in: Regenerated.
         * gfortran.map: Add _gfortran_st_wait_async.
         * io/async.c: New file.
         * io/async.h: New file.
         * io/close.c: Include async.h.
         (st_close): Call async_wait for an asynchronous unit.
         * io/file_pos.c (st_backspace): Likewise.
         (st_endfile): Likewise.
         (st_rewind): Likewise.
         (st_flush): Likewise.
         * io/inquire.c: Add handling for asynchronous PENDING
         and ID arguments.
         * io/io.h (st_parameter_dt): Add async bit.
         (st_parameter_wait): Correct.
         (gfc_unit): Add au pointer.
         (st_wait_async): Add prototype.
         (transfer_array_inner): Likewise.
         (st_write_done_worker): Likewise.
         * io/open.c: Include async.h.
         (new_unit): Initialize asynchronous unit.
         * io/transfer.c (async_opt): New struct.
         (wrap_scalar_transfer): New function.
         (transfer_integer): Call wrap_scalar_transfer to do the work.
         (transfer_real): Likewise.
         (transfer_real_write): Likewise.
         (transfer_character): Likewise.
         (transfer_character_wide): Likewise.
         (transfer_complex): Likewise.
         (transfer_array_inner): New function.
         (transfer_array): Call transfer_array_inner.
         (transfer_derived): Call wrap_scalar_transfer.
         (data_transfer_init): Check for asynchronous I/O.
         Perform a wait operation on any pending asynchronous I/O
         if the data transfer is synchronous. Copy PDT and enqueue
         thread for data transfer.
         (st_read_done_worker): New function.
         (st_read_done): Enqueue transfer or call st_read_done_worker.
         (st_write_done_worker): New function.
         (st_write_done): Enqueue transfer or call st_read_done_worker.
         (st_wait): Document as no-op for compatibility reasons.
         (st_wait_async): New function.
         * io/unit.c (insert_unit): Use macros LOCK, UNLOCK and TRYLOCK;
         add NOTE where necessary.
         (get_gfc_unit): Likewise.
         (init_units): Likewise.
         (close_unit_1): Likewise. Call async_close if asynchronous.
         (close_unit): Use macros LOCK and UNLOCK.
         (finish_last_advance_record): Likewise.
         (newunit_alloc): Likewise.
         * io/unix.c (find_file): Likewise.
         (flush_all_units_1): Likewise.
         (flush_all_units): Likewise.
         * libgfortran.h (generate_error_common): Add prototype.
         * runtime/error.c: Include io.h and async.h.
         (generate_error_common): New function.

2018-06-03  Nicolas Koenig  <koenigni@gcc.gnu.org>
         Thomas Koenig <tkoenig@gcc.gnu.org>

         PR fortran/25829
         * testsuite/libgfomp.fortran/asynchronous_6.f90: New test.
         * testsuite/libgfomp.fortran/asynchronous_8.f90: New test.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: p8f.diff
Type: text/x-patch
Size: 53081 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20180603/bd25012d/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: asynchronous_6.f90
Type: text/x-fortran
Size: 1324 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20180603/bd25012d/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: asynchronous_8.f90
Type: text/x-fortran
Size: 371 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20180603/bd25012d/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: asynchronous_9.f90
Type: text/x-fortran
Size: 491 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20180603/bd25012d/attachment-0003.bin>


More information about the Fortran mailing list