Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 11/07/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

File Sharing on Linux

Depending on the value specified by the ACTION (or READONLY) specifier in the OPEN statement, the file will be opened by your program for reading, writing, or both reading and writing records. This simply checks that the program itself executes the type of statements intended.

File locking mechanisms allow users to enable or restrict access to a particular file when that file is being accessed by another process.

Intel® Fortran file locking features provide three file access modes:

  • Implicit Shared mode, which occurs when no mode is specified. This mode is also called No Locking.

  • Explicit Shared mode, when all cooperating processes have access to a file. This mode is set in the OPEN statement by the SHARED specifier or the SHARE='DENYNONE' specifier.

  • Exclusive mode, when only one process has access to a file. This mode is set in the OPEN statement by the NOSHARED specifier or the SHARE='DENYRW' specifier.

The file locking mechanism looks for explicit setting of the corresponding specifier in the OPEN statement. Otherwise, the Fortran runtime does not perform any setting or checking for file locking. The process can access the file regardless of the fact that other processes have already opened or locked the file.

Examples

In the following examples, Process 1 and Process 2 are separate programs running at the same time, and opening the same file. Process 1 opens the file first. Process 2 opens the file later, before Process 1 closes it. The processes may or may not be cooperating.

Implicit Shared Mode (No Locking)

Process 1 opens the file without a specifier, resulting in no locking.

Process 2 now tries to open the file:

  • It gains access regardless of the mode it is using.

Explicit Shared Mode

Process 1 opens the file with Explicit Shared mode.

Process 2 now tries to open the file:

  • If process 2 opens the file with Explicit Shared mode or Implicit Shared (No Locking) mode, it gets access to the file.

  • If process 2 opens the file with Exclusive mode, it receives an error.

Exclusive Mode

Process 1 opens the file with Exclusive mode.

Process 2 now tries to open the file:

  • If process 2 opens the file with Implicit Shared (No Locking) mode, it gets access to the file.

  • If process 2 opens the file with Explicit Shared or Exclusive mode, it receives an error.

The Fortran runtime does not coordinate file entry updates during cooperative access. The user needs to coordinate access times among cooperating processes to handle the possibility of simultaneous WRITE and REWRITE statements on the same record positions.