Документ взят из кэша поисковой машины. Адрес оригинального документа : http://sp.cs.msu.ru/dvm/dvmhtm1107/eng/sys/libdvm/rtsIDe6.html
Дата изменения: Mon Feb 13 12:59:10 2006
Дата индексирования: Mon Oct 1 23:23:24 2012
Кодировка: Windows-1251
Lib-DVM. Interface description. Part 6 (16-18)
Lib-DVM interface description (contents) Part 1
(1-5)
Part 2
(6-7)
Part 3
(8-11)
Part 4
(12-13)
Part 5
(14-15)
Part 6
(16-18)
Part 7
(19)
created: february, 2001 - last edited 03.05.01 -

16 Input/Output

16.1 Analogies to functions of C language standard library

All functions discussed below is intended for usage for input/output of the replicated variables (all copies of each variable are equal). The implementaфion of these functions is based on the execution of the standard C functions on the processor, called "I/O processor". The result (if one exists) of the functions is sent to all the processors. For example, the execution of the function dvm_prinf results in single printing from the I/O processor. The execution of the function printf results in multiple printing from each processor. It is possible to determine if the current processor is I/O processor with the help of the function tstio_ (see section 17.6).

Note, that it is possible to use in the user program the I/O functions of the standard C language library (ANSI), which have no corresponding functions in the list below and have no undesirable effect of multiple executions.

16.1.1. High level input/output functions

ANSI:

void dvm_clearerr (DVMFILE *StreamPtr);
int dvm_fclose (DVMFILE *StreamPtr);
int dvm_feof (DVMFILE *StreamPtr);
int dvm_ferror (DVMFILE *StreamPtr);
int dvm_fflush (DVMFILE *StreamPtr);
int dvm_fgetc (DVMFILE *StreamPtr);
int dvm_fgetpos (DVMFILE *StreamPtr, fpos_t *PosPtr);
char *dvm_fgets (char *StringPtr, int n, DVMFILE *StreamPtr);
DVMFILE *dvm_fopen (const char *FileNamePtr, const char TypePtr);
int dvm_fprintf (DVMFILE *StreamPtr, const char *FormatPtr [, Argument, ... ]);
void dvm_void_fprintf (DVMFILE *StreamPtr, const char *FormatPtr [, Argument, ... ]);
int dvm_fputc (int c, DVMFILE *StreamPtr);
int dvm_fputs (const char *StringPtr, DVMFILE *StreamPtr);
int dvm_fread (void *BufferPtr, size_t Size, size_t Count, DVMFILE *StreamPtr);
DVMFILE *dvm_freopen (const char *FileNamePtr, const char *TypePtr, DVMFILE *StreamPtr);
int dvm_fscanf (DVMFILE *StreamPtr, const char *FormatPtr [, ArgumentPtr, ... ]);
int dvm_fseek (DVMFILE *StreamPtr, long Offset, int Origin);
int dvm_fsetpos (DVMFILE *StreamPtr, const fpos_t *PosPtr);
long dvm_ftell (DVMFILE *StreamPtr);
int dvm_fwrite (const void *BufferPtr, size_t Size, size_t Count, DVMFILE *StreamPtr);
int dvm_getc (DVM_FILE *StreamPtr);
int dvm_getchar (void);
char *dvm_gets (char *BufferPtr);
int dvm_printf (const char *FormatPtr, ... );
void dvm_void_printf (const char *FormatPtr, ... );
int dvm_putc (int c, DVMFILE *StreamPtr);
int dvm_putchar (int c);
int dvm_puts (char const *StringPtr);
void dvm_rewind (DVMFILE *StreamPtr);
int dvm_scanf (const char *FormatPtr [, ArgumentPtr, ... ]);
void dvm_setbuf (DVMFILE *StreamPtr, char *BufferPtr);
int dvm_setvbuf (DVMFILE *StreamPtr, char *BufferPtr, int Type, int Size);
DVMFILE *dvm_tmpfile (void);
int dvm_ungetc (int c, DVMFILE *StreamPtr);
int dvm_vfprintf (DVMFILE *StreamPtr, const char *FormatPtr, va_list ArgList);
void dvm_void_vfprintf (DVMFILE *StreamPtr, const char *FormatPtr, va_list ArgList);
int dvm_vprintf (const char *FormatPtr, va_list ArgList);
void dvm_void_vprintf (const char *FormatPtr, va_list ArgList);

