ParallelIO
pio_internal.h
Go to the documentation of this file.
1 
10 #ifndef __PIO_INTERNAL__
11 #define __PIO_INTERNAL__
12 
13 #include <pio.h>
14 
15 /* It seems that some versions of openmpi fail to define
16  * MPI_OFFSET. */
17 #ifdef OMPI_OFFSET_DATATYPE
18 #ifndef MPI_OFFSET
19 #define MPI_OFFSET OMPI_OFFSET_DATATYPE
20 #endif
21 #endif
22 #ifndef MPI_Offset
23 #define MPI_Offset long long
24 #endif
25 #include <bget.h>
26 #include <limits.h>
27 #include <math.h>
28 #ifdef TIMING
29 #include <gptl.h>
30 #endif
31 
32 #if PIO_ENABLE_LOGGING
33 void pio_log(int severity, const char *fmt, ...);
34 #define LOG(e) pio_log e
35 #else
36 #define LOG(e)
37 #endif /* PIO_ENABLE_LOGGING */
38 
39 #define max(a,b) \
40  ({ __typeof__ (a) _a = (a); \
41  __typeof__ (b) _b = (b); \
42  _a > _b ? _a : _b; })
43 
44 #define min(a,b) \
45  ({ __typeof__ (a) _a = (a); \
46  __typeof__ (b) _b = (b); \
47  _a < _b ? _a : _b; })
48 
49 #define MAX_GATHER_BLOCK_SIZE 0
50 #define PIO_REQUEST_ALLOC_CHUNK 16
51 
52 #if defined(__cplusplus)
53 extern "C" {
54 #endif
55 
56  extern PIO_Offset PIO_BUFFER_SIZE_LIMIT;
57  extern bool PIO_Save_Decomps;
58 
60  typedef struct mapsort
61  {
62  int rfrom;
63  PIO_Offset soffset;
64  PIO_Offset iomap;
65  } mapsort;
66 
68  typedef struct pio_swapm_defaults
69  {
70  int nreqs;
71  bool handshake;
72  bool isend;
74 
75  void pio_get_env(void);
76  int pio_add_to_iodesc_list(io_desc_t *iodesc);
77  io_desc_t *pio_get_iodesc_from_id(int ioid);
78  int pio_delete_iodesc_from_list(int ioid);
79 
80  file_desc_t *pio_get_file_from_id(int ncid);
81  int pio_delete_file_from_list(int ncid);
83  void pio_push_request(file_desc_t *file, int request);
84 
85  iosystem_desc_t *pio_get_iosystem_from_id(int iosysid);
86  int pio_add_to_iosystem_list(iosystem_desc_t *ios);
87 
88  int check_netcdf(file_desc_t *file,const int status, const char *fname, const int line);
89  int iotype_error(const int iotype, const char *fname, const int line);
90  void piodie(const char *msg,const char *fname, const int line);
91  void pioassert(bool exp, const char *msg,const char *fname, const int line);
92  int CalcStartandCount(const int basetype, const int ndims, const int *gdims, const int num_io_procs,
93  const int myiorank, PIO_Offset *start, PIO_Offset *kount);
94  void CheckMPIReturn(const int ierr,const char file[],const int line);
95  int pio_fc_gather( void *sendbuf, const int sendcnt, const MPI_Datatype sendtype,
96  void *recvbuf, const int recvcnt, const MPI_Datatype recvtype, const int root,
97  MPI_Comm comm, const int flow_cntl);
98  int pio_fc_gatherv( void *sendbuf, const int sendcnt, const MPI_Datatype sendtype,
99  void *recvbuf, const int recvcnts[], const int recvdispl[], const MPI_Datatype recvtype, const int root,
100  MPI_Comm comm, const int flow_cntl);
101 
102  int pio_fc_gatherv( void *sendbuf, const int sendcnt, const MPI_Datatype sendtype,
103  void *recvbuf, const int recvcnts[], const int rdispls[], const MPI_Datatype recvtype, const int root,
104  MPI_Comm comm, const int flow_cntl);
105 
106  int pio_swapm(void *sndbuf, int sndlths[], int sdispls[], MPI_Datatype stypes[],
107  void *rcvbuf, int rcvlths[], int rdispls[], MPI_Datatype rtypes[],
108  MPI_Comm comm, const bool handshake, bool isend, const int max_requests);
109 
110  long long lgcd_array(int nain, long long*ain);
111 
112  void PIO_Offset_size(MPI_Datatype *dtype, int *tsize);
113  PIO_Offset GCDblocksize(const int arrlen, const PIO_Offset arr_in[]);
114 
115  int subset_rearrange_create(const iosystem_desc_t ios,const int maplen, PIO_Offset compmap[], const int gsize[],
116  const int ndim, io_desc_t *iodesc);
117 
118 
119  int box_rearrange_create(const iosystem_desc_t ios,const int maplen, const PIO_Offset compmap[], const int gsize[],
120  const int ndim, io_desc_t *iodesc);
121 
122 
123  int rearrange_io2comp(const iosystem_desc_t ios, io_desc_t *iodesc, void *sbuf,
124  void *rbuf);
125  int rearrange_comp2io(const iosystem_desc_t ios, io_desc_t *iodesc, void *sbuf,
126  void *rbuf, const int nvars);
127  int calcdisplace(const int bsize, const int numblocks,const PIO_Offset map[],int displace[]);
128  io_desc_t *malloc_iodesc(const int piotype, const int ndims);
129  void performance_tune_rearranger(iosystem_desc_t ios, io_desc_t *iodesc);
130 
131  int flush_output_buffer(file_desc_t *file, bool force, PIO_Offset addsize);
132  void compute_maxIObuffersize(MPI_Comm io_comm, io_desc_t *iodesc);
133  io_region *alloc_region(const int ndims);
134  int pio_delete_iosystem_from_list(int piosysid);
135  int gcd(int a, int b);
136  long long lgcd (long long a,long long b );
137  int gcd_array(int nain, int *ain);
138  void free_region_list(io_region *top);
139  void gindex_to_coord(const int ndims, const PIO_Offset gindex, const PIO_Offset gstride[], PIO_Offset *gcoord);
140  PIO_Offset coord_to_lindex(const int ndims, const PIO_Offset lcoord[], const PIO_Offset count[]);
141 
142  int ceil2(const int i);
143  int pair(const int np, const int p, const int k);
144  int define_iodesc_datatypes(const iosystem_desc_t ios, io_desc_t *iodesc);
145 
146  int create_mpi_datatypes(const MPI_Datatype basetype,const int msgcnt,const PIO_Offset dlen,
147  const PIO_Offset mindex[],const int mcount[],int *mfrom, MPI_Datatype mtype[]);
148  int compare_offsets(const void *a,const void *b) ;
149 
150  int subset_rearrange_create(const iosystem_desc_t ios, int maplen, PIO_Offset compmap[],
151  const int gsize[], const int ndims, io_desc_t *iodesc);
152  void print_trace (FILE *fp);
153  void cn_buffer_report(iosystem_desc_t ios, bool collective);
156  void flush_buffer(int ncid, wmulti_buffer *wmb, bool flushtodisk);
157  void piomemerror(iosystem_desc_t ios, size_t req, char *fname, const int line);
158  void compute_maxaggregate_bytes(const iosystem_desc_t ios, io_desc_t *iodesc);
159  int check_mpi(file_desc_t *file, const int mpierr, const char *filename,
160  const int line);
161 
162 #ifdef BGQ
163  void identity(MPI_Comm comm, int *iotask);
164  void determineiotasks(const MPI_Comm comm, int *numiotasks,int *base, int *stride, int *rearr,
165  bool *iamIOtask);
166 
167 #endif
168 
169 #if defined(__cplusplus)
170 }
171 #endif
172 
176 {
177  PIO_MSG_OPEN_FILE,
178  PIO_MSG_CREATE_FILE,
179  PIO_MSG_INQ_ATT,
180  PIO_MSG_INQ_FORMAT,
181  PIO_MSG_INQ_VARID,
182  PIO_MSG_DEF_VAR,
183  PIO_MSG_INQ_VAR,
184  PIO_MSG_PUT_ATT_DOUBLE,
185  PIO_MSG_PUT_ATT_INT,
186  PIO_MSG_RENAME_ATT,
187  PIO_MSG_DEL_ATT,
188  PIO_MSG_INQ,
189  PIO_MSG_GET_ATT_TEXT,
190  PIO_MSG_GET_ATT_SHORT,
191  PIO_MSG_PUT_ATT_LONG,
192  PIO_MSG_REDEF,
193  PIO_MSG_SET_FILL,
194  PIO_MSG_ENDDEF,
195  PIO_MSG_RENAME_VAR,
196  PIO_MSG_PUT_ATT_SHORT,
197  PIO_MSG_PUT_ATT_TEXT,
198  PIO_MSG_INQ_ATTNAME,
199  PIO_MSG_GET_ATT_ULONGLONG,
200  PIO_MSG_GET_ATT_USHORT,
201  PIO_MSG_PUT_ATT_ULONGLONG,
202  PIO_MSG_GET_ATT_UINT,
203  PIO_MSG_GET_ATT_LONGLONG,
204  PIO_MSG_PUT_ATT_SCHAR,
205  PIO_MSG_PUT_ATT_FLOAT,
206  PIO_MSG_RENAME_DIM,
207  PIO_MSG_GET_ATT_LONG,
208  PIO_MSG_INQ_DIM,
209  PIO_MSG_INQ_DIMID,
210  PIO_MSG_PUT_ATT_USHORT,
211  PIO_MSG_GET_ATT_FLOAT,
212  PIO_MSG_SYNC,
213  PIO_MSG_PUT_ATT_LONGLONG,
214  PIO_MSG_PUT_ATT_UINT,
215  PIO_MSG_GET_ATT_SCHAR,
216  PIO_MSG_INQ_ATTID,
217  PIO_MSG_DEF_DIM,
218  PIO_MSG_GET_ATT_INT,
219  PIO_MSG_GET_ATT_DOUBLE,
220  PIO_MSG_PUT_ATT_UCHAR,
221  PIO_MSG_GET_ATT_UCHAR,
222  PIO_MSG_PUT_VARS_UCHAR,
223  PIO_MSG_GET_VAR1_SCHAR,
224  PIO_MSG_GET_VARS_ULONGLONG,
225  PIO_MSG_GET_VARM_UCHAR,
226  PIO_MSG_GET_VARM_SCHAR,
227  PIO_MSG_GET_VARS_SHORT,
228  PIO_MSG_GET_VAR_DOUBLE,
229  PIO_MSG_GET_VARA_DOUBLE,
230  PIO_MSG_GET_VAR_INT,
231  PIO_MSG_GET_VAR_USHORT,
232  PIO_MSG_PUT_VARS_USHORT,
233  PIO_MSG_GET_VARA_TEXT,
234  PIO_MSG_PUT_VARS_ULONGLONG,
235  PIO_MSG_GET_VARA_INT,
236  PIO_MSG_PUT_VARM,
237  PIO_MSG_GET_VAR1_FLOAT,
238  PIO_MSG_GET_VAR1_SHORT,
239  PIO_MSG_GET_VARS_INT,
240  PIO_MSG_PUT_VARS_UINT,
241  PIO_MSG_GET_VAR_TEXT,
242  PIO_MSG_GET_VARM_DOUBLE,
243  PIO_MSG_PUT_VARM_UCHAR,
244  PIO_MSG_PUT_VAR_USHORT,
245  PIO_MSG_GET_VARS_SCHAR,
246  PIO_MSG_GET_VARA_USHORT,
247  PIO_MSG_PUT_VAR1_LONGLONG,
248  PIO_MSG_PUT_VARA_UCHAR,
249  PIO_MSG_PUT_VARM_SHORT,
250  PIO_MSG_PUT_VAR1_LONG,
251  PIO_MSG_PUT_VARS_LONG,
252  PIO_MSG_GET_VAR1_USHORT,
253  PIO_MSG_PUT_VAR_SHORT,
254  PIO_MSG_PUT_VARA_INT,
255  PIO_MSG_GET_VAR_FLOAT,
256  PIO_MSG_PUT_VAR1_USHORT,
257  PIO_MSG_PUT_VARA_TEXT,
258  PIO_MSG_PUT_VARM_TEXT,
259  PIO_MSG_GET_VARS_UCHAR,
260  PIO_MSG_GET_VAR,
261  PIO_MSG_PUT_VARM_USHORT,
262  PIO_MSG_GET_VAR1_LONGLONG,
263  PIO_MSG_GET_VARS_USHORT,
264  PIO_MSG_GET_VAR_LONG,
265  PIO_MSG_GET_VAR1_DOUBLE,
266  PIO_MSG_PUT_VAR_ULONGLONG,
267  PIO_MSG_PUT_VAR_INT,
268  PIO_MSG_GET_VARA_UINT,
269  PIO_MSG_PUT_VAR_LONGLONG,
270  PIO_MSG_GET_VARS_LONGLONG,
271  PIO_MSG_PUT_VAR_SCHAR,
272  PIO_MSG_PUT_VAR_UINT,
273  PIO_MSG_PUT_VAR,
274  PIO_MSG_PUT_VARA_USHORT,
275  PIO_MSG_GET_VAR_LONGLONG,
276  PIO_MSG_GET_VARA_SHORT,
277  PIO_MSG_PUT_VARS_SHORT,
278  PIO_MSG_PUT_VARA_UINT,
279  PIO_MSG_PUT_VARA_SCHAR,
280  PIO_MSG_PUT_VARM_ULONGLONG,
281  PIO_MSG_PUT_VAR1_UCHAR,
282  PIO_MSG_PUT_VARM_INT,
283  PIO_MSG_PUT_VARS_SCHAR,
284  PIO_MSG_GET_VARA_LONG,
285  PIO_MSG_PUT_VAR1,
286  PIO_MSG_GET_VAR1_INT,
287  PIO_MSG_GET_VAR1_ULONGLONG,
288  PIO_MSG_GET_VAR_UCHAR,
289  PIO_MSG_PUT_VARA_FLOAT,
290  PIO_MSG_GET_VARA_UCHAR,
291  PIO_MSG_GET_VARS_FLOAT,
292  PIO_MSG_PUT_VAR1_FLOAT,
293  PIO_MSG_PUT_VARM_FLOAT,
294  PIO_MSG_PUT_VAR1_TEXT,
295  PIO_MSG_PUT_VARS_TEXT,
296  PIO_MSG_PUT_VARM_LONG,
297  PIO_MSG_GET_VARS_LONG,
298  PIO_MSG_PUT_VARS_DOUBLE,
299  PIO_MSG_GET_VAR1,
300  PIO_MSG_GET_VAR_UINT,
301  PIO_MSG_PUT_VARA_LONGLONG,
302  PIO_MSG_GET_VARA,
303  PIO_MSG_PUT_VAR_DOUBLE,
304  PIO_MSG_GET_VARA_SCHAR,
305  PIO_MSG_PUT_VAR_FLOAT,
306  PIO_MSG_GET_VAR1_UINT,
307  PIO_MSG_GET_VARS_UINT,
308  PIO_MSG_PUT_VAR1_ULONGLONG,
309  PIO_MSG_PUT_VARM_UINT,
310  PIO_MSG_PUT_VAR1_UINT,
311  PIO_MSG_PUT_VAR1_INT,
312  PIO_MSG_GET_VARA_FLOAT,
313  PIO_MSG_GET_VARM_TEXT,
314  PIO_MSG_PUT_VARS_FLOAT,
315  PIO_MSG_GET_VAR1_TEXT,
316  PIO_MSG_PUT_VARA_SHORT,
317  PIO_MSG_PUT_VAR1_SCHAR,
318  PIO_MSG_PUT_VARA_ULONGLONG,
319  PIO_MSG_PUT_VARM_DOUBLE,
320  PIO_MSG_GET_VARM_INT,
321  PIO_MSG_PUT_VARA,
322  PIO_MSG_PUT_VARA_LONG,
323  PIO_MSG_GET_VARM_UINT,
324  PIO_MSG_GET_VARM,
325  PIO_MSG_PUT_VAR1_DOUBLE,
326  PIO_MSG_GET_VARS_DOUBLE,
327  PIO_MSG_GET_VARA_LONGLONG,
328  PIO_MSG_GET_VAR_ULONGLONG,
329  PIO_MSG_PUT_VARM_SCHAR,
330  PIO_MSG_GET_VARA_ULONGLONG,
331  PIO_MSG_GET_VAR_SHORT,
332  PIO_MSG_GET_VARM_FLOAT,
333  PIO_MSG_PUT_VAR_TEXT,
334  PIO_MSG_PUT_VARS_INT,
335  PIO_MSG_GET_VAR1_LONG,
336  PIO_MSG_GET_VARM_LONG,
337  PIO_MSG_GET_VARM_USHORT,
338  PIO_MSG_PUT_VAR1_SHORT,
339  PIO_MSG_PUT_VARS_LONGLONG,
340  PIO_MSG_GET_VARM_LONGLONG,
341  PIO_MSG_GET_VARS_TEXT,
342  PIO_MSG_PUT_VARA_DOUBLE,
343  PIO_MSG_PUT_VARS,
344  PIO_MSG_PUT_VAR_UCHAR,
345  PIO_MSG_GET_VAR1_UCHAR,
346  PIO_MSG_PUT_VAR_LONG,
347  PIO_MSG_GET_VARS,
348  PIO_MSG_GET_VARM_SHORT,
349  PIO_MSG_GET_VARM_ULONGLONG,
350  PIO_MSG_PUT_VARM_LONGLONG,
351  PIO_MSG_GET_VAR_SCHAR,
352  PIO_MSG_GET_ATT_UBYTE,
353  PIO_MSG_PUT_ATT_STRING,
354  PIO_MSG_GET_ATT_STRING,
355  PIO_MSG_PUT_ATT_UBYTE,
356  PIO_MSG_INQ_VAR_FILL,
357  PIO_MSG_DEF_VAR_FILL,
358  PIO_MSG_DEF_VAR_DEFLATE,
359  PIO_MSG_INQ_VAR_DEFLATE,
360  PIO_MSG_INQ_VAR_SZIP,
361  PIO_MSG_DEF_VAR_FLETCHER32,
362  PIO_MSG_INQ_VAR_FLETCHER32,
363  PIO_MSG_DEF_VAR_CHUNKING,
364  PIO_MSG_INQ_VAR_CHUNKING,
365  PIO_MSG_DEF_VAR_ENDIAN,
366  PIO_MSG_INQ_VAR_ENDIAN,
367  PIO_MSG_SET_CHUNK_CACHE,
368  PIO_MSG_GET_CHUNK_CACHE,
369  PIO_MSG_SET_VAR_CHUNK_CACHE,
370  PIO_MSG_GET_VAR_CHUNK_CACHE,
371  PIO_MSG_INITDECOMP_DOF,
372  PIO_MSG_WRITEDARRAY,
373  PIO_MSG_READDARRAY,
374  PIO_MSG_SETERRORHANDLING,
375  PIO_MSG_FREEDECOMP,
376  PIO_MSG_CLOSE_FILE,
377  PIO_MSG_DELETE_FILE,
378  PIO_MSG_EXIT,
379  PIO_MSG_GET_ATT,
380  PIO_MSG_PUT_ATT,
381  PIO_MSG_INQ_TYPE
382 };
383 
384 #endif /* __PIO_INTERNAL__ */
IO system descriptor structure.
Definition: pio.h:140
void compute_maxaggregate_bytes(const iosystem_desc_t ios, io_desc_t *iodesc)
Compute the maximum aggregate number of bytes.
Definition: pio_darray.c:2148
void CheckMPIReturn(const int ierr, const char file[], const int line)
Wrapper for MPI calls to print the Error string on error.
Definition: pio_spmd.c:32
void pio_get_env(void)
Get PIO environment variables.
Definition: pioc_support.c:163
int pio_swapm(void *sndbuf, int sndlths[], int sdispls[], MPI_Datatype stypes[], void *rcvbuf, int rcvlths[], int rdispls[], MPI_Datatype rtypes[], MPI_Comm comm, const bool handshake, bool isend, const int max_requests)
Provides the functionality of MPI_Alltoallw with flow control options.
Definition: pio_spmd.c:241
PIO_Offset coord_to_lindex(const int ndims, const PIO_Offset lcoord[], const PIO_Offset count[])
Definition: pio_rearrange.c:130
int check_netcdf(file_desc_t *file, const int status, const char *fname, const int line)
Check the result of a netCDF API call.
Definition: pioc_support.c:304
int create_mpi_datatypes(const MPI_Datatype basetype, const int msgcnt, const PIO_Offset dlen, const PIO_Offset mindex[], const int mcount[], int *mfrom, MPI_Datatype mtype[])
Definition: pio_rearrange.c:187
int pio_fc_gather(void *sendbuf, const int sendcnt, const MPI_Datatype sendtype, void *recvbuf, const int recvcnt, const MPI_Datatype recvtype, const int root, MPI_Comm comm, const int flow_cntl)
Provides the functionality of MPI_Gather with flow control options.
Definition: pio_spmd.c:50
int pio_fc_gatherv(void *sendbuf, const int sendcnt, const MPI_Datatype sendtype, void *recvbuf, const int recvcnts[], const int recvdispl[], const MPI_Datatype recvtype, const int root, MPI_Comm comm, const int flow_cntl)
Provides the functionality of MPI_Gatherv with flow control options.
Definition: pio_spmd.c:137
struct pio_swapm_defaults pio_swapm_defaults
swapm defaults.
int compare_offsets(const void *a, const void *b)
Definition: pio_rearrange.c:1125
swapm defaults.
Definition: pio_internal.h:68
int pio_delete_iosystem_from_list(int piosysid)
Delete iosystem info from list.
Definition: pio_lists.c:88
PIO_MSG
These are the messages that can be sent over the intercomm when async is being used.
Definition: pio_internal.h:175
File descriptor structure.
Definition: pio.h:254
void compute_maxIObuffersize(MPI_Comm io_comm, io_desc_t *iodesc)
Definition: pio_rearrange.c:148
int define_iodesc_datatypes(const iosystem_desc_t ios, io_desc_t *iodesc)
Definition: pio_rearrange.c:278
void compute_buffer_init(iosystem_desc_t ios)
Initialize the compute buffer to size PIO_CNBUFFER_LIMIT.
Definition: pio_darray.c:56
int rearrange_comp2io(const iosystem_desc_t ios, io_desc_t *iodesc, void *sbuf, void *rbuf, const int nvars)
Definition: pio_rearrange.c:597
Used to sort map points in the subset rearranger.
Definition: pio_internal.h:60
struct mapsort mapsort
Used to sort map points in the subset rearranger.
int subset_rearrange_create(const iosystem_desc_t ios, const int maplen, PIO_Offset compmap[], const int gsize[], const int ndim, io_desc_t *iodesc)
Definition: pio_rearrange.c:1222
int ceil2(const int i)
Returns the smallest power of 2 greater than i.
Definition: pio_spmd.c:219
void flush_buffer(int ncid, wmulti_buffer *wmb, bool flushtodisk)
Flush the buffer.
Definition: pio_darray.c:2119
void cn_buffer_report(iosystem_desc_t ios, bool collective)
Print out info about the buffer for debug purposes.
Definition: pio_darray.c:2044
int check_mpi(file_desc_t *file, const int mpierr, const char *filename, const int line)
Handle MPI errors.
Definition: pioc_support.c:274
int rearrange_io2comp(const iosystem_desc_t ios, io_desc_t *iodesc, void *sbuf, void *rbuf)
Definition: pio_rearrange.c:762
int pair(const int np, const int p, const int k)
Given integers p and k between 0 and np-1, if (p+1)^k <= np-1 then return (p+1)^k else -1...
Definition: pio_spmd.c:231
multi buffer.
Definition: pio.h:237
int box_rearrange_create(const iosystem_desc_t ios, const int maplen, const PIO_Offset compmap[], const int gsize[], const int ndim, io_desc_t *iodesc)
Definition: pio_rearrange.c:966
void free_cn_buffer_pool(iosystem_desc_t ios)
Free the buffer pool.
Definition: pio_darray.c:2097
int flush_output_buffer(file_desc_t *file, bool force, PIO_Offset addsize)
Flush the output buffer.
Definition: pio_darray.c:1912
IO region structure.
Definition: pio.h:76
IO descriptor structure.
Definition: pio.h:90
Public headers for the PIO C interface.
void pio_add_to_file_list(file_desc_t *file)
Add a new entry to the global list of open files.
Definition: pio_lists.c:17