File: eof_offset.c

package info (click to toggle)
openmpi 5.0.8-3
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 201,692 kB
  • sloc: ansic: 613,078; makefile: 42,353; sh: 11,194; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,179; python: 1,859; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (73 lines) | stat: -rw-r--r-- 2,745 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

#include "adio.h"
#include "adio_extern.h"

/* return the current end of file in etype units relative to the
   current view */

void ADIOI_Get_eof_offset(ADIO_File fd, ADIO_Offset * eof_offset)
{
    MPI_Count filetype_size;
    int error_code, filetype_is_contig;
    ADIO_Offset fsize, disp, sum = 0, size_in_file, n_filetypes, rem, etype_size;
    int flag, i;
    ADIO_Fcntl_t *fcntl_struct;
    MPI_Aint lb, filetype_extent;
    ADIOI_Flatlist_node *flat_file;

    /* find the eof in bytes */
    fcntl_struct = (ADIO_Fcntl_t *) ADIOI_Malloc(sizeof(ADIO_Fcntl_t));
    ADIO_Fcntl(fd, ADIO_FCNTL_GET_FSIZE, fcntl_struct, &error_code);
    fsize = fcntl_struct->fsize;
    ADIOI_Free(fcntl_struct);

    /* Find the offset in etype units corresponding to eof.
     * The eof could lie in a hole in the current view, or in the
     * middle of an etype. In that case the offset will be the offset
     * corresponding to the start of the next etype in the current view. */

    ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
    etype_size = fd->etype_size;

    if (filetype_is_contig)
        *eof_offset = (fsize - fd->disp + etype_size - 1) / etype_size;
    /* ceiling division in case fsize is not a multiple of etype_size; */
    else {
        flat_file = ADIOI_Flatten_and_find(fd->filetype);

        MPI_Type_size_x(fd->filetype, &filetype_size);
        MPI_Type_get_extent(fd->filetype, &lb, &filetype_extent);

        disp = fd->disp;
        n_filetypes = -1;
        flag = 0;
        while (!flag) {
            sum = 0;
            n_filetypes++;
            for (i = 0; i < flat_file->count; i++) {
                sum += flat_file->blocklens[i];
                if (disp + flat_file->indices[i] +
                    n_filetypes * ADIOI_AINT_CAST_TO_OFFSET filetype_extent +
                    flat_file->blocklens[i] >= fsize) {
                    if (disp + flat_file->indices[i] +
                        n_filetypes * ADIOI_AINT_CAST_TO_OFFSET filetype_extent >= fsize)
                        sum -= flat_file->blocklens[i];
                    else {
                        rem = (disp + flat_file->indices[i] +
                               n_filetypes * ADIOI_AINT_CAST_TO_OFFSET filetype_extent
                               + flat_file->blocklens[i] - fsize);
                        sum -= rem;
                    }
                    flag = 1;
                    break;
                }
            }
        }
        size_in_file = n_filetypes * (ADIO_Offset) filetype_size + sum;
        *eof_offset = (size_in_file + etype_size - 1) / etype_size;     /* ceiling division */
    }
}