BORLAND-C & MICROSOFT-C:

int dvm_fgetchar (void);
int dvm_fputchar (int c);

BORLAND-C:

int dvm_vfscanf (DVMFILE *StreamPtr, const char *FormatPtr,
va_list ArgList);
int dvm_vscanf (const char *FormatPtr, va_list ArgList);

In the functions above to specify standard streams the following pointers can be used:

DVMFILE *DVMSTDIN - standard input stream;
DVMFILE *DVMSTDOUT - standard output stream;
DVMFILE *DVMSTDERR - standard error stream;
DVMFILE *DVMSTDAUX - standard com port;
DVMFILE *DVMSTDPRN - standard printer port.

Note 1. The distinction (in the realization) between the functions dvm_void_printf, dvm_void_fprintf, dvm_void_vprintf, dvm_void_vfprintf are the functions dvm_printf, dvm_fprintf, dvm_vprintf, dvm_vfprintf is that the I/O processor does not send the return values of the functions printf, fprintf, vprintf and vfprintf to another processors, i.e. their is difference in the execution time. The full analogues of the standard functions printf, fprintf, vprintf and vfprintf are the functions dvm_printf, dvm_fprintf, dvm_vprintf and dvm_.

Note2. The functions dvm_fread and dvm_fwrite can be used to read/write the distributed array. In this case, the BufferPtr pointer has to point to the header of the distributed array. The size of the array element is assumed to be equal to *TypeSizePtr (that is value used at the array creation with the function crtda_), not Size. The number of the elements to read/write is assumed to be equal to the minimum of Count*Size/(*TypeSizePtr) and the number of the elements in the distributed array (also see the description of the functions dvm_dfread and dvm_dfwrite in sections 16.2 and 16.3).

Distributed array, specified in dvm_fread and dvm_fwrite function call must be mapped on the processor system, all elements of which must belong to the current processor system.

Note 3. Access to standard stdaux (stdprn) stream using DVMSTDAUX (DVMSTDPRN) pointer is possible only if Run-Time System was compiled with defined compilation variable _DVM_STDAUX_ (_DVM_STDPRN_).

16.1.2 Low lewel I/O functions

BORLAND-C & MICROSOFT-C & PORTLAND GROUP-C:

int dvm_close (DVMHANDLE *HandlePtr);
int dvm_fstat (DVMHANDLE *HandlePtr, struct stat *BufferPtr);
long dvm_lseek (DVMHANDLE *HandlePtr, long Offset, int Origin);
DVMHANDLE *dvm_open (const char *FileNamePtr, int OFlag, int Pmode);
int dvm_read (DVMHANDLE *HandlePtr, char *BufferPtr, unsigned int Count);
int dvm_write (DVMHANDLE *HandlePtr, const void *BufferPtr, unsigned int Count);

To access to standard I/O streams in low level I/O functions the following pointers may be used:

DVMSTREAM0 - standard input stream;
DVMSTREAM1 - standard output stream;
DVMSTREAM2 - standard error stream;
DVMSTREAM3 - standard com port;
DVMSTREAM4 - standard printer port

16.1.3 Operations with directories and files

ANSI:

int dvm_remove (const char *FileNamePtr);
int dvm_rename (const char *OldNamePtr, const char NewNamePtr);
char *dvm_tmpnam (char *FileNamePtr);

BORLAND-C & MICROSOFT-C & PORTLAND GROUP-C:

int dvm_access (const char *FileNamePtr, int Mode);
int dvm_stat (const char *FileName, struct stat *BufferPtr);
int dvm_unlink (const char *FileNamePtr);

