Coarray & OMP file access

Coarray & OMP file access

 

Steve, Colleagues:

I have a large, binary, sequential access data file. Each record corresponds to data for a particular element in a large problem being analyzed. Each record is the same length. Two scenarios:

1. I launch a coarray program and each image opens this (same) file. Different images read through (skip over) the records until the file pointer is at the first element to be processed by that image. Each image then process it's own set of elements, sequentially reading records from the file as necessary. Does the file/MPI system maintain the correct/separate file pointer position(s) for each image?

2. Parallelization is achieved by an OMP 'parallel do' in a single program. Before the parallel do loop is entered, the data file is opened. Each thread is responsible for processing a subset of the elements in the problem. Does the file/OMP system maintain the correct/separate file pointer position(s) for each thread?

Or must I use a binary direct access file and calculated/seek the correct record for each read in each image or thread?

David

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
jimdempseyatthecove's picture

1) The different images are run in different processes (different address space and may even be located on a different physical system in a network). Your file will have to be opened in a shared mode to permit multiple processes, or the same process with multiple units opening the same file. The short answer then is each image has its own file pointer. Appending to a shared file has its own set of problems and solution.

2) The threads from an OMP parallel do are run from the same process (do not confuse process with processor). The file handles of open files are shared. Therefore consider using either !$OMP CRITICAL(PickANameHere), FSEEK, READ, !$OMP END CRITICAL(PickANameHere). If the file is opened in stream mode you also have the POS= modifier. Or use separate file handles per thread to the same file (also must be open with sharing enabled).

Jim Dempsey

www.quickthreadprogramming.com

Login to leave a comment.