SIONlib  1.7.7
Scalable I/O library for parallel access to task-local files
sion_filedesc.c
Go to the documentation of this file.
1 /****************************************************************************
2 ** SIONLIB http://www.fz-juelich.de/jsc/sionlib **
3 *****************************************************************************
4 ** Copyright (c) 2008-2019 **
5 ** Forschungszentrum Juelich, Juelich Supercomputing Centre **
6 ** **
7 ** See the file COPYRIGHT in the package base directory for details **
8 ****************************************************************************/
9 
14 #define _XOPEN_SOURCE 700
15 
16 #include <stdlib.h>
17 #include <stdio.h>
18 #include <string.h>
19 #include <time.h>
20 #include <assert.h>
21 
22 #include "sion.h"
23 #include "sion_debug.h"
24 #include "sion_error_handler.h"
25 #include "sion_internal.h"
26 #include "sion_filedesc.h"
27 #include "sion_keyvalue_keymngr.h"
28 
29 
30 #define DFUNCTION "_sion_init_filedesc"
38 {
39 
40  int rc = SION_SUCCESS;
41 
42  if (sion_filedesc == NULL) {
43  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot initalized, data structure is not allocated, aborting ...\n"));
44  }
45  sion_filedesc->fileptr = NULL;
46  sion_filedesc->fname = NULL;
47  sion_filedesc->sid = -1;
48  sion_filedesc->rank = -1;
49  sion_filedesc->lrank = -1;
50  sion_filedesc->globalrank = -1;
51  sion_filedesc->ntasks = -1;
52  sion_filedesc->state = SION_FILESTATE_UNKNOWN;
53  sion_filedesc->mode = SION_FILEMODE_UNKNOWN;
54  sion_filedesc->dup_mode = SION_DESCSTATE_ORIG;
55  sion_filedesc->dup_sel_rank = 0;
56  sion_filedesc->dup_sel_key = 0;
57  sion_filedesc->endianness = -1;
58  sion_filedesc->swapbytes = 0;
59  sion_filedesc->fileversion = SION_FILEFORMAT_VERSION;
60  sion_filedesc->filesionversion = 1000 * SION_MAIN_VERSION + SION_SUB_VERSION;
61  sion_filedesc->filesionpatchlevel = SION_SUB_VERSION;
62  sion_filedesc->fsblksize = -1; /* fs block size */
63  sion_filedesc->lastchunknr = -1; /* number of current block */
64  sion_filedesc->maxchunks = -1;
65  sion_filedesc->maxusedchunks = -1;
66 
67  sion_filedesc->startpos = -1;
68  sion_filedesc->chunksize = -1;
69  sion_filedesc->chunksize_req = -1;
70  sion_filedesc->blocksizes = NULL; /* vector of written bytes in each block for current task */
71 
72  sion_filedesc->globalskip = -1; /* number of bytes to skip to next block of same processor */
73  sion_filedesc->end_of_header = -1;
74  sion_filedesc->start_of_varheader = -1;
75  sion_filedesc->start_of_data = -1;
76 
77  sion_filedesc->all_chunksizes = NULL; /* only used if sion is opened from a single task for read */
78  sion_filedesc->all_globalranks = NULL; /* only used if sion is opened from a single task for read */
79  sion_filedesc->all_localranks = NULL; /* only used if sion is opened in mapped mode */
80  sion_filedesc->all_startpointers = NULL; /* only used if sion is opened from a single task for read */
81 
82  sion_filedesc->all_currentpos = NULL; /* only used if sion is opened from a single task for write */
83  sion_filedesc->all_currentblocknr = NULL; /* only used if sion is opened from a single task for write */
84 
85  sion_filedesc->all_coll_collector = NULL; /* only used on rank 0 if usecoll=1 */
86  sion_filedesc->all_coll_collsize = NULL; /* only used on rank 0 if usecoll=1 */
87  sion_filedesc->all_coll_capability = NULL; /* only used on rank 0 if usecoll=1 */
88 
89  sion_filedesc->all_blockcount = NULL; /* size, only used if sion is opened from a single task for read */
90  sion_filedesc->all_blocksizes = NULL; /* size*maxchunks, only used if sion is opened from a single task for read */
91 
92  sion_filedesc->currentpos = -1; /* only used if opened for one rank, reading */
93  sion_filedesc->currentblocknr = -1; /* only used if opened for one rank, reading */
94  sion_filedesc->debug = -1; /* 0 or 1 for debugging */
95 
96  sion_filedesc->nfiles = -1;
97  sion_filedesc->filenumber = -1;
98  sion_filedesc->mapping_size = -1;
99  sion_filedesc->mapping = NULL;
100 
101  sion_filedesc->ntotaltasksinfile = -1;
102  sion_filedesc->nlocaltasksinfile = -1;
103  sion_filedesc->filemanagedbytask = -1;
104 
105  sion_filedesc->ntasks = -1;
106 
107  sion_filedesc->multifiles = NULL;
108 
109  sion_filedesc->flag1 = _SION_FLAG1_NONE;
110  sion_filedesc->flag2 = _SION_FLAG2_NONE;
111  sion_filedesc->prefix = NULL;
112 
113  sion_filedesc->dataptr = NULL;
114  sion_filedesc->keyvalptr = NULL;
115 
116  sion_filedesc->keyvalmode = SION_KEYVAL_NONE;
117  sion_filedesc->keyvalptr = NULL;
118  sion_filedesc->all_keyvalptr = NULL;
119 
120  sion_filedesc->fpbuffer = NULL;
121  sion_filedesc->fpbuffer_size = -1;
122 
123  sion_filedesc->usecache = 0;
124  sion_filedesc->cachesize = -1;
125  sion_filedesc->cacheid = -1;
126  if(SION_CACHE_FNLEN>0) {
127  sion_filedesc->cachefn[0]='\0';
128  }
129  sion_filedesc->cachemode = SION_CACHE_UNKNOWN;
130  sion_filedesc->cacheptr = NULL;
131 
132  sion_filedesc->usebuffer = 0;
133  sion_filedesc->buffer = NULL;
134  sion_filedesc->buffer_size = -1;
135  sion_filedesc->buffer_ptr = 0;
136 
137  sion_filedesc->compress = 0;
138 
139 
140  sion_filedesc->usecoll = 0;
141  sion_filedesc->collsize = -1;
142  sion_filedesc->collector = -1;
143  sion_filedesc->coll_capability = SION_CAPABILITY_FULL;
144  sion_filedesc->colldebug = 0;
145  sion_filedesc->collcmdused = 0;
146  sion_filedesc->fileptr_exported = 0;
147  sion_filedesc->collmergemode = 0;
148  sion_filedesc->collmsa = 0;
149 
150  sion_filedesc->usebuddy = 0;
151  sion_filedesc->buddylevel = 0;
152  sion_filedesc->buddynr = 0;
153  sion_filedesc->buddies = NULL;
154 
155  sion_filedesc->usehints = 0;
156  sion_filedesc->hinttype = SION_HINTS_TYPE_UNKNOWN;
157 
158  return (rc);
159 }
160 #undef DFUNCTION
161 
162 
163 #define DFUNCTION "_sion_alloc_filedesc"
169 {
170  _sion_filedesc *sion_filedesc;
171 
172  sion_filedesc = (_sion_filedesc *) malloc(sizeof(_sion_filedesc));
173  if (sion_filedesc == NULL) {
174  _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"cannot allocate filedescriptor structure of size %lu (sion_filedesc), aborting ...\n", (unsigned long) sizeof(sion_filedesc));
175  return(NULL);
176  }
177 
178  return(sion_filedesc);
179 }
180 #undef DFUNCTION
181 
182 
183 #define DFUNCTION "_sion_realloc_filedesc_blocklist"
191 int _sion_realloc_filedesc_blocklist(_sion_filedesc *sion_filedesc, sion_int32 maxchunks)
192 {
193  int rc = SION_SUCCESS;
194  int i;
195  if (sion_filedesc->maxchunks <= 0) {
196  sion_filedesc->blocksizes = (sion_int64 *) malloc(maxchunks * sizeof(sion_int64));
197  if (sion_filedesc->blocksizes == NULL) {
198  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot allocate temporary memory of size %lu (sion_blocksizes), aborting ...\n",
199  (unsigned long) maxchunks * sizeof(sion_int64)));
200  }
201  for (i = 0; i < maxchunks; i++)
202  sion_filedesc->blocksizes[i] = 0; /* init */
203  sion_filedesc->maxchunks = maxchunks;
204  DPRINTFP((2, DFUNCTION, -1, " alloc for %d chunks\n", maxchunks ));
205  }
206  else {
207  if (sion_filedesc->maxchunks <= maxchunks) {
208  sion_filedesc->blocksizes = (sion_int64 *) realloc(sion_filedesc->blocksizes, maxchunks * sizeof(sion_int64));
209  for (i = sion_filedesc->maxchunks; i < maxchunks; i++)
210  sion_filedesc->blocksizes[i] = 0; /* init */
211  DPRINTFP((2, DFUNCTION, -1, " realloc from %d to %d chunks\n", sion_filedesc->maxchunks, maxchunks ));
212  sion_filedesc->maxchunks = maxchunks;
213  }
214  else {
215  fprintf(stderr, "allocate temporary memory of size %zu (sion_blocksizes) not necessary (allocated size %zu) ...\n",
216  (size_t) maxchunks * sizeof(sion_int64), (size_t) sion_filedesc->maxchunks * sizeof(sion_int64));
217  DPRINTFP((2, DFUNCTION, -1, "allocate temporary memory of size %zu (sion_blocksizes) not necessary (allocated size %zu) ...\n",
218  (size_t) maxchunks * sizeof(sion_int64), (size_t) sion_filedesc->maxchunks * sizeof(sion_int64) ));
219  }
220  }
221  return (rc);
222 }
223 #undef DFUNCTION
224 
225 
226 #define DFUNCTION "_sion_alloc_filedesc_all_chunksizes"
227 int _sion_alloc_filedesc_all_chunksizes(_sion_filedesc *sion_filedesc)
228 {
229  int i, rc = SION_SUCCESS;
230  sion_int64 *p;
231 
232  if (sion_filedesc->ntasks<0) {
233  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot allocate internal arrays ntasks<0, aborting ...\n"));
234  }
235 
236  DPRINTFP((2, DFUNCTION, -1, "enter alloc arrays size=%d (%lu bytes)\n", sion_filedesc->ntasks, (unsigned long) sion_filedesc->ntasks * sizeof(sion_int64)));
237  sion_filedesc->all_chunksizes = p = (sion_int64 *) malloc(sion_filedesc->ntasks * sizeof(sion_int64));
238  if (sion_filedesc->all_chunksizes == NULL) {
239  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot allocate temporary memory of size %lu (sion_chunksizes), aborting ...\n",
240  (unsigned long) sion_filedesc->ntasks * sizeof(sion_int64)));
241  }
242  for (i = 0; i < sion_filedesc->ntasks; i++) p[i] = -1;
243  return(rc);
244 }
245 #undef DFUNCTION
246 
247 #define DFUNCTION "_sion_alloc_filedesc_all_startpointers"
248 int _sion_alloc_filedesc_all_startpointers(_sion_filedesc *sion_filedesc)
249 {
250  int i, rc = SION_SUCCESS;
251  sion_int64 *p;
252 
253  if (sion_filedesc->ntasks<0) {
254  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot allocate internal arrays ntasks<0, aborting ...\n"));
255  }
256  sion_filedesc->all_startpointers = p = (sion_int64 *) malloc(sion_filedesc->ntasks * sizeof(sion_int64));
257  if (sion_filedesc->all_startpointers == NULL) {
258  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot allocate temporary memory of size %lu (sion_all_startpointers), aborting ...\n",
259  (unsigned long) sion_filedesc->ntasks * sizeof(sion_int64)));
260  }
261  for (i = 0; i < sion_filedesc->ntasks; i++) p[i] = -1;
262 
263  return(rc);
264 }
265 #undef DFUNCTION
266 
267 #define DFUNCTION "_sion_alloc_filedesc_all_globalranks"
268 int _sion_alloc_filedesc_all_globalranks(_sion_filedesc *sion_filedesc)
269 {
270  int i, rc = SION_SUCCESS;
271  sion_int64 *p;
272 
273  if (sion_filedesc->ntasks<0) {
274  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot allocate internal arrays ntasks<0, aborting ...\n"));
275  }
276  sion_filedesc->all_globalranks = p = (sion_int64 *) malloc(sion_filedesc->ntasks * sizeof(sion_int64));
277  if (sion_filedesc->all_globalranks == NULL) {
278  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot allocate temporary memory of size %lu (sion_all_globalranks), aborting ...\n",
279  (unsigned long) sion_filedesc->ntasks * sizeof(sion_int64)));
280  }
281  for (i = 0; i < sion_filedesc->ntasks; i++) p[i] = -1;
282 
283  return(rc);
284 }
285 #undef DFUNCTION
286 
287 #define DFUNCTION "_sion_alloc_filedesc_all_localranks"
288 int _sion_alloc_filedesc_all_localranks(_sion_filedesc *sion_filedesc)
289 {
290  int i, rc = SION_SUCCESS;
291  sion_int64 *p;
292 
293  if (sion_filedesc->ntasks<0) {
294  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot allocate internal arrays ntasks<0, aborting ...\n"));
295  }
296  sion_filedesc->all_localranks = p = (sion_int64 *) malloc(sion_filedesc->ntasks * sizeof(sion_int64));
297  if (sion_filedesc->all_localranks == NULL) {
298  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot allocate temporary memory of size %lu (sion_all_localranks), aborting ...\n",
299  (unsigned long) sion_filedesc->ntasks * sizeof(sion_int64)));
300  }
301  for (i = 0; i < sion_filedesc->ntasks; i++) p[i] = -1;
302 
303  return(rc);
304 }
305 #undef DFUNCTION
306 
307 #define DFUNCTION "_sion_alloc_filedesc_all_keyvalptr"
308 int _sion_alloc_filedesc_all_keyvalptr(_sion_filedesc *sion_filedesc)
309 {
310  int i, rc = SION_SUCCESS;
311  void **p;
312 
313  if (sion_filedesc->ntasks<0) {
314  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot allocate internal arrays ntasks<0, aborting ...\n"));
315  }
316 
317  DPRINTFP((2, DFUNCTION, -1, "enter alloc arrays size=%d (%lu bytes)\n", sion_filedesc->ntasks, (unsigned long) sion_filedesc->ntasks * sizeof(sion_int64)));
318  sion_filedesc->all_keyvalptr = p = (void *) malloc(sion_filedesc->ntasks * sizeof(void *));
319  if (sion_filedesc->all_keyvalptr == NULL) {
320  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot allocate temporary memory of size %lu (sion_all_keyvalptr), aborting ...\n",
321  (unsigned long) sion_filedesc->ntasks * sizeof(sion_int64)));
322  }
323  for (i = 0; i < sion_filedesc->ntasks; i++) p[i] = NULL;
324  return(rc);
325 }
326 #undef DFUNCTION
327 
328 
329 #define DFUNCTION "_sion_alloc_filedesc_arrays"
337 {
338  DPRINTFP((2, DFUNCTION, -1, "enter alloc arrays size=%d (%lu bytes)\n", sion_filedesc->ntasks, (unsigned long) sion_filedesc->ntasks * sizeof(sion_int64)));
339 
340  _sion_alloc_filedesc_all_chunksizes(sion_filedesc);
341  _sion_alloc_filedesc_all_startpointers(sion_filedesc);
342  _sion_alloc_filedesc_all_globalranks(sion_filedesc);
343 
344  DPRINTFP((2, DFUNCTION, -1, "leave alloc arrays size=%d\n", sion_filedesc->ntasks));
345  return (1);
346 }
347 #undef DFUNCTION
348 
349 
350 #define DFUNCTION "_sion_free_filedesc_all_chunksizes"
351 int _sion_free_filedesc_all_chunksizes(_sion_filedesc *sion_filedesc)
352 {
353  DPRINTFP((2, DFUNCTION, -1, "enter free arrays\n"));
354  if (sion_filedesc->all_chunksizes != NULL) {
355  free(sion_filedesc->all_chunksizes);
356  sion_filedesc->all_chunksizes=NULL;
357  }
358  DPRINTFP((2, DFUNCTION, -1, "leave free arrays\n"));
359  return (1);
360 }
361 #undef DFUNCTION
362 
363 #define DFUNCTION "_sion_free_filedesc_all_globalranks"
364 int _sion_free_filedesc_all_globalranks(_sion_filedesc *sion_filedesc)
365 {
366  DPRINTFP((2, DFUNCTION, -1, "enter free arrays\n"));
367  if (sion_filedesc->all_globalranks != NULL) {
368  free(sion_filedesc->all_globalranks);
369  sion_filedesc->all_globalranks=NULL;
370  }
371  DPRINTFP((2, DFUNCTION, -1, "leave free arrays\n"));
372  return (1);
373 }
374 #undef DFUNCTION
375 
376 #define DFUNCTION "_sion_free_filedesc_all_startpointers"
377 int _sion_free_filedesc_all_startpointers(_sion_filedesc *sion_filedesc)
378 {
379  DPRINTFP((2, DFUNCTION, -1, "enter free arrays\n"));
380  if (sion_filedesc->all_startpointers != NULL) {
381  free(sion_filedesc->all_startpointers);
382  sion_filedesc->all_startpointers=NULL;
383  }
384  DPRINTFP((2, DFUNCTION, -1, "leave free arrays\n"));
385  return (1);
386 }
387 #undef DFUNCTION
388 
389 #define DFUNCTION "_sion_free_filedesc_all_localranks"
390 int _sion_free_filedesc_all_localranks(_sion_filedesc *sion_filedesc)
391 {
392  DPRINTFP((2, DFUNCTION, -1, "enter free arrays\n"));
393  if (sion_filedesc->all_localranks != NULL) {
394  free(sion_filedesc->all_localranks);
395  sion_filedesc->all_localranks=NULL;
396  }
397  DPRINTFP((2, DFUNCTION, -1, "leave free arrays\n"));
398  return (1);
399 }
400 #undef DFUNCTION
401 
402 #define DFUNCTION "_sion_free_filedesc_all_keyvalptr"
403 int _sion_free_filedesc_all_keyvalptr(_sion_filedesc *sion_filedesc)
404 {
405  int tasknr = 0;
406  DPRINTFP((2, DFUNCTION, -1, "enter free arrays\n"));
407  if (sion_filedesc->all_keyvalptr != NULL) {
408  for(tasknr=0;tasknr<sion_filedesc->ntasks;tasknr++) {
409  if (sion_filedesc->all_keyvalptr[tasknr]) {
410  DPRINTFP((2, DFUNCTION, -1, "free now KEYVALPTR all_keyvalptr[%d] = %x\n",tasknr,sion_filedesc->all_keyvalptr[tasknr]));
411  _sion_keyvalue_keymngr_destroy((_sion_keyvalue_keymngr **)&(sion_filedesc->all_keyvalptr[tasknr]));
412  }
413  }
414  free(sion_filedesc->all_keyvalptr);
415  sion_filedesc->all_keyvalptr=NULL;
416  }
417  DPRINTFP((2, DFUNCTION, -1, "leave free arrays\n"));
418  return (1);
419 }
420 #undef DFUNCTION
421 
422 #define DFUNCTION "_sion_free_filedesc_arrays"
430 {
431 
432  _sion_free_filedesc_all_chunksizes(sion_filedesc);
433  _sion_free_filedesc_all_globalranks(sion_filedesc);
434  _sion_free_filedesc_all_startpointers(sion_filedesc);
435  return (1);
436 }
437 #undef DFUNCTION
438 
439 
440 #define DFUNCTION "_sion_alloc_filedesc_coll_arrays"
448 {
449  int i;
450  sion_int32 *p;
451 
452  if (sion_filedesc->ntasks<0) {
453  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot allocate internal arrays ntasks<0, aborting ...\n"));
454  }
455 
456  DPRINTFP((2, DFUNCTION, -1, "enter alloc arrays size=%d (%lu bytes)\n", sion_filedesc->ntasks, (unsigned long) sion_filedesc->ntasks * sizeof(sion_int32)));
457  sion_filedesc->all_coll_collsize = p = (sion_int32 *) malloc(sion_filedesc->ntasks * sizeof(sion_int32));
458  if (sion_filedesc->all_coll_collsize == NULL) {
459  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot allocate temporary memory of size %lu (sion_all_collsize), aborting ...\n",
460  (unsigned long) sion_filedesc->ntasks * sizeof(sion_int32)));
461  }
462  for (i = 0; i < sion_filedesc->ntasks; i++) p[i] = -1;
463 
464  DPRINTFP((2, DFUNCTION, -1, "enter alloc arrays size=%d (%lu bytes)\n", sion_filedesc->ntasks, (unsigned long) sion_filedesc->ntasks * sizeof(sion_int32)));
465  sion_filedesc->all_coll_collector = p = (sion_int32 *) malloc(sion_filedesc->ntasks * sizeof(sion_int32));
466  if (sion_filedesc->all_coll_collector == NULL) {
467  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot allocate temporary memory of size %lu (sion_all_collector), aborting ...\n",
468  (unsigned long) sion_filedesc->ntasks * sizeof(sion_int32)));
469  }
470  for (i = 0; i < sion_filedesc->ntasks; i++) p[i] = -1;
471 
472  DPRINTFP((2, DFUNCTION, -1, "enter alloc arrays size=%d (%lu bytes)\n", sion_filedesc->ntasks, (unsigned long) sion_filedesc->ntasks * sizeof(sion_int32)));
473  sion_filedesc->all_coll_capability = p = (sion_int32 *) malloc(sion_filedesc->ntasks * sizeof(sion_int32));
474  if (sion_filedesc->all_coll_capability == NULL) {
475  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot allocate temporary memory of size %lu (sion_all_capability), aborting ...\n",
476  (unsigned long) sion_filedesc->ntasks * sizeof(sion_int32)));
477  }
478  for (i = 0; i < sion_filedesc->ntasks; i++) p[i] = -1;
479 
480 
481  DPRINTFP((2, DFUNCTION, -1, "leave alloc arrays size=%d\n", sion_filedesc->ntasks));
482  return (1);
483 }
484 #undef DFUNCTION
485 
486 
487 #define DFUNCTION "_sion_free_filedesc_coll_arrays"
495 {
496 
497  DPRINTFP((2, DFUNCTION, -1, "enter free arrays\n"));
498  if (sion_filedesc->all_coll_collsize != NULL) {
499  free(sion_filedesc->all_coll_collsize);
500  sion_filedesc->all_coll_collsize=NULL;
501  }
502  if (sion_filedesc->all_coll_collector != NULL) {
503  free(sion_filedesc->all_coll_collector);
504  sion_filedesc->all_coll_collector=NULL;
505  }
506  if (sion_filedesc->all_coll_capability != NULL) {
507  free(sion_filedesc->all_coll_capability);
508  sion_filedesc->all_coll_capability=NULL;
509  }
510  DPRINTFP((2, DFUNCTION, -1, "leave free arrays\n"));
511  return (1);
512 }
513 #undef DFUNCTION
514 
515 #define DFUNCTION "_sion_alloc_filedesc_block_arrays"
523 {
524  int i;
525  sion_int64 *p;
526 
527  DPRINTFP((2, DFUNCTION, -1, "enter alloc locations size=%d, maxblocks=%d\n", sion_filedesc->ntasks, sion_filedesc->maxchunks));
528  sion_filedesc->all_blockcount = p = (sion_int64 *) malloc(sion_filedesc->ntasks * sizeof(sion_int64));
529  if (sion_filedesc->all_blockcount == NULL) {
530  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot allocate temporary memory of size %lu (sion_blockcount), aborting ...\n",
531  (unsigned long) sion_filedesc->ntasks * sizeof(sion_int64)));
532  }
533  for (i = 0; i < sion_filedesc->ntasks; i++) p[i] = -1;
534 
535  sion_filedesc->all_currentpos = p = (sion_int64 *) malloc(sion_filedesc->ntasks * sizeof(sion_int64));
536  if (sion_filedesc->all_currentpos == NULL) {
537  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot allocate temporary memory of size %lu (sion_currentpos), aborting ...\n",
538  (unsigned long) sion_filedesc->ntasks * sizeof(sion_int64)));
539  }
540  for (i = 0; i < sion_filedesc->ntasks; i++) p[i] = -1;
541 
542  sion_filedesc->all_currentblocknr = p = (sion_int64 *) malloc(sion_filedesc->ntasks * sizeof(sion_int64));
543  if (sion_filedesc->all_currentblocknr == NULL) {
544  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot allocate temporary memory of size %lu (sion_currentblocknr), aborting ...\n",
545  (unsigned long) sion_filedesc->ntasks * sizeof(sion_int64)));
546  }
547  for (i = 0; i < sion_filedesc->ntasks; i++) p[i] = -1;
548 
549  sion_filedesc->all_blocksizes = p = (sion_int64 *) malloc(sion_filedesc->maxchunks * sion_filedesc->ntasks * sizeof(sion_int64));
550  if (sion_filedesc->all_blocksizes == NULL) {
551  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot allocate temporary memory of size %lu (sion_blocksizes), aborting ...\n",
552  (unsigned long) sion_filedesc->ntasks * sizeof(sion_int64)));
553  }
554  for (i = 0; i < sion_filedesc->maxchunks * sion_filedesc->ntasks; i++) p[i] = -1;
555 
556 
557  DPRINTFP((2, DFUNCTION, -1, "leave alloc locations size=%d, maxblocks=%d\n", sion_filedesc->ntasks, sion_filedesc->maxchunks));
558  return (1);
559 }
560 #undef DFUNCTION
561 
562 
563 #define DFUNCTION "_sion_alloc_filedesc_block_arrays_only"
571 {
572  int i;
573  sion_int64 *p;
574 
575  DPRINTFP((2, DFUNCTION, -1, "enter alloc locations size=%d, maxblocks=%d\n", sion_filedesc->ntasks, sion_filedesc->maxchunks));
576  sion_filedesc->all_blockcount = p = (sion_int64 *) malloc(sion_filedesc->ntasks * sizeof(sion_int64));
577  if (sion_filedesc->all_blockcount == NULL) {
578  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot allocate temporary memory of size %lu (sion_blockcount), aborting ...\n",
579  (unsigned long) sion_filedesc->ntasks * sizeof(sion_int64)));
580  }
581  for (i = 0; i < sion_filedesc->ntasks; i++) p[i] = -1;
582 
583  sion_filedesc->all_blocksizes = p = (sion_int64 *) malloc(sion_filedesc->maxchunks * sion_filedesc->ntasks * sizeof(sion_int64));
584  if (sion_filedesc->all_blocksizes == NULL) {
585  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot allocate temporary memory of size %lu (sion_blocksizes), aborting ...\n",
586  (unsigned long) sion_filedesc->ntasks * sizeof(sion_int64)));
587  }
588  for (i = 0; i < sion_filedesc->maxchunks * sion_filedesc->ntasks; i++) p[i] = -1;
589 
590  DPRINTFP((2, DFUNCTION, -1, "leave alloc locations size=%d, maxblocks=%d\n", sion_filedesc->ntasks, sion_filedesc->maxchunks));
591  return (1);
592 }
593 #undef DFUNCTION
594 
595 #define DFUNCTION "_sion_free_filedesc"
596 int _sion_free_filedesc(_sion_filedesc *sion_filedesc)
597 {
598 
599  int rc = SION_SUCCESS;
600 
601  if (sion_filedesc == NULL) {
602  return (0);
603  }
604 
605  if (sion_filedesc->fname)
606  free(sion_filedesc->fname);
607  if (sion_filedesc->blocksizes)
608  free(sion_filedesc->blocksizes);
609  if (sion_filedesc->all_chunksizes)
610  free(sion_filedesc->all_chunksizes);
611  if (sion_filedesc->all_globalranks)
612  free(sion_filedesc->all_globalranks);
613  if (sion_filedesc->all_localranks)
614  free(sion_filedesc->all_localranks);
615  if (sion_filedesc->all_startpointers)
616  free(sion_filedesc->all_startpointers);
617  if (sion_filedesc->all_currentpos)
618  free(sion_filedesc->all_currentpos);
619  if (sion_filedesc->all_currentblocknr)
620  free(sion_filedesc->all_currentblocknr);
621  if (sion_filedesc->all_blockcount)
622  free(sion_filedesc->all_blockcount);
623  if (sion_filedesc->all_blocksizes)
624  free(sion_filedesc->all_blocksizes);
625  if (sion_filedesc->all_coll_collsize)
626  free(sion_filedesc->all_coll_collsize);
627  if (sion_filedesc->all_coll_collector)
628  free(sion_filedesc->all_coll_collector);
629  if (sion_filedesc->all_keyvalptr)
630  _sion_free_filedesc_all_keyvalptr(sion_filedesc);
631  if (sion_filedesc->keyvalptr)
632  _sion_keyvalue_keymngr_destroy((_sion_keyvalue_keymngr **)&(sion_filedesc->keyvalptr));
633  if (sion_filedesc->prefix)
634  free(sion_filedesc->prefix);
635  if (sion_filedesc->mapping)
636  free(sion_filedesc->mapping);
637  /* is only a payload pointer, memory should not freed here */
638  /* if (sion_filedesc->dataptr) */
639  /* free(sion_filedesc->dataptr); */
640  if (sion_filedesc->fpbuffer)
641  free(sion_filedesc->fpbuffer);
642  if (sion_filedesc->buffer)
643  free(sion_filedesc->buffer);
644 
645  free(sion_filedesc);
646 
647  return (rc);
648 }
649 #undef DFUNCTION
650 
651 #define DFUNCTION "_sion_print_filedesc"
656 int _sion_print_filedesc(_sion_filedesc *sion_filedesc, int level, char *desc, int flag)
657 {
658 
659  int rc = SION_SUCCESS;
660  int i;
661 
662  if (sion_filedesc == NULL) {
663  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN, DFUNCTION ": cannot print, data structure is not allocated, aborting ...\n"));
664  }
665 
666  DPRINTFP((level, desc, sion_filedesc->rank, "DUMP: sion_filedesc\n"));
667  DPRINTFP((level, desc, sion_filedesc->rank, "-------------------\n"));
668 
669  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%x\n", "fileptr", sion_filedesc->fileptr));
670  if(sion_filedesc->fileptr) {
671  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d %s\n", "fileptr->flags", sion_filedesc->fileptr->flags,_sion_get_fileptr_desc(sion_filedesc->fileptr)));
672  }
673  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%s\n", "fname", sion_filedesc->fname));
674  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "sid", sion_filedesc->sid));
675  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "rank", sion_filedesc->rank));
676  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "globalrank", sion_filedesc->globalrank));
677  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "ntasks", sion_filedesc->ntasks));
678  if(sion_filedesc->state==SION_FILESTATE_PAROPEN) DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d (SION_FILESTATE_PAROPEN)\n", "state", sion_filedesc->state));
679  else if(sion_filedesc->state==SION_FILESTATE_SEROPEN) DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d (SION_FILESTATE_SEROPEN)\n", "state", sion_filedesc->state));
680  else if(sion_filedesc->state==SION_FILESTATE_SEROPENRANK) DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d (SION_FILESTATE_SEROPENRANK)\n", "state", sion_filedesc->state));
681  else if(sion_filedesc->state==SION_FILESTATE_SEROPENMASTER)DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d (SION_FILESTATE_SEROPENMASTER)\n", "state", sion_filedesc->state));
682  else if(sion_filedesc->state==SION_FILESTATE_CLOSE) DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d (SION_FILESTATE_CLOSE)\n", "state", sion_filedesc->state));
683  else if(sion_filedesc->state==SION_FILESTATE_PAROPENMAPPED) DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d (SION_FILESTATE_PAROPENMAPPED)\n", "state", sion_filedesc->state));
684  else if(sion_filedesc->state==SION_FILESTATE_PAROPENMAPPEDMANAGED)DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d (SION_FILESTATE_PAROPENMAPPEDMANAGED)\n", "state", sion_filedesc->state));
685  else if(sion_filedesc->state==SION_FILESTATE_PAROPENMAPPEDMASTER) DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d (SION_FILESTATE_PAROPENMAPPEDMASTER)\n", "state", sion_filedesc->state));
686  else DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d (unknown)\n", "state", sion_filedesc->state));
687  if(sion_filedesc->mode==SION_FILEMODE_WRITE) DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d (SION_FILEMODE_WRITE)\n", "mode", sion_filedesc->mode));
688  else if(sion_filedesc->mode==SION_FILEMODE_READ) DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d (SION_FILEMODE_READ)\n", "mode", sion_filedesc->mode));
689  else DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d (unknown)\n", "mode", sion_filedesc->mode));
690  if(sion_filedesc->dup_mode==SION_DESCSTATE_ORIG) DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d (SION_DESCSTATE_ORIG)\n", "dup", sion_filedesc->dup_mode));
691  else if(sion_filedesc->dup_mode==SION_DESCSTATE_DUP) DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d (SION_DESCSTATE_DUP)\n", "dup", sion_filedesc->dup_mode));
692  else if(sion_filedesc->dup_mode==SION_DESCSTATE_DUP_SEL_RANK) DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d (SION_DESCSTATE_DUP_SEL_RANK)\n", "dup", sion_filedesc->dup_mode));
693  else if(sion_filedesc->dup_mode==SION_DESCSTATE_DUP_SEL_RANK_KEY) DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d (SION_DESCSTATE_DUP_SEL_RANK_KEY)\n", "dup", sion_filedesc->dup_mode));
694  else DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d (unknown)\n", "dup", sion_filedesc->dup_mode));
695  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "endianness", sion_filedesc->endianness));
696  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "swapbytes", sion_filedesc->swapbytes));
697  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "fileversion", sion_filedesc->fileversion));
698  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "filesionversion", sion_filedesc->filesionversion));
699  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "filesionpatchlevel", sion_filedesc->filesionpatchlevel));
700  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "fsblksize", sion_filedesc->fsblksize));
701  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "lastchunknr", sion_filedesc->lastchunknr));
702  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "maxchunks", sion_filedesc->maxchunks));
703  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "maxusedchunks", sion_filedesc->maxusedchunks));
704 
705  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "currentpos", sion_filedesc->currentpos));
706  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "currentblocknr", sion_filedesc->currentblocknr));
707 
708  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%lld\n", "startpos", sion_filedesc->startpos));
709  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%lld\n", "chunksize", sion_filedesc->chunksize));
710  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%lld\n", "chunksize_req", sion_filedesc->chunksize_req));
711  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%lld\n", "globalskip", sion_filedesc->globalskip));
712  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%lld\n", "end_of_header", sion_filedesc->end_of_header));
713  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%lld\n", "start_of_varheader", sion_filedesc->start_of_varheader));
714  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%lld\n", "start_of_data", sion_filedesc->start_of_data));
715 
716  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "nfiles", sion_filedesc->nfiles));
717  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "filenumber", sion_filedesc->filenumber));
718  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=\"%s\"\n", "prefix", sion_filedesc->prefix));
719  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%x\n", "fpbuffer", sion_filedesc->fpbuffer));
720  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "fpbuffer_size", sion_filedesc->fpbuffer_size));
721  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%x\n", "buffer", sion_filedesc->buffer));
722  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "buffer_size", sion_filedesc->buffer_size));
723  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "buffer_ptr", sion_filedesc->buffer_ptr));
724 
725  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "compress", sion_filedesc->compress));
726 
727  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "usecache", sion_filedesc->usecache));
728  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "cachesize", sion_filedesc->cachesize));
729 
730  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "usecoll", sion_filedesc->usecoll));
731  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "collsize", sion_filedesc->collsize));
732  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "collector", sion_filedesc->collector));
733  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "colldebug", sion_filedesc->colldebug));
734  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "collcmdused", sion_filedesc->collcmdused));
735  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "collmergemode", sion_filedesc->collmergemode));
736  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "collmsa", sion_filedesc->collmsa));
737  if(sion_filedesc->coll_capability==SION_CAPABILITY_FULL) DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%s\n", "coll_capability", "FULL"));
738  if(sion_filedesc->coll_capability==SION_CAPABILITY_ONLY_SENDER) DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%s\n", "coll_capability", "ONLY_SENDER"));
739  if(sion_filedesc->coll_capability==SION_CAPABILITY_NONE) DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%s\n", "coll_capability", "NONE"));
740 
741  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "fileptr_exported", sion_filedesc->fileptr_exported));
742 
743  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "usebuddy", sion_filedesc->usebuddy));
744  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "buddylevel", sion_filedesc->buddylevel));
745  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "buddynr", sion_filedesc->buddynr));
746  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%x\n", "buddies", sion_filedesc->buddies));
747 
748  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "usehints", sion_filedesc->usehints));
749  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "hinttype", sion_filedesc->hinttype));
750 
751 
752  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "lrank", sion_filedesc->lrank));
753  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "nlocaltasksinfile", sion_filedesc->nlocaltasksinfile));
754  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "ntotaltasksinfile", sion_filedesc->ntotaltasksinfile));
755  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%d\n", "filemanagedbytask", sion_filedesc->filemanagedbytask));
756 
757 
758  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%x\n", "dataptr", sion_filedesc->dataptr));
759 
760  if(sion_filedesc->keyvalmode==SION_KEYVAL_NONE) DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%s\n", "keyvalmode", "NONE"));
761  if(sion_filedesc->keyvalmode==SION_KEYVAL_INLINE) DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%s\n", "keyvalmode", "INLINE"));
762  if(sion_filedesc->keyvalmode==SION_KEYVAL_UNKNOWN) DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%s\n", "keyvalmode", "UNKNOWN"));
763  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%x\n", "keyvalptr", sion_filedesc->keyvalptr));
764  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s=%x\n", "all_keyvalptr", sion_filedesc->all_keyvalptr));
765 
766  /* if (sion_filedesc->nfiles > 1) */
767  /* for(i=0;i<sion_filedesc->nfiles;i++) */
768  /* DPRINTFP(( level,desc,sion_filedesc->rank,"D: file[%d]=%s\n", i, sion_filedesc->files[i])); */
769 
770 
771  if(sion_filedesc->blocksizes !=NULL) {
772  int maxprintblocks=sion_filedesc->lastchunknr;
773  if (maxprintblocks>20) maxprintblocks=20;
774  for (i = 0; i <= maxprintblocks; i++) {
775  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s[%4d]=%lld\n", "blocksizes", i, sion_filedesc->blocksizes[i]));
776  }
777  if(maxprintblocks<sion_filedesc->lastchunknr) {
778  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s[....]=...\n", "blocksizes"));
779  }
780 
781  }
782 
783  if( (sion_filedesc->state==SION_FILESTATE_SEROPENMASTER) || (sion_filedesc->state==SION_FILESTATE_PAROPENMAPPEDMASTER) ) {
784  for (i = 0; i < sion_filedesc->nfiles; i++) {
785  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s[%4d]=%s\n", "file:", i, sion_filedesc->multifiles[i]->fname));
786  }
787  }
788 
789  if (flag&_SION_DEBUG_PRINT_ALL) {
790 
791  if(sion_filedesc->all_chunksizes !=NULL) {
792  for (i = 0; i < sion_filedesc->ntasks; i++) {
793  DPRINTFP((2048, desc, sion_filedesc->rank, "D: %-20s[%4d]=%lld\n", "all_chunksizes", i, sion_filedesc->all_chunksizes[i]));
794  }
795  }
796 
797  if(sion_filedesc->all_globalranks !=NULL) {
798  for (i = 0; i < sion_filedesc->ntasks; i++) {
799  DPRINTFP((2048, desc, sion_filedesc->rank, "D: %-20s[%4d]=%lld\n", "all_globalranks", i, sion_filedesc->all_globalranks[i]));
800  }
801  }
802 
803  if(sion_filedesc->all_localranks !=NULL) {
804  for (i = 0; i < sion_filedesc->ntasks; i++) {
805  DPRINTFP((2048, desc, sion_filedesc->rank, "D: %-20s[%4d]=%lld\n", "all_localranks", i, sion_filedesc->all_localranks[i]));
806  }
807  }
808 
809  if(sion_filedesc->all_startpointers !=NULL) {
810  for (i = 0; i < sion_filedesc->ntasks; i++) {
811  DPRINTFP((2048, desc, sion_filedesc->rank, "D: %-20s[%4d]=%lld\n", "all_startpointers", i, sion_filedesc->all_startpointers[i]));
812  }
813  }
814 
815  if(sion_filedesc->all_currentpos !=NULL) {
816  for (i = 0; i < sion_filedesc->ntasks; i++) {
817  DPRINTFP((2048, desc, sion_filedesc->rank, "D: %-20s[%4d]=%lld\n", "all_currentpos", i, sion_filedesc->all_currentpos[i]));
818  }
819  }
820 
821  if(sion_filedesc->all_currentblocknr !=NULL) {
822  for (i = 0; i < sion_filedesc->ntasks; i++) {
823  DPRINTFP((2048, desc, sion_filedesc->rank, "D: %-20s[%4d]=%lld\n", "all_currentblocknr", i, sion_filedesc->all_currentblocknr[i]));
824  }
825  }
826 
827  if(sion_filedesc->all_blockcount !=NULL) {
828  for (i = 0; i < sion_filedesc->ntasks; i++) {
829  DPRINTFP((2048, desc, sion_filedesc->rank, "D: %-20s[%4d]=%lld\n", "all_blockcount", i, sion_filedesc->all_blockcount[i]));
830  }
831  }
832 
833  if((sion_filedesc->all_blocksizes != NULL) && (sion_filedesc->all_blockcount != NULL)) {
834  for (i = 0; i < sion_filedesc->ntasks; i++) {
835  int b;
836  int maxprintblocks=sion_filedesc->all_blockcount[i];
837  if (maxprintblocks>20) maxprintblocks=20;
838  for (b = 0; b < maxprintblocks ; b++) {
839  DPRINTFP((2048, desc, sion_filedesc->rank, "D: %-20s[%4d][%d]=%lld\n", "all_blocksizes", i, b,
840  sion_filedesc->all_blocksizes[b*sion_filedesc->ntasks+i]));
841  }
842  if(maxprintblocks<sion_filedesc->all_blockcount[i]) {
843  DPRINTFP((level, desc, sion_filedesc->rank, "D: %-20s[%4d][..]=...\n", "all_blocksizes", i));
844  }
845  }
846  }
847  }
848 
849  if( (sion_filedesc->state==SION_FILESTATE_SEROPENMASTER) || (sion_filedesc->state==SION_FILESTATE_PAROPENMAPPEDMASTER) ) {
850  if (flag&_SION_DEBUG_PRINT_RECURSIVE) {
851  for (i = 0; i < sion_filedesc->nfiles; i++) {
852  DPRINTFP((level, desc, sion_filedesc->rank, "\n"));
853  DPRINTFP((level, desc, sion_filedesc->rank, "*** DUMP of multifile[%d] ***\n",i));
854  _sion_print_filedesc(sion_filedesc->multifiles[i], level, desc, flag&~(_SION_DEBUG_PRINT_RECURSIVE));
855  }
856  }
857  }
858 
859  return (rc);
860 }
861 #undef DFUNCTION
862 
863 #define DFUNCTION "_sion_get_size_of_filedesc"
870 int _sion_get_size_of_filedesc(_sion_filedesc *sion_filedesc, int *numbytes, int *numfds)
871 {
872  int rc=SION_SUCCESS;
873  int bytes=0, fds=0, help_bytes, help_fds, i;
874 
875  if(sion_filedesc==NULL) return(bytes);
876 
877  DPRINTFP((2, DFUNCTION, -1, "start sid=%d nfiles=%d ntasks=%d maxchunks=%d mapping_size=%d\n", sion_filedesc->sid,
878  sion_filedesc->nfiles,sion_filedesc->ntasks,sion_filedesc->maxchunks,sion_filedesc->mapping_size));
879 
880  help_bytes=sizeof(_sion_filedesc);
881  DPRINTFP((512, DFUNCTION, -1, " sizeof(sion_filedesc)= %5d\n", help_bytes));
882  bytes+=help_bytes;
883 
884  if( (sion_filedesc->blocksizes!=NULL) ) {
885  help_bytes=sion_filedesc->maxchunks*sizeof(sion_filedesc->blocksizes[0]);
886  DPRINTFP((512, DFUNCTION, -1, " sizeof blocksizes= %5d\n", help_bytes));
887  bytes+=help_bytes;
888  }
889 
890  if( (sion_filedesc->all_chunksizes!=NULL) ) {
891  help_bytes=sion_filedesc->ntasks*sizeof(sion_filedesc->all_chunksizes[0]);
892  DPRINTFP((512, DFUNCTION, -1, " sizeof all_chunksizes= %5d\n", help_bytes));
893  bytes+=help_bytes;
894  }
895 
896  if( (sion_filedesc->all_globalranks!=NULL) ) {
897  help_bytes=sion_filedesc->ntasks*sizeof(sion_filedesc->all_globalranks[0]);
898  DPRINTFP((512, DFUNCTION, -1, " sizeof all_globalranks= %5d\n", help_bytes));
899  bytes+=help_bytes;
900  }
901 
902  if( (sion_filedesc->state!=SION_FILESTATE_SEROPENMASTER) && (sion_filedesc->state!=SION_FILESTATE_PAROPENMAPPEDMASTER) ) {
903  if(sion_filedesc->fileptr!=NULL) {
904  fds++;
905  }
906  }
907 
908  if( (sion_filedesc->all_localranks!=NULL) ) {
909  help_bytes=sion_filedesc->ntasks*sizeof(sion_filedesc->all_localranks[0]);
910  DPRINTFP((512, DFUNCTION, -1, " sizeof all_localranks= %5d\n", help_bytes));
911  bytes+=help_bytes;
912  }
913 
914  if( (sion_filedesc->all_startpointers!=NULL) ) {
915  help_bytes=sion_filedesc->ntasks*sizeof(sion_filedesc->all_startpointers[0]);
916  DPRINTFP((512, DFUNCTION, -1, " sizeof all_startpointers= %5d\n", help_bytes));
917  bytes+=help_bytes;
918  }
919 
920  if( (sion_filedesc->all_currentpos!=NULL) ) {
921  help_bytes=sion_filedesc->ntasks*sizeof(sion_filedesc->all_currentpos[0]);
922  DPRINTFP((512, DFUNCTION, -1, " sizeof all_currentpos= %5d\n", help_bytes));
923  bytes+=help_bytes;
924  }
925 
926  if( (sion_filedesc->all_currentblocknr!=NULL) ) {
927  help_bytes=sion_filedesc->ntasks*sizeof(sion_filedesc->all_currentblocknr[0]);
928  DPRINTFP((512, DFUNCTION, -1, " sizeof all_currentblocknr= %5d\n", help_bytes));
929  bytes+=help_bytes;
930  }
931 
932  if( (sion_filedesc->all_coll_collector!=NULL) ) {
933  help_bytes=sion_filedesc->ntasks*sizeof(sion_filedesc->all_coll_collector[0]);
934  DPRINTFP((512, DFUNCTION, -1, " sizeof all_coll_collector= %5d\n", help_bytes));
935  bytes+=help_bytes;
936  }
937 
938  if( (sion_filedesc->all_coll_collsize!=NULL) ) {
939  help_bytes=sion_filedesc->ntasks*sizeof(sion_filedesc->all_coll_collsize[0]);
940  DPRINTFP((512, DFUNCTION, -1, " sizeof all_coll_collsize= %5d\n", help_bytes));
941  bytes+=help_bytes;
942  }
943 
944  if( (sion_filedesc->all_blockcount!=NULL) ) {
945  help_bytes=sion_filedesc->ntasks*sizeof(sion_filedesc->all_blockcount[0]);
946  DPRINTFP((512, DFUNCTION, -1, " sizeof all_blockcount= %5d\n", help_bytes));
947  bytes+=help_bytes;
948  }
949 
950  if( (sion_filedesc->all_blocksizes!=NULL) ) {
951  help_bytes=sion_filedesc->maxchunks * sion_filedesc->ntasks*sizeof(sion_filedesc->all_blocksizes[0]);
952  DPRINTFP((512, DFUNCTION, -1, " sizeof all_blocksizes= %5d\n", help_bytes));
953  bytes+=help_bytes;
954  }
955 
956  if( (sion_filedesc->mapping!=NULL) ) {
957  help_bytes=sion_filedesc->mapping_size * 2 * sizeof(sion_filedesc->mapping[0]);
958  DPRINTFP((512, DFUNCTION, -1, " sizeof mapping= %5d\n", help_bytes));
959  bytes+=help_bytes;
960  }
961 
962  if( (sion_filedesc->prefix!=NULL) ) {
963  help_bytes=strlen(sion_filedesc->prefix);
964  DPRINTFP((512, DFUNCTION, -1, " sizeof prefix= %5d\n", help_bytes));
965  bytes+=help_bytes;
966  }
967 
968  if( (sion_filedesc->fpbuffer!=NULL) ) {
969  help_bytes=sion_filedesc->fpbuffer_size;
970  DPRINTFP((512, DFUNCTION, -1, " sizeof fpbuffer= %5d\n", help_bytes));
971  bytes+=help_bytes;
972  }
973 
974  if( (sion_filedesc->buffer!=NULL) ) {
975  help_bytes=sion_filedesc->buffer_size;
976  DPRINTFP((512, DFUNCTION, -1, " sizeof buffer= %5d\n", help_bytes));
977  bytes+=help_bytes;
978  }
979 
980 
981  if( (sion_filedesc->state==SION_FILESTATE_PAROPEN) || (sion_filedesc->state==SION_FILESTATE_SEROPENRANK) ) {
982  if( (sion_filedesc->keyvalptr!=NULL) ) {
983  help_bytes=_sion_keyvalue_keymngr_key_get_sizeof(sion_filedesc->keyvalptr);
984  DPRINTFP((512, DFUNCTION, -1, " sizeof keyvalptr= %5d\n", help_bytes));
985  bytes+=help_bytes;
986  }
987  }
988 
989  if( (sion_filedesc->state==SION_FILESTATE_SEROPEN) || (sion_filedesc->state==SION_FILESTATE_SEROPENMASTER)
991  || (sion_filedesc->state==SION_FILESTATE_PAROPENMAPPED) ) {
992 
993  if( (sion_filedesc->all_keyvalptr!=NULL) ) {
994  for (i = 0; i < sion_filedesc->ntasks; i++) {
995  if(sion_filedesc->all_keyvalptr[i]!=NULL) {
996  help_bytes=_sion_keyvalue_keymngr_key_get_sizeof(sion_filedesc->all_keyvalptr[i]);
997  DPRINTFP((512, DFUNCTION, -1, " sizeof all_keyvalptr[%d]= %5d\n", i, help_bytes));
998  bytes+=help_bytes;
999  }
1000  }
1001  }
1002  }
1003 
1004  if( (sion_filedesc->state==SION_FILESTATE_SEROPENMASTER) || (sion_filedesc->state==SION_FILESTATE_PAROPENMAPPEDMASTER) ) {
1005 
1006  help_bytes=sion_filedesc->nfiles*sizeof(sion_filedesc->multifiles[0]);
1007  DPRINTFP((512, DFUNCTION, -1, " sizeof multifiles= %5d\n", help_bytes));
1008  bytes+=help_bytes;
1009 
1010  for (i = 0; i < sion_filedesc->nfiles; i++) {
1011 
1012  rc=_sion_get_size_of_filedesc(sion_filedesc->multifiles[i], &help_bytes, &help_fds);
1013  DPRINTFP((512, DFUNCTION, -1, " sizeof multifile[%d]= %5d + %1d\n", i, help_bytes, help_fds));
1014  bytes+=help_bytes;
1015  fds+=help_fds;
1016  }
1017  }
1018 
1019  *numbytes=bytes;*numfds=fds;
1020  DPRINTFP((2, DFUNCTION, -1, "leave total_size =%5d + %d fds\n", bytes, fds));
1021 
1022  return(rc);
1023 }
1024 #undef DFUNCTION
1025 
1026 #define DFUNCTION "_sion_dup_filedesc"
1033 {
1034  _sion_filedesc *new_fd=NULL;
1035 
1036  if (sion_filedesc == NULL) {
1037  _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"cannot allocate filedescriptor structure (sion_filedesc), aborting ...\n");
1038  return(NULL);
1039  }
1040  new_fd=_sion_alloc_filedesc();
1041 
1042  new_fd->dup_mode = SION_DESCSTATE_DUP;
1043 
1044  /* values which will not be copied */
1045  new_fd->fileptr = NULL;
1046  new_fd->sid = -1;
1047  new_fd->dataptr = NULL; /* not needed in a dup fd */
1048  new_fd->keyvalptr = NULL; /* not needed in a dup fd */
1049  new_fd->usecoll = 0;
1050  new_fd->maxchunks = -1;
1051 
1052  /* copy scalar values */
1053  new_fd->fname = strdup(sion_filedesc->fname);
1054  new_fd->rank = sion_filedesc->rank;
1055  new_fd->lrank = sion_filedesc->lrank;
1056  new_fd->globalrank = sion_filedesc->globalrank;
1057 
1058  new_fd->ntasks = sion_filedesc->ntasks;
1059  new_fd->state = sion_filedesc->state;
1060  new_fd->mode = sion_filedesc->mode;
1061  new_fd->endianness = sion_filedesc->endianness;
1062  new_fd->swapbytes = sion_filedesc->swapbytes;
1063  new_fd->fileversion = sion_filedesc->fileversion;
1064  new_fd->filesionversion = sion_filedesc->filesionversion;
1065  new_fd->filesionpatchlevel = sion_filedesc->filesionpatchlevel;
1066  new_fd->fsblksize = sion_filedesc->fsblksize;
1067  new_fd->lastchunknr = sion_filedesc->lastchunknr;
1068  new_fd->maxusedchunks = sion_filedesc->maxusedchunks;
1069  new_fd->startpos = sion_filedesc->startpos;
1070  new_fd->chunksize = sion_filedesc->chunksize;
1071  new_fd->chunksize_req = sion_filedesc->chunksize_req;
1072 
1073  new_fd->globalskip = sion_filedesc->globalskip;
1074  new_fd->end_of_header = sion_filedesc->end_of_header;
1075  new_fd->start_of_varheader = sion_filedesc->start_of_varheader;
1076  new_fd->start_of_data = sion_filedesc->start_of_data;
1077 
1078  new_fd->currentpos = sion_filedesc->currentpos;
1079  new_fd->currentblocknr = sion_filedesc->currentblocknr;
1080  new_fd->debug = sion_filedesc->debug;
1081 
1082  new_fd->nfiles = sion_filedesc->nfiles;
1083  new_fd->filenumber = sion_filedesc->filenumber;
1084  new_fd->mapping_size = sion_filedesc->mapping_size;
1085 
1086  new_fd->ntotaltasksinfile = sion_filedesc->ntotaltasksinfile;
1087  new_fd->nlocaltasksinfile = sion_filedesc->nlocaltasksinfile;
1088  new_fd->filemanagedbytask = sion_filedesc->filemanagedbytask;
1089 
1090  new_fd->ntasks = sion_filedesc->ntasks;
1091  new_fd->flag1 = sion_filedesc->flag1;
1092  new_fd->flag2 = sion_filedesc->flag2;
1093  new_fd->fpbuffer_size = sion_filedesc->fpbuffer_size;
1094 
1095  new_fd->usecache = sion_filedesc->usecache;
1096  new_fd->cachesize = sion_filedesc->cachesize;
1097  new_fd->cacheid = sion_filedesc->cacheid;
1098  strcpy(new_fd->cachefn,sion_filedesc->cachefn);
1099 
1100  new_fd->cachemode = sion_filedesc->cachemode;
1101  new_fd->usebuffer = sion_filedesc->usebuffer;
1102  new_fd->buffer_size = sion_filedesc->buffer_size;
1103  new_fd->buffer_ptr = sion_filedesc->buffer_ptr;
1104  new_fd->compress = sion_filedesc->compress;
1105  new_fd->keyvalmode = sion_filedesc->keyvalmode;
1106 
1107  new_fd->collsize = sion_filedesc->collsize;
1108  new_fd->coll_capability = sion_filedesc->coll_capability;
1109  new_fd->collector = sion_filedesc->collector;
1110  new_fd->colldebug = sion_filedesc->colldebug;
1111  new_fd->collcmdused = sion_filedesc->collcmdused;
1112  new_fd->usebuddy = sion_filedesc->usebuddy;
1113  new_fd->buddylevel = sion_filedesc->buddylevel;
1114  new_fd->buddynr = sion_filedesc->buddynr;
1115  new_fd->buddies = sion_filedesc->buddies;
1116  new_fd->usehints = sion_filedesc->usehints;
1117  new_fd->hinttype = sion_filedesc->hinttype;
1118  new_fd->fileptr_exported = sion_filedesc->fileptr_exported;
1119  new_fd->collmergemode = sion_filedesc->collmergemode;
1120  new_fd->collmsa = sion_filedesc->collmsa;
1121 
1122  new_fd->prefix=NULL;
1123  if(sion_filedesc->prefix) new_fd->prefix = strdup(sion_filedesc->prefix);
1124 
1125  new_fd->blocksizes = NULL; /* vector of written bytes in each block for current task */
1126  new_fd->all_chunksizes = NULL; /* only used if sion is opened from a single task for read */
1127  new_fd->all_globalranks = NULL; /* only used if sion is opened from a single task for read */
1128  new_fd->all_localranks = NULL; /* only used if sion is opened in mapped mode */
1129  new_fd->all_startpointers = NULL; /* only used if sion is opened from a single task for read */
1130 
1131  new_fd->all_currentpos = NULL; /* only used if sion is opened from a single task for write */
1132  new_fd->all_currentblocknr = NULL; /* only used if sion is opened from a single task for write */
1133 
1134  new_fd->all_coll_collector = NULL; /* only used on rank 0 if usecoll=1 */
1135  new_fd->all_coll_collsize = NULL; /* only used on rank 0 if usecoll=1 */
1136 
1137  new_fd->all_blockcount = NULL; /* size, only used if sion is opened from a single task for read */
1138  new_fd->all_blocksizes = NULL; /* size*maxchunks, only used if sion is opened from a single task for read */
1139 
1140  new_fd->all_keyvalptr = NULL;
1141 
1142  new_fd->mapping = NULL;
1143  new_fd->multifiles = NULL;
1144 
1145  new_fd->fpbuffer = NULL;
1146  new_fd->cacheptr = NULL;
1147  new_fd->buffer = NULL;
1148 
1149  return (new_fd);
1150 }
1151 #undef DFUNCTION
#define SION_KEYVAL_INLINE
Definition: sion_const.h:81
#define SION_KEYVAL_UNKNOWN
Definition: sion_const.h:84
#define SION_KEYVAL_NONE
Definition: sion_const.h:80
char * _sion_get_fileptr_desc(_sion_fileptr *sion_fileptr)
Definition: sion_file.c:1568
int _sion_alloc_filedesc_block_arrays_only(_sion_filedesc *sion_filedesc)
Allocate memory for the internal sion structure, fields for all chunksizes of all tasks.
int _sion_init_filedesc(_sion_filedesc *sion_filedesc)
Initialize the sion file description.
Definition: sion_filedesc.c:37
int _sion_realloc_filedesc_blocklist(_sion_filedesc *sion_filedesc, sion_int32 maxchunks)
Increase the memory used by the internal sion structure for the blocklist.
int _sion_alloc_filedesc_coll_arrays(_sion_filedesc *sion_filedesc)
Allocate memory for the internal sion arrays.
int _sion_get_size_of_filedesc(_sion_filedesc *sion_filedesc, int *numbytes, int *numfds)
get size of internal data structure sion_filedesc
int _sion_alloc_filedesc_arrays(_sion_filedesc *sion_filedesc)
Allocate memory for the internal sion arrays.
int _sion_print_filedesc(_sion_filedesc *sion_filedesc, int level, char *desc, int flag)
Print the initialized sion file description.
_sion_filedesc * _sion_dup_filedesc(_sion_filedesc *sion_filedesc)
duplicates a filedesc data structure, not copying/reopen active file pointers
int _sion_free_filedesc_arrays(_sion_filedesc *sion_filedesc)
free memory for the internal sion arrays
_sion_filedesc * _sion_alloc_filedesc(void)
Allocates memory for internal sion structure.
int _sion_free_filedesc_coll_arrays(_sion_filedesc *sion_filedesc)
free memory for the internal sion arrays
int _sion_alloc_filedesc_block_arrays(_sion_filedesc *sion_filedesc)
Allocate memory for the internal sion structure, fields for all chunksizes of all tasks.
#define SION_DESCSTATE_ORIG
Definition: sion_filedesc.h:45
#define _SION_FLAG2_NONE
Definition: sion_filedesc.h:22
#define SION_FILESTATE_PAROPENMAPPED
Definition: sion_filedesc.h:34
#define SION_FILEMODE_WRITE
Definition: sion_filedesc.h:38
struct _sion_filedesc_struct _sion_filedesc
SION File Descriptor Alias.
Definition: sion_filedesc.h:64
#define SION_FILESTATE_PAROPENMAPPEDMANAGED
Definition: sion_filedesc.h:33
#define SION_DESCSTATE_DUP_SEL_RANK
Definition: sion_filedesc.h:47
#define SION_FILEMODE_READ
Definition: sion_filedesc.h:37
#define SION_CACHE_UNKNOWN
Definition: sion_filedesc.h:42
#define SION_FILESTATE_UNKNOWN
Definition: sion_filedesc.h:27
#define SION_DESCSTATE_DUP
Definition: sion_filedesc.h:46
#define SION_FILESTATE_SEROPENRANK
Definition: sion_filedesc.h:30
#define SION_CAPABILITY_NONE
Definition: sion_filedesc.h:56
#define SION_FILESTATE_PAROPEN
Definition: sion_filedesc.h:28
#define SION_CAPABILITY_ONLY_SENDER
Definition: sion_filedesc.h:55
#define SION_FILESTATE_SEROPENMASTER
Definition: sion_filedesc.h:31
#define SION_FILESTATE_CLOSE
Definition: sion_filedesc.h:35
#define SION_DESCSTATE_DUP_SEL_RANK_KEY
Definition: sion_filedesc.h:48
#define _SION_FLAG1_NONE
Definition: sion_filedesc.h:21
#define SION_CACHE_FNLEN
Definition: sion_filedesc.h:43
#define SION_FILESTATE_SEROPEN
Definition: sion_filedesc.h:29
#define SION_FILEMODE_UNKNOWN
Definition: sion_filedesc.h:36
#define SION_HINTS_TYPE_UNKNOWN
Definition: sion_filedesc.h:50
#define SION_CAPABILITY_FULL
Definition: sion_filedesc.h:54
#define SION_FILESTATE_PAROPENMAPPEDMASTER
Definition: sion_filedesc.h:32
Sion File Descriptor Structure.
Definition: sion_filedesc.h:79
sion_int64 * all_localranks
sion_int64 * all_blocksizes
char cachefn[SION_CACHE_FNLEN]
sion_int32 * all_coll_collsize
sion_int32 * all_coll_collector
sion_int32 filesionversion
sion_int32 nlocaltasksinfile
sion_int64 start_of_varheader
sion_int32 filesionpatchlevel
sion_int64 * all_chunksizes
sion_int64 * all_currentpos
sion_int64 * blocksizes
sion_int32 filemanagedbytask
sion_int64 * all_currentblocknr
sion_int32 fileptr_exported
_sion_filedesc ** multifiles
sion_int64 * all_globalranks
sion_int32 ntotaltasksinfile
sion_int32 currentblocknr
Definition: sion_filedesc.h:97
sion_int32 fpbuffer_size
Definition: sion_filedesc.h:88
sion_int32 * all_coll_capability
_sion_fileptr * fileptr
Definition: sion_filedesc.h:82
sion_int32 coll_capability
sion_int64 * all_startpointers
sion_int64 * all_blockcount