User`s guide
Cray XMT™ Programming Environment User’s Guide
Internally, the UNIX library enforces locking for each file descriptor so that output
to multiple files can occur in parallel, but output to a single file occurs serially. For
example, in the following loop, every iteration refers to a different file descriptor, so
each call to write runs without interfering with other calls.
#pragma mta assert parallel
for (i = 0; i < n; i++)
{
char line[80];
int len = sprintf(line, "this is iteration %d\n", i);
write(fd[i], line, len);
}
If many parallel calls refer to the same file, locking forces a serial execution order.
For example, in the following code, it makes little sense to run the loop in parallel
because calls to
write are serialized by the lock on the file descriptor fd.
#pragma mta assert parallel
for (i = 0; i < n; i++)
{
char line[80];
int len = sprintf(line, "this is iteration %d\n", i);
write(fd, line, len);
}
If the loop contains a significant computation, such as in the following example, you
may want to parallelize the loop.
#pragma mta assert parallel
for (i = 0; i < n; i++)
{
char line[80];
int j = expensive_function(i);
int len = sprintf(line, "f(%d) = %d\n" ,` i, j);
write(fd, line, len);
}
You cannot use the other low-level UNIX I/O functions to support concurrent access
to a single file.
42 S–2479–20