1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *   Copyright (C) 1997 University of Chicago.
5  *   See COPYRIGHT notice in top-level directory.
6  */
7 
8 #include "mpioimpl.h"
9 
10 #ifdef HAVE_WEAK_SYMBOLS
11 
12 #if defined(HAVE_PRAGMA_WEAK)
13 #pragma weak MPI_File_iread = PMPI_File_iread
14 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
15 #pragma _HP_SECONDARY_DEF PMPI_File_iread MPI_File_iread
16 #elif defined(HAVE_PRAGMA_CRI_DUP)
17 #pragma _CRI duplicate MPI_File_iread as PMPI_File_iread
18 /* end of weak pragmas */
19 #elif defined(HAVE_WEAK_ATTRIBUTE)
20 int MPI_File_iread(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPIO_Request *request)
21     __attribute__((weak,alias("PMPI_File_iread")));
22 #endif
23 
24 /* Include mapping from MPI->PMPI */
25 #define MPIO_BUILD_PROFILING
26 #include "mpioprof.h"
27 #endif
28 
29 #ifdef HAVE_MPI_GREQUEST
30 #include "mpiu_greq.h"
31 #endif
32 
33 /*@
34     MPI_File_iread - Nonblocking read using individual file pointer
35 
36 Input Parameters:
37 . fh - file handle (handle)
38 . count - number of elements in buffer (nonnegative integer)
39 . datatype - datatype of each buffer element (handle)
40 
41 Output Parameters:
42 . buf - initial address of buffer (choice)
43 . request - request object (handle)
44 
45 .N fortran
46 @*/
MPI_File_iread(MPI_File fh,void * buf,int count,MPI_Datatype datatype,MPI_Request * request)47 int MPI_File_iread(MPI_File fh, void *buf, int count, MPI_Datatype datatype, MPI_Request *request)
48 {
49     int error_code=MPI_SUCCESS;
50     static char myname[] = "MPI_FILE_IREAD";
51 #ifdef MPI_hpux
52     int fl_xmpi;
53 
54     HPMP_IO_START(fl_xmpi, BLKMPIFILEIREAD, TRDTSYSTEM, fh, datatype,
55 		  count);
56 #endif /* MPI_hpux */
57 
58 
59     error_code = MPIOI_File_iread(fh, (MPI_Offset) 0, ADIO_INDIVIDUAL,
60 				  buf, count, datatype, myname, request);
61 
62     /* --BEGIN ERROR HANDLING-- */
63     if (error_code != MPI_SUCCESS)
64 	error_code = MPIO_Err_return_file(fh, error_code);
65     /* --END ERROR HANDLING-- */
66 
67 #ifdef MPI_hpux
68     HPMP_IO_END(fl_xmpi, fh, datatype, count);
69 #endif /* MPI_hpux */
70 
71     return error_code;
72 }
73 
74 /* prevent multiple definitions of this routine */
75 #ifdef MPIO_BUILD_PROFILING
MPIOI_File_iread(MPI_File fh,MPI_Offset offset,int file_ptr_type,void * buf,int count,MPI_Datatype datatype,char * myname,MPI_Request * request)76 int MPIOI_File_iread(MPI_File fh, MPI_Offset offset, int file_ptr_type, void *buf, int count,
77 		     MPI_Datatype datatype, char *myname, MPI_Request *request)
78 {
79     int error_code, buftype_is_contig, filetype_is_contig;
80     MPI_Count datatype_size;
81     ADIO_Status status;
82     ADIO_File adio_fh;
83     ADIO_Offset off, bufsize;
84     MPI_Offset nbytes=0;
85 
86     MPIU_THREAD_CS_ENTER(ALLFUNC,);
87 
88     adio_fh = MPIO_File_resolve(fh);
89 
90     /* --BEGIN ERROR HANDLING-- */
91     MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code);
92     MPIO_CHECK_COUNT(adio_fh, count, myname, error_code);
93     MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code);
94 
95     if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) {
96 	error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
97 					  myname, __LINE__, MPI_ERR_ARG,
98 					  "**iobadoffset", 0);
99 	error_code = MPIO_Err_return_file(adio_fh, error_code);
100 	goto fn_exit;
101     }
102     /* --END ERROR HANDLING-- */
103 
104     MPI_Type_size_x(datatype, &datatype_size);
105 
106     /* --BEGIN ERROR HANDLING-- */
107     MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code);
108     MPIO_CHECK_READABLE(adio_fh, myname, error_code);
109     MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, myname, error_code);
110     MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code);
111     /* --END ERROR HANDLING-- */
112 
113     ADIOI_Datatype_iscontig(datatype, &buftype_is_contig);
114     ADIOI_Datatype_iscontig(adio_fh->filetype, &filetype_is_contig);
115 
116     ADIOI_TEST_DEFERRED(adio_fh, myname, &error_code);
117 
118     if (buftype_is_contig && filetype_is_contig) {
119 	/* convert count and offset to bytes */
120 	bufsize = datatype_size * count;
121 
122 	if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {
123 	    off = adio_fh->disp + adio_fh->etype_size * offset;
124 	}
125 	else {
126 	    off = adio_fh->fp_ind;
127 	}
128 
129         if (!(adio_fh->atomicity))
130 	    ADIO_IreadContig(adio_fh, buf, count, datatype, file_ptr_type,
131 			off, request, &error_code);
132         else {
133             /* to maintain strict atomicity semantics with other concurrent
134               operations, lock (exclusive) and call blocking routine */
135 	    if (ADIO_Feature(adio_fh, ADIO_LOCKS))
136 	    {
137                 ADIOI_WRITE_LOCK(adio_fh, off, SEEK_SET, bufsize);
138 	    }
139 
140             ADIO_ReadContig(adio_fh, buf, count, datatype, file_ptr_type,
141 			    off, &status, &error_code);
142 
143 	    if (ADIO_Feature(adio_fh, ADIO_LOCKS))
144 	    {
145                 ADIOI_UNLOCK(adio_fh, off, SEEK_SET, bufsize);
146 	    }
147 	    if (error_code == MPI_SUCCESS) {
148 		nbytes = count*datatype_size;
149 	    }
150 	    MPIO_Completed_request_create(&adio_fh, nbytes, &error_code, request);
151         }
152     }
153     else ADIO_IreadStrided(adio_fh, buf, count, datatype, file_ptr_type,
154 			   offset, request, &error_code);
155 
156 fn_exit:
157     MPIU_THREAD_CS_EXIT(ALLFUNC,);
158 
159     return error_code;
160 }
161 #endif
162