24.05.2014 Views

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

XL Fortran Enterprise Edition for AIX : User's Guide - IBM

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

statements from different threads at the same time, you must use this library. In<br />

other words, to per<strong>for</strong>m <strong>Fortran</strong> I/O in parallel, you must link applications with<br />

this library to get expected results.<br />

However, note that on <strong>AIX</strong> operating system levels Version 4.3 and higher, a link is<br />

provided from the libxlf90.a library to the libxlf90_r.a library. You do not need to<br />

link with separate libraries depending on whether you are creating a threaded or a<br />

non-threaded application. <strong>XL</strong> <strong>Fortran</strong> determines at run time whether your<br />

application is threaded.<br />

Synchronization of I/O Operations<br />

During parallel execution, multiple threads might per<strong>for</strong>m I/O operations on the<br />

same file at the same time. If they are not synchronized, the results of these I/O<br />

operations could be shuffled or merged or both, and the application might produce<br />

incorrect results or even terminate. The <strong>XL</strong> <strong>Fortran</strong> thread-safe I/O library<br />

synchronizes I/O operations <strong>for</strong> parallel applications. It per<strong>for</strong>ms the<br />

synchronization within the I/O library, and it is transparent to application<br />

programs. The purpose of the synchronization is to ensure the integrity and<br />

correctness of each individual I/O operation. However, the thread-safe I/O library<br />

does not have control over the order in which threads execute I/O statements.<br />

There<strong>for</strong>e, the order of records read in or written out is not predictable under<br />

parallel I/O operations. Refer to “Parallel I/O Issues” <strong>for</strong> details.<br />

External Files: For external files, the synchronization is per<strong>for</strong>med on a per-unit<br />

basis. The <strong>XL</strong> <strong>Fortran</strong> thread-safe I/O library ensures that only one thread can<br />

access a particular logical unit to prevent several threads from interfering with<br />

each other. When a thread is per<strong>for</strong>ming an I/O operation on a unit, other threads<br />

attempting to per<strong>for</strong>m I/O operations on the same unit must wait until the first<br />

thread finishes its operation. There<strong>for</strong>e, the execution of I/O statements by<br />

multiple threads on the same unit is serialized. However, the thread-safe I/O<br />

library does not prevent threads from operating on different logical units in<br />

parallel. In other words, parallel access to different logical units is not necessarily<br />

serialized.<br />

Functionality of I/O under Synchronization: The <strong>XL</strong> <strong>Fortran</strong> thread-safe I/O<br />

library sets its internal locks to synchronize access to logical units. This should not<br />

have any functional impact on the I/O operations per<strong>for</strong>med by a <strong>Fortran</strong><br />

program. Also, it will not impose any additional restrictions to the operability of<br />

<strong>Fortran</strong> I/O statements except <strong>for</strong> the use of I/O statements in a signal handler<br />

that is invoked asynchronously. Refer to “Use of I/O Statements in Signal<br />

Handlers” on page 343 <strong>for</strong> details.<br />

The <strong>Fortran</strong> standard prohibits a function reference from appearing in an<br />

expression anywhere in an I/O statement if such a reference causes another I/O<br />

statement to run. This restriction still applies with the <strong>XL</strong> <strong>Fortran</strong> thread-safe I/O<br />

library.<br />

Parallel I/O Issues<br />

The order in which parallel threads per<strong>for</strong>m I/O operations is not predictable. The<br />

<strong>XL</strong> <strong>Fortran</strong> thread-safe I/O library does not have control over the ordering. It will<br />

allow whichever thread that executes an I/O statement on a particular logical unit<br />

and obtains the lock on it first to proceed with the operation. There<strong>for</strong>e, only use<br />

parallel I/O in cases where at least one of the following is true:<br />

v<br />

v<br />

Each thread per<strong>for</strong>ms I/O on a predetermined record in direct-access files.<br />

Each thread per<strong>for</strong>ms I/O on a different part of a stream-access file. Different<br />

I/O statements cannot use the same, or overlapping, areas of a file.<br />

Implementation Details of <strong>XL</strong> <strong>Fortran</strong> Input/Output 341

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!