1 /*
2  * Copyright (C) by Argonne National Laboratory
3  *     See COPYRIGHT in top-level directory
4  */
5 
6 /* main include file for ADIO.
7    contains general definitions, declarations, and macros independent
8    of the underlying file system */
9 
10 /* Functions and datataypes that are "internal" to the ADIO implementation
11    prefixed ADIOI_. Functions and datatypes that are part of the
12    "externally visible" (documented) ADIO interface are prefixed ADIO_.
13 
14    An implementation of MPI-IO, or any other high-level interface, should
15    not need to use any of the ADIOI_ functions/datatypes.
16    Only someone implementing ADIO on a new file system, or modifying
17    an existing ADIO implementation, would need to use the ADIOI_
18    functions/datatypes. */
19 
20 #ifndef ADIO_H_INCLUDED
21 #define ADIO_H_INCLUDED
22 
23 #ifdef SPPUX
24 #define _POSIX_SOURCE
25 #endif
26 
27 #ifdef USE_FORT_STDCALL
28 #define FORT_CALL __stdcall
29 #elif defined (USE_FORT_CDECL)
30 #define FORT_CALL __cdecl
31 #else
32 #define FORT_CALL
33 #endif
34 
35 #ifdef USE_FORT_MIXED_STR_LEN
36 #define FORT_MIXED_LEN_DECL   , int
37 #define FORT_END_LEN_DECL
38 #define FORT_MIXED_LEN(a)     , int a
39 #define FORT_END_LEN(a)
40 #else
41 #define FORT_MIXED_LEN_DECL
42 #define FORT_END_LEN_DECL     , int
43 #define FORT_MIXED_LEN(a)
44 #define FORT_END_LEN(a)       , int a
45 #endif
46 
47 
48 #ifdef HAVE_FORTRAN_API
49 #ifdef FORTRAN_EXPORTS
50 #define FORTRAN_API __declspec(dllexport)
51 #else
52 #define FORTRAN_API __declspec(dllimport)
53 #endif
54 #else
55 #define FORTRAN_API
56 #endif
57 
58 /* Include romioconf.h if we haven't already (some include files may
59    need to include romioconf before some system includes) */
60 #ifndef ROMIOCONF_H_INCLUDED
61 #include "romioconf.h"
62 #define ROMIOCONF_H_INCLUDED
63 #endif
64 
65 #include "mpi.h"
66 #include "mpio.h"
67 #ifdef HAVE_FCNTL_H
68 #include <fcntl.h>
69 #endif
70 #ifdef HAVE_SYS_TYPES_H
71 #include <sys/types.h>
72 #endif
73 #include <sys/stat.h>
74 #include <string.h>
75 #include <stdio.h>
76 #include <stdlib.h>
77 #include <errno.h>
78 #ifdef SPPUX
79 #include <sys/cnx_fcntl.h>
80 #endif
81 
82 #ifdef ROMIO_NTFS
83 #include <winsock2.h>
84 #include <windows.h>
85 #define FDTYPE HANDLE
86 #else
87 #define FDTYPE int
88 #ifdef ROMIO_QUOBYTEFS
89 #include "quobyte.h"
90 #endif
91 #endif
92 
93 typedef MPI_Offset ADIO_Offset;
94 #ifdef MPI_OFFSET_IS_INT
95 #define ADIO_OFFSET MPI_INT
96 #elif defined(HAVE_LONG_LONG_64)
97 #ifdef HAVE_MPI_LONG_LONG_INT
98 #define ADIO_OFFSET MPI_LONG_LONG_INT
99 #else
100 #define ADIO_OFFSET MPI_DOUBLE
101 #endif
102 #elif defined(HAVE_INT64)
103 #define ADIO_OFFSET MPI_DOUBLE
104 #else
105 #define ADIO_OFFSET MPI_LONG
106 #endif
107 
108 #define ADIO_Status MPI_Status
109 
110 #ifndef MPIO_INCLUDE
111 #ifdef NEEDS_MPI_FINT
112 typedef int MPI_Fint;
113 #endif
114 #endif
115 
116 #if (!defined(HAVE_MPI_INFO) && !defined(MPIO_INCLUDE))
117 typedef struct MPIR_Info *MPI_Info;
118 #define MPI_INFO_NULL 0
119 #define MPI_MAX_INFO_VAL      1024
120 
121 int MPI_Info_create(MPI_Info * info);
122 int MPI_Info_set(MPI_Info info, char *key, char *value);
123 int MPI_Info_delete(MPI_Info info, char *key);
124 int MPI_Info_get(MPI_Info info, char *key, int valuelen, char *value, int *flag);
125 int MPI_Info_get_valuelen(MPI_Info info, char *key, int *valuelen, int *flag);
126 int MPI_Info_get_nkeys(MPI_Info info, int *nkeys);
127 int MPI_Info_get_nthkey(MPI_Info info, int n, char *key);
128 int MPI_Info_dup(MPI_Info info, MPI_Info * newinfo);
129 int MPI_Info_free(MPI_Info * info);
130 
131 #ifdef MPI_Info_f2c
132 #undef MPI_Info_f2c
133 #endif
134 #ifdef MPI_Info_c2f
135 #undef MPI_Info_c2f
136 #endif
137 /* above needed for some versions of mpi.h in MPICH!! */
138 MPI_Fint MPI_Info_c2f(MPI_Info info);
139 MPI_Info MPI_Info_f2c(MPI_Fint info);
140 
141 int PMPI_Info_create(MPI_Info * info);
142 int PMPI_Info_set(MPI_Info info, char *key, char *value);
143 int PMPI_Info_delete(MPI_Info info, char *key);
144 int PMPI_Info_get(MPI_Info info, char *key, int valuelen, char *value, int *flag);
145 int PMPI_Info_get_valuelen(MPI_Info info, char *key, int *valuelen, int *flag);
146 int PMPI_Info_get_nkeys(MPI_Info info, int *nkeys);
147 int PMPI_Info_get_nthkey(MPI_Info info, int n, char *key);
148 int PMPI_Info_dup(MPI_Info info, MPI_Info * newinfo);
149 int PMPI_Info_free(MPI_Info * info);
150 
151 MPI_Fint PMPI_Info_c2f(MPI_Info info);
152 MPI_Info PMPI_Info_f2c(MPI_Fint info);
153 
154 #endif
155 
156 /* style: allow:strdup:1 sig:0 */
157 
158 #if defined(HAVE_STRDUP) && defined(NEEDS_STRDUP_DECL) && !defined(strdup)
159 char *strdup(const char *s);
160 #endif
161 #if defined(HAVE_READLINK) && defined(NEEDS_READLINK_DECL) && !defined(readlink)
162 ssize_t readlink(const char *path, char *buf, size_t bufsiz);
163 #endif
164 #if defined(HAVE_LSTAT) && defined(NEEDS_LSTAT_DECL) && !defined(lstat)
165 int lstat(const char *file_name, struct stat *buf);
166 #endif
167 #if defined(HAVE_FSYNC) && defined(NEEDS_FSYNC_DECL) && !defined(fsync)
168 int fsync(int fd);
169 #endif
170 #if defined(HAVE_FTRUNCATE) && defined(NEEDS_FTRUNCATE_DECL) && !defined(ftruncate)
171 int ftruncate(int fd, off_t length);
172 #endif
173 
174 
175 typedef struct ADIOI_Fns_struct ADIOI_Fns;
176 typedef struct ADIOI_Hints_struct ADIOI_Hints;
177 
178 typedef struct ADIOI_FileD {
179     int cookie;                 /* for error checking */
180     FDTYPE fd_sys;              /* system file descriptor */
181     FDTYPE null_fd;             /* the null-device file descriptor: debug only (obviously) */
182     int fd_direct;              /* On XFS, this is used for direct I/O;
183                                  * fd_sys is used for buffered I/O */
184     int direct_read;            /* flag; 1 means use direct read */
185     int direct_write;           /* flag; 1 means use direct write  */
186     /* direct I/O attributes */
187     unsigned d_mem;             /* data buffer memory alignment */
188     unsigned d_miniosz;         /* min xfer size, xfer size multiple,
189                                  * and file seek offset alignment */
190     long blksize;               /* some optimizations benefit from knowing
191                                  * underlying block size */
192     ADIO_Offset fp_ind;         /* individual file pointer in MPI-IO (in bytes) */
193     ADIO_Offset fp_sys_posn;    /* current location of the system file-pointer
194                                  * in bytes */
195     ADIOI_Fns *fns;             /* struct of I/O functions to use */
196     MPI_Comm comm;              /* communicator indicating who called open */
197     int is_open;                /* deferred open: 0: not open yet 1: is open */
198     int is_agg;                 /* bool: if I am an aggregator */
199     char *filename;
200     int file_system;            /* type of file system */
201     int access_mode;            /* Access mode (sequential, append, etc.),
202                                  * possibly modified to deal with
203                                  * data sieving or deferred open */
204     int orig_access_mode;       /* Access mode provided by user: unmodified */
205     ADIO_Offset disp;           /* reqd. for MPI-IO */
206     MPI_Datatype etype;         /* reqd. for MPI-IO */
207     MPI_Datatype filetype;      /* reqd. for MPI-IO */
208     MPI_Count etype_size;       /* in bytes */
209     ADIOI_Hints *hints;         /* structure containing fs-indep. info values */
210     MPI_Info info;
211 
212     /* The following support the split collective operations */
213     int split_coll_count;       /* count of outstanding split coll. ops. */
214     MPI_Status split_status;    /* status used for split collectives */
215     MPI_Datatype split_datatype;        /* datatype used for split collectives */
216 
217     /* The following support the shared file operations */
218     char *shared_fp_fname;      /* name of file containing shared file pointer */
219     struct ADIOI_FileD *shared_fp_fd;   /* file handle of file
220                                          * containing shared fp */
221     int async_count;            /* count of outstanding nonblocking operations */
222     int perm;
223     int atomicity;              /* true=atomic, false=nonatomic */
224     int fortran_handle;         /* handle for Fortran interface if needed */
225     MPI_Errhandler err_handler;
226     void *fs_ptr;               /* file-system specific information */
227 
228     /* Two phase collective I/O support */
229     ADIO_Offset *file_realm_st_offs;    /* file realm starting offsets */
230     MPI_Datatype *file_realm_types;     /* file realm datatypes */
231     int my_cb_nodes_index;      /* my index into cb_config_list. -1 if N/A */
232     char *io_buf;               /* two-phase buffer allocated out of i/o path */
233     MPI_Win io_buf_window;      /* Window over the io_buf to support one-sided aggregation */
234     int io_buf_put_amounts;     /* the amount of data mpi_put into the io_buf
235                                  * during the same round of one-sided write aggregation */
236     MPI_Win io_buf_put_amounts_window;  /* Window over the io_buf_put_amounts */
237     /* External32 */
238     int is_external32;          /* bool:  0 means native view */
239 #ifdef ROMIO_QUOBYTEFS
240     struct quobyte_fh *file_handle;     /* file handle for quobytefs */
241 #endif
242 } ADIOI_FileD;
243 
244 typedef struct ADIOI_FileD *ADIO_File;
245 
246 typedef MPI_Request ADIO_Request;
247 
248 /* fcntl structure */
249 typedef struct {
250     ADIO_Offset disp;
251     MPI_Datatype etype;
252     MPI_Datatype filetype;
253     MPI_Info info;
254     int atomicity;
255     ADIO_Offset fsize;          /* for get_fsize only */
256     ADIO_Offset diskspace;      /* for file preallocation */
257 } ADIO_Fcntl_t;                 /* should contain more stuff */
258 
259 
260 /* access modes */
261 #define ADIO_CREATE              1
262 #define ADIO_RDONLY              2
263 #define ADIO_WRONLY              4
264 #define ADIO_RDWR                8
265 #define ADIO_DELETE_ON_CLOSE     16
266 #define ADIO_UNIQUE_OPEN         32
267 #define ADIO_EXCL                64
268 #define ADIO_APPEND             128
269 #define ADIO_SEQUENTIAL         256
270 
271 #define ADIO_AMODE_NOMATCH  ~(ADIO_CREATE|ADIO_RDONLY|ADIO_WRONLY|ADIO_RDWR|ADIO_DELETE_ON_CLOSE|ADIO_UNIQUE_OPEN|ADIO_EXCL|ADIO_APPEND|ADIO_SEQUENTIAL)
272 
273 /* file-pointer types */
274 #define ADIO_EXPLICIT_OFFSET     100
275 #define ADIO_INDIVIDUAL          101
276 #define ADIO_SHARED              102
277 
278 #define ADIO_REQUEST_NULL        ((ADIO_Request) 0)
279 #define ADIO_FILE_NULL           ((ADIO_File) 0)
280 
281 /* file systems:
282  * the numbering is slightly strange because we have deleted file
283  * systems over time */
284 #define ADIO_NFS                 150
285 #define ADIO_UFS                 152    /* Unix file system */
286 #define ADIO_XFS                 154    /* SGI */
287 #define ADIO_TESTFS              159    /* fake file system for testing */
288 #define ADIO_PVFS2               160    /* PVFS2: 2nd generation PVFS */
289 #define ADIO_PANFS               161    /* Panasas FS */
290 #define ADIO_LUSTRE              163    /* Lustre */
291 #define ADIO_GPFS                168
292 #define ADIO_IME                 169    /* IME burst buffer */
293 #define ADIO_DAOS                170
294 #define ADIO_QUOBYTEFS           171    /* Quobyte FS */
295 
296 #define ADIO_SEEK_SET            SEEK_SET
297 #define ADIO_SEEK_CUR            SEEK_CUR
298 #define ADIO_SEEK_END            SEEK_END
299 
300 #define ADIO_FCNTL_SET_ATOMICITY 180
301 #define ADIO_FCNTL_SET_DISKSPACE 188
302 #define ADIO_FCNTL_GET_FSIZE     200
303 
304 /* file system feature tests */
305 #define ADIO_LOCKS               300    /* file system supports fcntl()-style locking */
306 #define ADIO_SHARED_FP           301    /* file system supports shared file pointers */
307 #define ADIO_ATOMIC_MODE         302    /* file system supports atomic mode */
308 #define ADIO_DATA_SIEVING_WRITES 303    /* file system supports data sieving for writes */
309 #define ADIO_SCALABLE_OPEN       304    /* one process can open the file and
310                                          * broadcast result to all other
311                                          * processors */
312 #define ADIO_UNLINK_AFTER_CLOSE  305    /* supports posix semantic of keeping a
313                                          * deleted file around until all
314                                          * processors have closed it */
315 #define ADIO_TWO_PHASE           306    /* file system implements some version of
316                                          * two-phase collective buffering with
317                                          * aggregation */
318 #define ADIO_SCALABLE_RESIZE     307    /* file system supports resizing from one
319                                          * processor (nfs, e.g. does not) */
320 
321 /* for default file permissions */
322 #define ADIO_PERM_NULL           -1
323 
324 #define ADIOI_FILE_COOKIE 2487376
325 #define ADIOI_REQ_COOKIE 3493740
326 
327 /* ADIO function prototypes */
328 /* all these may not be necessary, as many of them are macro replaced to
329    function pointers that point to the appropriate functions for each
330    different file system (in adioi.h), but anyway... */
331 
332 void ADIO_Init(int *argc, char ***argv, int *error_code);
333 void ADIO_End(int *error_code);
334 MPI_File ADIO_Open(MPI_Comm orig_comm, MPI_Comm comm, const char *filename,
335                    int file_system, ADIOI_Fns * ops,
336                    int access_mode, ADIO_Offset disp, MPI_Datatype etype,
337                    MPI_Datatype filetype, MPI_Info info, int perm, int *error_code);
338 void ADIOI_OpenColl(ADIO_File fd, int rank, int acces_mode, int *error_code);
339 void ADIO_ImmediateOpen(ADIO_File fd, int *error_code);
340 void ADIO_Close(ADIO_File fd, int *error_code);
341 void ADIO_ReadContig(ADIO_File fd, void *buf, int count, MPI_Datatype datatype,
342                      int file_ptr_type, ADIO_Offset offset, ADIO_Status * status, int *error_code);
343 void ADIO_WriteContig(ADIO_File fd, void *buf, int count,
344                       MPI_Datatype datatype, int file_ptr_type,
345                       ADIO_Offset offset, int *bytes_written, int
346                       *error_code);
347 void ADIO_IwriteContig(ADIO_File fd, void *buf, int count,
348                        MPI_Datatype datatype, int file_ptr_type,
349                        ADIO_Offset offset, ADIO_Request * request, int
350                        *error_code);
351 void ADIO_IreadContig(ADIO_File fd, void *buf, int count,
352                       MPI_Datatype datatype, int file_ptr_type,
353                       ADIO_Offset offset, ADIO_Request * request, int
354                       *error_code);
355 int ADIO_ReadDone(ADIO_Request * request, ADIO_Status * status, int *error_code);
356 int ADIO_WriteDone(ADIO_Request * request, ADIO_Status * status, int *error_code);
357 int ADIO_ReadIcomplete(ADIO_Request * request, ADIO_Status * status, int
358                        *error_code);
359 int ADIO_WriteIcomplete(ADIO_Request * request, ADIO_Status * status, int *error_code);
360 void ADIO_ReadComplete(ADIO_Request * request, ADIO_Status * status, int
361                        *error_code);
362 void ADIO_WriteComplete(ADIO_Request * request, ADIO_Status * status, int *error_code);
363 void ADIO_Fcntl(ADIO_File fd, int flag, ADIO_Fcntl_t * fcntl_struct, int
364                 *error_code);
365 void ADIO_ReadStrided(ADIO_File fd, void *buf, int count,
366                       MPI_Datatype datatype, int file_ptr_type,
367                       ADIO_Offset offset, ADIO_Status * status, int
368                       *error_code);
369 void ADIO_WriteStrided(ADIO_File fd, const void *buf, int count,
370                        MPI_Datatype datatype, int file_ptr_type,
371                        ADIO_Offset offset, ADIO_Status * status, int
372                        *error_code);
373 void ADIO_ReadStridedColl(ADIO_File fd, void *buf, int count,
374                           MPI_Datatype datatype, int file_ptr_type,
375                           ADIO_Offset offset, ADIO_Status * status, int
376                           *error_code);
377 void ADIO_WriteStridedColl(ADIO_File fd, void *buf, int count,
378                            MPI_Datatype datatype, int file_ptr_type,
379                            ADIO_Offset offset, ADIO_Status * status, int
380                            *error_code);
381 void ADIO_IreadStrided(ADIO_File fd, void *buf, int count,
382                        MPI_Datatype datatype, int file_ptr_type,
383                        ADIO_Offset offset, ADIO_Request * request, int
384                        *error_code);
385 void ADIO_IwriteStrided(ADIO_File fd, void *buf, int count,
386                         MPI_Datatype datatype, int file_ptr_type,
387                         ADIO_Offset offset, ADIO_Request * request, int
388                         *error_code);
389 void ADIO_IreadStridedColl(ADIO_File fd, void *buf, int count,
390                            MPI_Datatype datatype, int file_ptr_type,
391                            ADIO_Offset offset, ADIO_Request * request, int *error_code);
392 void ADIO_IwriteStridedColl(ADIO_File fd, void *buf, int count,
393                             MPI_Datatype datatype, int file_ptr_type,
394                             ADIO_Offset offset, ADIO_Request * request, int *error_code);
395 ADIO_Offset ADIO_SeekIndividual(ADIO_File fd, ADIO_Offset offset, int whence, int *error_code);
396 void ADIO_Delete(char *filename, int *error_code);
397 void ADIO_Flush(ADIO_File fd, int *error_code);
398 void ADIO_Resize(ADIO_File fd, ADIO_Offset size, int *error_code);
399 void ADIO_SetInfo(ADIO_File fd, MPI_Info users_info, int *error_code);
400 void ADIO_ResolveFileType(MPI_Comm comm, const char *filename, int *fstype,
401                           ADIOI_Fns ** ops, int *error_code);
402 void ADIO_Get_shared_fp(ADIO_File fd, ADIO_Offset size, ADIO_Offset * shared_fp, int *error_code);
403 void ADIO_Set_shared_fp(ADIO_File fd, ADIO_Offset offset, int *error_code);
404 void ADIO_Set_view(ADIO_File fd, ADIO_Offset disp, MPI_Datatype etype,
405                    MPI_Datatype filetype, MPI_Info info, int *error_code);
406 int ADIO_Feature(ADIO_File fd, int flag);
407 
408 /* functions to help deal with the array datatypes */
409 int ADIO_Type_create_subarray(int ndims,
410                               int *array_of_sizes,
411                               int *array_of_subsizes,
412                               int *array_of_starts,
413                               int order, MPI_Datatype oldtype, MPI_Datatype * newtype);
414 int ADIO_Type_create_darray(int size, int rank, int ndims,
415                             int *array_of_gsizes, int *array_of_distribs,
416                             int *array_of_dargs, int *array_of_psizes,
417                             int order, MPI_Datatype oldtype, MPI_Datatype * newtype);
418 
419 /* MPI_File management functions (in mpio_file.c) */
420 MPI_File MPIO_File_create(int size);
421 ADIO_File MPIO_File_resolve(MPI_File mpi_fh);
422 void MPIO_File_free(MPI_File * mpi_fh);
423 MPI_File MPIO_File_f2c(MPI_Fint fh);
424 MPI_Fint MPIO_File_c2f(MPI_File fh);
425 int MPIO_Err_create_code(int lastcode, int fatal, const char fcname[],
426                          int line, int error_class, const char generic_msg[],
427                          const char specific_msg[], ...);
428 int MPIO_Err_return_file(MPI_File mpi_fh, int error_code);
429 int MPIO_Err_return_comm(MPI_Comm mpi_comm, int error_code);
430 
431 /* request managment helper functions */
432 void MPIO_Completed_request_create(MPI_File * fh, MPI_Offset nbytes,
433                                    int *error_code, MPI_Request * request);
434 
435 #include "adioi.h"
436 #include "adioi_fs_proto.h"
437 #include "mpio_error.h"
438 #include "mpipr.h"
439 
440 /* these two defines don't appear to be in any other header file */
441 #define MPIR_ERR_FATAL 1
442 #define MPIR_ERR_RECOVERABLE 0
443 
444 #endif /* ADIO_H_INCLUDED */
445