Note. A user program can use low level I/O functions and the functions dvm_access and dvm_stat only in the case, if C compiler library contains corresponding functions. To use low level input/output functions Run-Time System and user program should be compiled with defined compilation variable _DVM_LLIO_. To link function dvm_access (dvm_stat) the compilation should be done with defined variable _ACCESS_FUN_ (_STRUCT_STAT_).

When working in WINDOWS+MPI+MICROSOFT_C (WINDOWS+MICROSOFT_C) environment to link all functions above Run-Time System and user рrogram must be compiled with defined compilation variable _WIN_MPI_ (_DVM_MSC_).

16.2 Reading from file to sub-array of distributed array

long DisArrRead( DVMFILE
long
long
long
long
*StreamPtr,
ArrayHeader[],
InitIndexArray[],
LastIndexArray[],
StepArray[] );
     
*StreamPtr - the input file descriptor.
ArrayHeader - the header of the distributed array.
InitIndexArray - array, which i-th element is the initial value of the index variable of the (i+1)-th dimension of the distributed array.
LastIndexArray - array, which i-th element ] is the last value of the index variable of the (i+1)-th dimension of the distributed array.
  - array, which i-th element is the step value for the index variable of the (i+1)-th dimension of the distributed array.

The function reads the sub-array of the distributed array. This sub-array is determined by the following set of the index corteges:

{I1 О M1 :   I1 = InitIndexArray[0]      + StepArray[0] *P1 } ?
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
{ I
k
О Mk:   Ik = InitIndexArray[k-1] + StepArray[k-1]*Pk } ?
       . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
{ I
n
О Mn:   In = InitIndexArray[n-1]  + StepArray[n-1]*Pn } ,

where:

? - symbol of Cartesian product;
n - rank of the distributed array;
Ik - index variable of the k-th dimension of the distributed array.

0 ? Pk ? (LastIndexArray[k-1] - InitIndexArray[k-1] + 1) / StepArray[k-1].

The subarray to be read is a block (stretched, if at least one StepArray[i] is not equal to 1).

The reading is executed until the exhaustion of the source elements. The elements are copied in the order, according to the C language discipline of allocating of the elements in the memory, that is the right index is changed more faster then the left one. If the initial value of the index by some dimension of the tбrget array is greater or equal to its last value, then the index of this dimension is not changed during copy operation. Note, that Run-Time System considers the last index value of any dimension as a minimum of the defined value in the function call and the real size of this dimension minus 1.

To use a full scope of the target array without requesting the size of the object by some dimension (see section 17.2), Run-Time System supposes that the value of the initial index value can be equal to -1. In that case, the initial index value is supposed to be equal to zero, the step be equal to 1, and the last index value be equal to the size of the dimension minus 1.

The function returns the number of the copied elements.

long dvm_dfread ( long
long
DVMFILE
ArrayHeader[],
Count,
*StreamPtr );
     
ArrayHeader - the header of the distributed array.
Count - the number of the elements to read.
*StreamPtr - the descriptor of the input file.

The function dvm_dfread reads no more than Count of the first elements of the distributed array (in order of allocation this array in memory). If Count is greater then zero the number of the copied elements is supposed to be minimum of Count and the real number of the elements in the distributed array. If Count is a negative number then the function reads the distributed array entirely.

The function returns the number of the copied elements.

16.3 Writing sub-array of distributed array to file

long DisArrWrite( DVMFILE
long
long
long
long
*StreamPtr,
ArrayHeader[],
InitIndexArray[],
LastIndexArray[],
StepArray[] );
*StreamPtr - the descriptor of the output file.
ArrayHeader - the header of the distributed array.
InitIndexArray - array, which i-th element is the initial value of the index variable of the (i+1)-th dimension of the distributed array.
LastIndexArray - array, which i-th element ] is the last value of the index variable of the (i+1)-th dimension of the distributed array.
StepArray - array, which i-th element is the step value for the index variable of the (i+1)-th dimension of the distributed array.

The functions writes the sub-array of the distributed array. This sub-array is determined by the following set of the index corteges:

{ I1 О