ad_read.c 2.76 KB
Newer Older
1
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2
3
4
5
6
7
8
9
/* 
 *
 *   Copyright (C) 1997 University of Chicago. 
 *   See COPYRIGHT notice in top-level directory.
 */


#include <unistd.h>
Rob Latham's avatar
Rob Latham committed
10
11

#include "adio.h"
12
13
14
#ifdef AGGREGATION_PROFILE
#include "mpe.h"
#endif
15
16
#ifdef ROMIO_GPFS
# include "adio/ad_gpfs/ad_gpfs_tuning.h"
17
#endif
18

19
20
21
22
#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif

23
24
25
26
27
void ADIOI_GEN_ReadContig(ADIO_File fd, void *buf, int count, 
			  MPI_Datatype datatype, int file_ptr_type,
			  ADIO_Offset offset, ADIO_Status *status,
			  int *error_code)
{
28
    ssize_t err = -1;
29
    MPI_Count datatype_size;
Rob Latham's avatar
Rob Latham committed
30
31
    ADIO_Offset len, bytes_xfered=0;
    size_t rd_count;
32
    static char myname[] = "ADIOI_GEN_READCONTIG";
33
#ifdef ROMIO_GPFS
Rob Latham's avatar
Rob Latham committed
34
    double io_time=0;
35
#endif
Rob Latham's avatar
Rob Latham committed
36
    char *p;
37

38
39
40
#ifdef AGGREGATION_PROFILE
    MPE_Log_event (5034, 0, NULL);
#endif
41
42
    MPI_Type_size_x(datatype, &datatype_size);
    len = datatype_size * (ADIO_Offset)count;
43

44
#ifdef ROMIO_GPFS
45
    io_time = MPI_Wtime();
46
47
    if (gpfsmpio_timing) {
	gpfsmpio_prof_cr[ GPFSMPIO_CIO_DATA_SIZE ] += len;
48
49
50
    }
#endif

51
52
53
    if (file_ptr_type == ADIO_INDIVIDUAL) {
	offset = fd->fp_ind;
    }
54

Rob Latham's avatar
Rob Latham committed
55
56
    p=buf;
    while (bytes_xfered < len) {
57
#ifdef ADIOI_MPE_LOGGING
Rob Latham's avatar
Rob Latham committed
58
	MPE_Log_event( ADIOI_MPE_read_a, 0, NULL );
59
#endif
Rob Latham's avatar
Rob Latham committed
60
	rd_count = len - bytes_xfered;
61
62
63
64
	/* stupid FreeBSD and Darwin do not like a count larger than a signed
           int, even though size_t is eight bytes... */
        if (rd_count > INT_MAX)
            rd_count = INT_MAX;
65
66
#ifdef ROMIO_GPFS
	if (gpfsmpio_devnullio)
Rob Latham's avatar
Rob Latham committed
67
68
	    err = pread(fd->null_fd, p, rd_count, offset+bytes_xfered);
	else
69
#endif
Rob Latham's avatar
Rob Latham committed
70
	    err = pread(fd->fd_sys, p, rd_count, offset+bytes_xfered);
Rob Latham's avatar
Rob Latham committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
	/* --BEGIN ERROR HANDLING-- */
	if (err == -1) {
	    *error_code = MPIO_Err_create_code(MPI_SUCCESS,
		    MPIR_ERR_RECOVERABLE,
		    myname, __LINE__,
		    MPI_ERR_IO, "**io",
		    "**io %s", strerror(errno));
	    fd->fp_sys_posn = -1;
	    return;
	}
	/* --END ERROR HANDLING-- */
	if (err == 0) {
	    /* end of file */
	    break;
	}

87
#ifdef ADIOI_MPE_LOGGING
Rob Latham's avatar
Rob Latham committed
88
	MPE_Log_event( ADIOI_MPE_read_b, 0, NULL );
89
#endif
Rob Latham's avatar
Rob Latham committed
90
91
	bytes_xfered += err;
	p += err;
92
    }
93
#ifdef ROMIO_GPFS
Rob Latham's avatar
Rob Latham committed
94
    if (gpfsmpio_timing) gpfsmpio_prof_cr[ GPFSMPIO_CIO_T_POSI_RW ] += (MPI_Wtime() - io_time);
95
#endif
Rob Latham's avatar
Rob Latham committed
96
    fd->fp_sys_posn = offset + bytes_xfered;
97
98

    if (file_ptr_type == ADIO_INDIVIDUAL) {
Rob Latham's avatar
Rob Latham committed
99
	fd->fp_ind += bytes_xfered; 
100
101
102
    }

#ifdef HAVE_STATUS_SET_BYTES
Rob Latham's avatar
Rob Latham committed
103
104
105
    /* what if we only read half a datatype? */
    /* bytes_xfered could be larger than int */
    if (err != -1) MPIR_Status_set_bytes(status, datatype, bytes_xfered);
106
107
108
#endif

    *error_code = MPI_SUCCESS;
109
110
111
#ifdef AGGREGATION_PROFILE
    MPE_Log_event (5035, 0, NULL);
#endif
112
113
114
#ifdef ROMIO_GPFS
    if (gpfsmpio_timing) gpfsmpio_prof_cr[ GPFSMPIO_CIO_T_MPIO_RW ] += (MPI_Wtime() - io_time);
#endif
115
}