SIONlib  1.7.0
Scalable I/O library for parallel access to task-local files
sion_common.c
Go to the documentation of this file.
1 /****************************************************************************
2 ** SIONLIB http://www.fz-juelich.de/jsc/sionlib **
3 *****************************************************************************
4 ** Copyright (c) 2008-2016 **
5 ** Forschungszentrum Juelich, Juelich Supercomputing Centre **
6 ** **
7 ** See the file COPYRIGHT in the package base directory for details **
8 ****************************************************************************/
9 
16 #include <stdlib.h>
17 #include <stdio.h>
18 #include <string.h>
19 #include <time.h>
20 #include <assert.h>
21 
22 #if defined(_BGL)
23 #include <rts.h>
24 #ifndef __USE_FILE_OFFSET64
25 #define __USE_FILE_OFFSET64
26 #endif
27 #endif
28 
29 #include <sys/time.h>
30 
31 
32 #include "sion.h"
33 #include "sion_debug.h"
34 #include "sion_error_handler.h"
35 #include "sion_filedesc.h"
36 #include "sion_tools.h"
37 #include "sion_fd.h"
38 #include "sion_file.h"
39 #include "sion_metadata.h"
40 #include "sion_internal.h"
41 #include "sion_internal_seek.h"
42 #include "sion_hints.h"
43 #include "sion_printts.h"
44 #include "sion_buffer.h"
45 #include "sion_dup.h"
46 #include "sion_lock.h"
47 #include "sion_buddy_common.h"
48 
49 
50 sion_io_stat_t* sion_get_io_info_buddy(int sid, int roles, int flag);
51 
86 int sion_get_locations(int sid,
87  int *ntasks,
88  int *maxchunks,
89  sion_int64 *globalskip,
90  sion_int64 *start_of_varheader,
91  sion_int64 **sion_chunksizes,
92  sion_int64 **sion_globalranks,
93  sion_int64 **sion_blockcount,
94  sion_int64 **sion_blocksizes ) {
95  int rc = SION_SUCCESS;
96  _sion_filedesc *sion_filedesc;
97 #ifdef SION_SERIAL_MASTER
98  _sion_filedesc *help;
99 #endif
100 
101  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
102  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
103  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"invalid sion_filedesc, aborting %d ...\n", sid));
104  }
105  DPRINTFP((1, "sion_get_locations", -1, "enter\n"));
106 
107 #ifdef SION_SERIAL_MASTER
108  if((sion_filedesc->state == SION_FILESTATE_SEROPENMASTER) &&
109  (sion_filedesc->all_blockcount==NULL) ) {
110  int i;
111 
112  /* collect info from sub files */
113  _sion_alloc_filedesc_arrays(sion_filedesc);
115 
116  for (i = 0; i < sion_filedesc->ntasks; i++) {
117  int lfile=sion_filedesc->mapping[i*2+0];
118  int lrank=sion_filedesc->mapping[i*2+1];
119  sion_filedesc->all_chunksizes[i] = sion_filedesc->multifiles[lfile]->all_chunksizes[lrank];
120  sion_filedesc->all_globalranks[i] = sion_filedesc->multifiles[lfile]->all_globalranks[lrank];
121  sion_filedesc->all_blockcount[i] = sion_filedesc->multifiles[lfile]->all_blockcount[lrank];
122  }
123  for (i = 0; i < sion_filedesc->ntasks; i++) {
124  int lfile=sion_filedesc->mapping[i*2+0];
125  int lrank=sion_filedesc->mapping[i*2+1];
126  int blknum;
127  help=sion_filedesc->multifiles[lfile];
128  for (blknum = 0; blknum < sion_filedesc->all_blockcount[i]; blknum++) {
129  sion_filedesc->all_blocksizes[sion_filedesc->ntasks * blknum + i] =
130  help->all_blocksizes[help->ntasks * blknum + lrank];
131  }
132  }
133  }
134 #endif
135 
136  *ntasks = sion_filedesc->ntasks;
137  *maxchunks = sion_filedesc->maxusedchunks;
138  *sion_chunksizes = sion_filedesc->all_chunksizes;
139  *sion_globalranks = sion_filedesc->all_globalranks;
140  *sion_blockcount = sion_filedesc->all_blockcount;
141  *sion_blocksizes = sion_filedesc->all_blocksizes;
142  *globalskip = sion_filedesc->globalskip;
143  *start_of_varheader = sion_filedesc->start_of_varheader;
144 
145  DPRINTFP((1, "sion_get_locations", -1, "leave\n"));
146 
147  return (rc);
148 }
149 
150 int _sion_close_sid(int sid)
151 {
152  int rc = SION_SUCCESS;
153  _sion_filedesc *sion_filedesc;
154 
155  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
156  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
157  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"_sion_close: invalid sion_filedesc, aborting %d ...\n", sid));
158  }
159  rc=_sion_close(sion_filedesc);
160 
161  if(rc==SION_SUCCESS) {
162  _sion_freevcd(sid);
163  _sion_free_filedesc(sion_filedesc);
164  }
165 
166  return(rc);
167 
168 }
169 
187 int sion_get_current_location(int sid, int *currentchunknr, sion_int64 *currentpos, int *maxchunks, sion_int64 **chunksizes)
188 {
189  int rc = SION_SUCCESS;
190  _sion_filedesc *sion_filedesc;
191 
192  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
193  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
194  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"invalid sion_filedesc, aborting %d ...\n", sid));
195  }
196  DPRINTFP((1, "sion_get_current_location", -1, "enter\n"));
197 
198  *currentchunknr = sion_filedesc->currentblocknr;
199  *currentpos = sion_filedesc->currentpos - (sion_filedesc->startpos + sion_filedesc->currentblocknr * sion_filedesc->globalskip);
200  *maxchunks = sion_filedesc->lastchunknr+1;
201  *chunksizes = sion_filedesc->blocksizes;
202 
203  DPRINTFP((1, "sion_get_current_location", -1, "leave\n"));
204  return (rc);
205 }
206 
221 int sion_get_mapping(int sid,
222  int *mapping_size,
223  sion_int32 **mapping,
224  int *numfiles ) {
225  int rc = SION_SUCCESS;
226  _sion_filedesc *sion_filedesc;
227 
228  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
229  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
230  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"invalid sion_filedesc, aborting %d ...\n", sid));
231  }
232  DPRINTFP((1, "sion_get_mapping", -1, "enter\n"));
233 
234  if(sion_filedesc->mapping_size>0) {
235  *mapping_size=sion_filedesc->mapping_size;
236  *mapping=sion_filedesc->mapping;
237  } else {
238  *mapping_size=-1;
239  }
240  *numfiles=sion_filedesc->nfiles;
241 
242  DPRINTFP((1, "sion_get_mapping", -1, "leave (mapping_size=%d)\n",*mapping_size));
243 
244  return (rc);
245 }
246 
256 {
257  _sion_filedesc *sion_filedesc;
258 
259  DPRINTFP((1, "sion_get_file_endianness", -1, "enter (sid=%d)\n",sid));
260 
261  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
262  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
263  return(_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,"invalid sion_filedesc, aborting %d ...\n", sid));
264  }
265 
266  DPRINTFP((1, "sion_get_file_endianness", -1, "leave (sid=%d)\n",sid));
267  /* return endianness of user data */
268  return ((sion_filedesc->endianness >> 8) & 1);
269 }
270 
280 {
281  int swap_needed = 0;
282 
283  DPRINTFP((1, "sion_endianness_swap_needed", -1, "enter (sid=%d)\n",sid));
284 
285  swap_needed = (sion_get_file_endianness(sid) != sion_get_endianness());
286 
287  DPRINTFP((1, "sion_endianness_swap_needed", -1, "leave (swap_needed=%d)\n",
288  swap_needed));
289 
290  return swap_needed;
291 }
292 
310  int *ntasks,
311  sion_int64 **sion_currentpos,
312  sion_int64 **sion_currentblocknr)
313 {
314  int rc = SION_SUCCESS;
315  _sion_filedesc *sion_filedesc;
316 
317  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
318  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
319  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"invalid sion_filedesc, aborting %d ...\n", sid));
320  }
321  DPRINTFP((1, "sion_get_current_locations", -1, "enter\n"));
322 
323  *ntasks = sion_filedesc->ntasks;
324  *sion_currentpos = sion_filedesc->all_currentpos;
325  *sion_currentblocknr = sion_filedesc->all_currentblocknr;
326 
327  DPRINTFP((1, "sion_get_current_locations", -1, "leave\n"));
328  return (rc);
329 }
330 
331 int sion_get_number_of_files(int sid)
332 {
333  _sion_filedesc *sion_filedesc;
334 
335  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
336  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
337  return(_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,"invalid sion_filedesc, aborting %d ...\n", sid));
338  }
339 
340  return (sion_filedesc->nfiles);
341 }
342 
343 int sion_get_filenumber(int sid)
344 {
345  _sion_filedesc *sion_filedesc;
346 
347  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
348  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
349  return(_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,"invalid sion_filedesc, aborting %d ...\n", sid));
350  }
351 
352  return (sion_filedesc->filenumber);
353 }
354 
355 int sion_is_serial_opened(int sid)
356 {
357  _sion_filedesc *sion_filedesc;
358 
359  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
360  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
361  return(_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,"invalid sion_filedesc, aborting %d ...\n", sid));
362  }
363 
364  return (sion_filedesc->state == SION_FILESTATE_SEROPEN
365  || sion_filedesc->state == SION_FILESTATE_SEROPENRANK
366  || sion_filedesc->state == SION_FILESTATE_SEROPENMASTER);
367 }
368 
369 int sion_using_hints(int sid)
370 {
371  _sion_filedesc *sion_filedesc;
372 
373  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
374  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
375  return(_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,"invalid sion_filedesc, aborting %d ...\n", sid));
376  }
377 
378  return (sion_filedesc->usehints);
379 }
380 
381 sion_int64 sion_get_bytes_written(int sid)
382 {
383  _sion_filedesc *sion_filedesc;
384  sion_int64 bytes=SION_SIZE_NOT_VALID;
385 
386  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
387  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
388  return(_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,"invalid sion_filedesc, aborting %d ...\n", sid));
389  }
390 
391  if (sion_filedesc->mode == SION_FILEMODE_WRITE) {
392  int i;
393  if (sion_filedesc->usebuffer) {
394  _sion_buffer_flush(sion_filedesc);
395  }
396  _sion_flush_block(sion_filedesc);
397  bytes=0;
398  for(i=0;i<=sion_filedesc->lastchunknr;i++) bytes+=sion_filedesc->blocksizes[i];
399  }
400 
401  return (bytes);
402 }
403 
404 sion_int64 sion_get_bytes_read(int sid)
405 {
406  _sion_filedesc *sion_filedesc;
407  sion_int64 bytes=SION_SIZE_NOT_VALID;
408 
409  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
410  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
411  return(_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,"invalid sion_filedesc, aborting %d ...\n", sid));
412  }
413 
414  if (sion_filedesc->mode == SION_FILEMODE_READ) {
415  int i;
416  _sion_file_purge(sion_filedesc->fileptr);
417  sion_filedesc->currentpos = _sion_file_get_position(sion_filedesc->fileptr);
418 
419  bytes=0;
420  for(i=0;i<sion_filedesc->currentblocknr;i++) bytes+=sion_filedesc->blocksizes[i];
421  /* current chunk */
422  bytes+=sion_filedesc->currentpos - (sion_filedesc->startpos + sion_filedesc->currentblocknr * sion_filedesc->globalskip);
423  }
424 
425  return (bytes);
426 }
427 
428 /* return list of filenames created and the size of their payload, and the task role on this file */
429 sion_io_stat_t* sion_get_io_info(int sid) {
430 
431  return(sion_get_io_info_by_spec(sid,SION_ROLE_COLLECTOR|SION_ROLE_WRITER|SION_ROLE_NOWRITER,SION_GET_IO_INFO_FLAG_NONE));
432 
433 }
434 
435 /* return list of filenames created and the size of their payload, and the task role on this file */
436 sion_io_stat_t* sion_get_io_info_by_spec(int sid, int roles, int flag) {
437  _sion_filedesc *sion_filedesc;
438  sion_io_stat_t *p=NULL;
439 
440  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
441  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
442  _sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,"invalid sion_filedesc, aborting %d ...\n", sid);
443  return(NULL);
444  }
445 
446  /* branch to buddy CP */
447  if(sion_filedesc->usebuddy) {
448  p=sion_get_io_info_buddy(sid,roles,flag);
449  }
450 
451  return (p);
452 }
453 
454 int sion_free_io_info(sion_io_stat_t *p) {
455  return (_sion_free_io_info(p));
456 }
457 
458 
472 size_t sion_fwrite(const void *data, size_t size, size_t nitems, int sid)
473 {
474  sion_int64 bytes_to_write, bbytes;
475  _sion_filedesc *sion_filedesc;
476  size_t rc=0, frc;
477  void *bdata;
478 
479  DPRINTFP((1, "sion_fwrite", -1, "enter size=%ld nitems=%ld\n",(long) size, (long) nitems));
480 
481  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
482  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
483  return(_sion_errorprint(SION_ANSI_SIZE_NOT_VALID,_SION_ERROR_RETURN,"invalid sion_filedesc, aborting %d ...\n", sid));
484  }
485 
486  _sion_check_on_collective_mode(sion_filedesc);
487 
488  bytes_to_write=size*nitems;
489 
490  /* buffering? */
491  if(sion_filedesc->usebuffer) {
492 
493  /* create a new block if needed and check size of input */
494  if(!sion_ensure_free_space(sid,bytes_to_write)) {
495  return(_sion_errorprint_on_rank(SION_ANSI_SIZE_NOT_VALID,_SION_ERROR_RETURN,sion_filedesc->rank,
496  "could not ensure free space for this buffered block of size %d, returning sid=%d ...",
497  (int) bytes_to_write, sid));
498  }
499 
500  char *data_ptr=(void *) data;
501  sion_int64 bytes_left = sion_filedesc->chunksize -
502  sion_filedesc->blocksizes[sion_filedesc->currentblocknr];
503  bbytes = sion_filedesc->buffer_ptr;
504 
505  /* check for enough space in current block */
506  if (bbytes + bytes_to_write > bytes_left) {
507  /* not enough space for buffer + bytes_to_write => flush first */
508  _sion_buffer_get_data_ptr(sion_filedesc,&bdata,&bbytes);
509  if(sion_ensure_free_space(sid,bbytes)) {
510  frc = _sion_file_write(bdata, bbytes, sion_filedesc->fileptr);
511  if(frc != bbytes) {
512  return(_sion_errorprint_on_rank(SION_ANSI_SIZE_NOT_VALID,_SION_ERROR_RETURN,sion_filedesc->rank,
513  "could not write data (%d bytes) to file (sid=%d) ...", (int) bbytes, sid));
514  }
515  } else {
516  return(_sion_errorprint_on_rank(SION_ANSI_SIZE_NOT_VALID,_SION_ERROR_RETURN,sion_filedesc->rank,
517  "could not ensure free space for this buffered block of size %d, returning sid=%d ...",
518  (int) bbytes, sid));
519  }
520  /* increase current position */
521  sion_filedesc->currentpos+=bbytes;
522  }
523  /* buffer data */
524  sion_int64 bytes_buffered=_sion_buffer_push(sion_filedesc,data_ptr,bytes_to_write);
525  bytes_to_write-=bytes_buffered;
526  data_ptr+=bytes_buffered;
527 
528  while(bytes_to_write>0) {
529  /* flush filled buffer to file, not all data could be stored */
530  _sion_buffer_get_data_ptr(sion_filedesc,&bdata,&bbytes);
531  if(sion_ensure_free_space(sid,bbytes)) {
532  frc = _sion_file_write(bdata, bbytes, sion_filedesc->fileptr);
533  if(frc != bbytes) {
534  return(_sion_errorprint_on_rank(SION_ANSI_SIZE_NOT_VALID,_SION_ERROR_RETURN,sion_filedesc->rank,
535  "could not write data (%d bytes) to file (sid=%d) ...", (int) bbytes, sid));
536  }
537  } else {
538  return(_sion_errorprint_on_rank(SION_ANSI_SIZE_NOT_VALID,_SION_ERROR_RETURN,sion_filedesc->rank,
539  "could not ensure free space for this buffered block of size %d, returning sid=%d ...",
540  (int) bbytes, sid));
541  }
542  /* increase current position */
543  sion_filedesc->currentpos+=bbytes;
544 
545  /* next try to push data into buffer */
546  bytes_buffered=_sion_buffer_push(sion_filedesc,data_ptr,bytes_to_write);
547  bytes_to_write-=bytes_buffered;
548  data_ptr+=bytes_buffered;
549  }
550  /* reset value since it will be used later */
551  bytes_to_write=size*nitems;
552  /* return code: bytes stored */
553  rc=(size_t) (size ? bytes_to_write / size : 0);
554 
555  } else {
556  /* normal write */
557  if(sion_ensure_free_space(sid,bytes_to_write)) {
558  frc = _sion_file_write(data, bytes_to_write, sion_filedesc->fileptr);
559  if(frc != bytes_to_write) {
560  return(_sion_errorprint_on_rank(SION_ANSI_SIZE_NOT_VALID,_SION_ERROR_RETURN,sion_filedesc->rank,
561  "could not write data (%d bytes) to file (frc=%d sid=%d) ...", (int) bytes_to_write, (int) frc, sid));
562  }
563 
564  rc=(size_t) (size ? bytes_to_write / size : 0);
565 
566  } else {
567  return(_sion_errorprint_on_rank(SION_ANSI_SIZE_NOT_VALID,_SION_ERROR_RETURN,sion_filedesc->rank,"could not ensure free space for this block, returning %d ...", sid));
568  }
569  /* increase current position */
570  sion_filedesc->currentpos+=bytes_to_write;
571  }
572 
573  DPRINTFP((1, "sion_fwrite", -1, "leave rc=%ld\n",(long) rc));
574  return(rc);
575 }
576 
591 size_t sion_fread( void *data, size_t size, size_t nitems, int sid) {
592  _sion_filedesc *sion_filedesc;
593  sion_int64 bytes, bread, bytes_left;
594 
595  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
596  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
597  return(_sion_errorprint(SION_ANSI_SIZE_NOT_VALID,_SION_ERROR_RETURN,"invalid sion_filedesc, aborting %d ...\n", sid));
598  }
599  if (!data) {
600  /* FIXME: replace SION_ANSI_SIZE_NOT_VALID? */
601  return(_sion_errorprint(SION_ANSI_SIZE_NOT_VALID,_SION_ERROR_RETURN,"invalid pointer, aborting %d ...\n", data));
602  }
603 
604  /* check and update current position */
605  _sion_update_fileposition(sion_filedesc);
606 
607  bytes_left = sion_filedesc->startpos +
608  sion_filedesc->currentblocknr * sion_filedesc->globalskip +
609  sion_filedesc->blocksizes[sion_filedesc->currentblocknr] -
610  sion_filedesc->currentpos;
611 
612  DPRINTFP((1, "sion_fread", -1, "enter\n"));
613  DPRINTFP((4, "sion_fread", -1, " parameter size=%ld nitems=%ld\n",(long) size,(long) nitems));
614 
615  _sion_check_on_collective_mode(sion_filedesc);
616 
617  bread=0;
618  bytes=size*nitems;
619 
620  /* Check size. bytes_left == 0 is handled by sion_feof */
621  if((sion_filedesc->chunksize < bytes) || ((bytes_left < bytes) &&
622  (bytes_left != 0))) {
623  /* FIXME: replace SION_ANSI_SIZE_NOT_VALID? */
624  return(_sion_errorprint(SION_ANSI_SIZE_NOT_VALID,_SION_ERROR_RETURN,"not enough bytes left in chunk, aborting (%ld < %ld) ...\n", bytes_left, bytes));
625  }
626 
627  if(!sion_feof(sid)) {
628  bread=_sion_file_read(data,bytes,sion_filedesc->fileptr);
629  DPRINTFP((256, "sion_fread", -1, " _sion_file_read returns %ld\n",(long) bread));
630  }
631  if(bread!=bytes) {
632  return (size_t) (size ? bread / size : 0);
633  }
634 
635  bread = size ? bread / size : 0;
636 
637  /* increase current position */
638  sion_filedesc->currentpos+=bytes;
639 
640  DPRINTFP((4, "sion_fread", -1, " return value %ld\n",(long) bread));
641  DPRINTFP((1, "sion_fread", -1, "leave\n"));
642  return(bread);
643 }
644 
659 int sion_seek(int sid, int rank, int currentblocknr, sion_int64 posinblk)
660 {
661  FILE *fileptr;
662  int rc=0;
663  /* TBD: check if not sion_open and multi file */
664  rc=sion_seek_fp(sid,rank,currentblocknr,posinblk,&fileptr);
665  return(rc);
666 
667 }
668 
682 int sion_seek_fp(int sid, int rank, int currentblocknr, sion_int64 posinblk, FILE **fileptr)
683 {
684  int rc = SION_SUCCESS;
685  _sion_filedesc *sion_filedesc;
686 
687  DPRINTFP((1, "sion_seek_fp", -1, " enter seek with sid=%d\n", sid));
688  assert((_sion_vcdtype(sid) == SION_FILEDESCRIPTOR));
689 
690  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
691  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
692  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"sion_seek: invalid sion_filedesc, aborting %d ...\n", sid));
693  }
694 
695  /* check state */
696  if ((sion_filedesc->mode != SION_FILEMODE_READ) && (sion_filedesc->mode != SION_FILEMODE_WRITE)) {
697  return(_sion_errorprint_on_rank(SION_NOT_SUCCESS,_SION_ERROR_RETURN,sion_filedesc->rank,"sion_seek_fp: unknown file open state !(READ|WRITE), aborting %d ...", sid));
698  }
699  if (sion_filedesc->usebuffer) {
700  _sion_buffer_flush(sion_filedesc);
701  }
702  if ( (sion_filedesc->state != SION_FILESTATE_PAROPEN)
703  && (sion_filedesc->state != SION_FILESTATE_SEROPEN)
704  && (sion_filedesc->state != SION_FILESTATE_SEROPENMASTER)
705  && (sion_filedesc->state != SION_FILESTATE_SEROPENRANK)
706  && (sion_filedesc->state != SION_FILESTATE_PAROPENMAPPEDMASTER)
707  ) {
708  return(_sion_errorprint_on_rank(SION_NOT_SUCCESS,_SION_ERROR_RETURN,sion_filedesc->rank,"sion_seek_fp: unknown file open state !(PAR|SER|SERRANK|MAPPED), aborting %d ...", sid));
709  }
710 
711 
712  if (sion_filedesc->mode == SION_FILEMODE_READ) { /* READ */
713 
714  if (sion_filedesc->state == SION_FILESTATE_SEROPEN) {
715  rc = _sion_seek_on_all_ranks_read(sion_filedesc, rank, currentblocknr, posinblk);
716  }
717  else if (sion_filedesc->state == SION_FILESTATE_SEROPENMASTER) {
718  rc = _sion_seek_on_all_ranks_read_master(sion_filedesc, rank, currentblocknr, posinblk);
719  }
720  else if ((sion_filedesc->state == SION_FILESTATE_SEROPENRANK) ||
721  (sion_filedesc->state == SION_FILESTATE_PAROPEN)) {
722  rc = _sion_seek_on_current_rank_read(sion_filedesc, rank, currentblocknr, posinblk);
723  }
724  else if (sion_filedesc->state == SION_FILESTATE_PAROPENMAPPEDMASTER) {
725  rc = _sion_seek_on_all_ranks_read_mapped(sion_filedesc, rank, currentblocknr, posinblk);
726  }
727  } else { /* WRITE */
728  if (sion_filedesc->state == SION_FILESTATE_SEROPEN) {
729  rc = _sion_seek_on_all_ranks_write(sion_filedesc, rank, currentblocknr, posinblk);
730  }
731  else if (sion_filedesc->state == SION_FILESTATE_SEROPENRANK) {
732  return _sion_errorprint_on_rank(SION_NOT_SUCCESS, _SION_ERROR_RETURN, sion_filedesc->rank, "sion_seek_fp: seek not supported for this type (write, sion_open_rank), aborting ...");
733  }
734  else if (sion_filedesc->state == SION_FILESTATE_PAROPEN) {
735  rc = _sion_seek_on_current_rank_write(sion_filedesc, rank, currentblocknr, posinblk);
736  }
737  else if (sion_filedesc->state == SION_FILESTATE_PAROPENMAPPEDMASTER) {
738  rc = _sion_seek_on_all_ranks_write_mapped(sion_filedesc, rank, currentblocknr, posinblk);
739  }
740 
741  }
742 
743  /* TBD: implement sion_open and sion_seek_fp for multi-files */
744  if(fileptr!=NULL) {
745  if(sion_filedesc->fileptr->flags&SION_FILE_FLAG_ANSI) {
746  *fileptr=sion_filedesc->fileptr->fileptr;
747  sion_filedesc->fileptr_exported=1;
748 
749  } else {
750  *fileptr=NULL;
751  sion_filedesc->fileptr_exported=0;
752  }
753  }
754 
755  DPRINTFP((1, "sion_seek_fp", -1, "leave seek rc=%d\n",rc));
756 
757  return (rc);
758 }
759 
770 int sion_feof(int sid)
771 {
772  int rc = SION_NOT_SUCCESS;
773  sion_int64 maxpos;
774 
775  _sion_filedesc *sion_filedesc;
776  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
777  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
778  return(_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,"sion_feof: invalid sion_filedesc, aborting %d ...\n", sid));
779  }
780 
781  DPRINTFP((8, "sion_feof", -1, "enter feof sid=%d currentpos=%15lld\n", sid, sion_filedesc->currentpos));
782 
783  /* check and update current position */
784  _sion_update_fileposition(sion_filedesc);
785 
786  maxpos = sion_filedesc->startpos
787  + sion_filedesc->currentblocknr * sion_filedesc->globalskip + sion_filedesc->blocksizes[sion_filedesc->currentblocknr];
788 
789  DPRINTFP((16, "sion_feof", -1,
790  " after flush sid=%d currentpos=%15lld maxpos= %lld startpos=%lld curblknr=%d\n",
791  sid, sion_filedesc->currentpos, maxpos, sion_filedesc->startpos, sion_filedesc->currentblocknr));
792 
793  if (sion_filedesc->currentpos < maxpos) {
794  /* end of current block not reached */
795  rc = 0;
796  DPRINTFP((16, "sion_feof", -1, " end of current block %d not reached sid=%d\n",
797  sion_filedesc->currentblocknr, sid));
798  } else {
799  if (sion_filedesc->currentblocknr < sion_filedesc->lastchunknr) {
800 
801  /* apply hint for freeing current chunk */
802  _sion_apply_hints(sion_filedesc,SION_HINTS_FREE_TYPE_CHUNK);
803 
804  /* end of current block reached, skip to next block */
805  sion_filedesc->currentblocknr++;
806  sion_filedesc->currentpos = sion_filedesc->startpos + sion_filedesc->currentblocknr * sion_filedesc->globalskip;
807 
808  /* apply hint for access current (new) chunk */
809  _sion_apply_hints(sion_filedesc,SION_HINTS_ACCESS_TYPE_CHUNK);
810 
811  _sion_file_purge(sion_filedesc->fileptr);
812  _sion_file_set_position(sion_filedesc->fileptr, sion_filedesc->currentpos);
813  rc = SION_NOT_SUCCESS;
814  DPRINTFP((8, "sion_feof", -1,
815  " end of block %d reached, skipping to next %lld -> %lld position=%lld gs=%lld sid=%d\n",
816  sion_filedesc->currentblocknr - 1,
817  sion_filedesc->currentpos, _sion_file_get_position(sion_filedesc->fileptr), sion_filedesc->currentpos, sion_filedesc->globalskip, sid));
818  }
819  else {
820  /* end of last block reached */
821  DPRINTFP((8, "sion_feof", -1, " end of last block %d reached sid=%d\n", sion_filedesc->currentblocknr, sid));
822  rc = SION_SUCCESS;
823  }
824  }
825 
826  DPRINTFP((8, "sion_feof", -1, "leave feof sid=%d currentpos=%15lld rc=%d\n", sid, sion_filedesc->currentpos, rc));
827 
828  return (rc);
829 }
830 
840 sion_int64 sion_bytes_avail_in_block(int sid)
841 {
842  return(sion_bytes_avail_in_chunk(sid));
843 }
844 
855 sion_int64 sion_bytes_avail_in_chunk(int sid)
856 {
857  sion_int64 maxpos;
858  sion_int64 bytes_avail=SION_SIZE_NOT_VALID;
859  _sion_filedesc *sion_filedesc;
860 
861  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
862  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
863  return(_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,"sion_bytes_avail_in_chunk: invalid sion_filedesc, aborting %d ...\n", sid));
864  }
865 
866 
867  _sion_update_fileposition(sion_filedesc);
868 
869  maxpos = sion_filedesc->startpos
870  + sion_filedesc->currentblocknr * sion_filedesc->globalskip + sion_filedesc->blocksizes[sion_filedesc->currentblocknr];
871 
872  bytes_avail = maxpos - sion_filedesc->currentpos;
873 
874  DPRINTFP((8, "sion_bytes_avail_in_chunk", -1,
875  "leave sid=%d rank=%4d currentpos=%lld maxpos= %lld -> bytes to read %lld\n",
876  sid, sion_filedesc->rank, sion_filedesc->currentpos, maxpos, bytes_avail));
877 
878  return (bytes_avail);
879 }
880 
891 sion_int64 sion_get_position(int sid)
892 {
893  _sion_filedesc *sion_filedesc;
894 
895  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
896  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
897  return(_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,"sion_get_position: invalid sion_filedesc, aborting %d ...\n", sid));
898  }
899 
900 
901  _sion_file_flush(sion_filedesc->fileptr);
902 
903  return (_sion_file_get_position(sion_filedesc->fileptr));
904 
905 }
906 
907 int sion_set_fp_closed(int sid)
908 {
909  int rc = SION_SUCCESS;
910  _sion_filedesc *sion_filedesc;
911 
912  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
913  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
914  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"sion_set_fp_closed: invalid sion_filedesc, aborting %d ...\n", sid));
915  }
916  sion_filedesc->state = SION_FILESTATE_CLOSE;
917  return (rc);
918 }
919 
920 int sion_set_second_fp(int sid, FILE *secondfd)
921 {
922  int rc = SION_SUCCESS;
923  _sion_filedesc *sion_filedesc;
924 
925 
926  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
927  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
928  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"sion_set_second_fp: invalid sion_filedesc, aborting %d ...\n", sid));
929  }
930 
931  if(!(sion_filedesc->fileptr->flags&SION_FILE_FLAG_ANSI)) {
932  return(_sion_errorprint_on_rank(SION_NOT_SUCCESS,_SION_ERROR_RETURN,sion_filedesc->rank,"sion_set_second_fp: file was not opened in ANSI mode, aborting %d ...", sid));
933  }
934 
935  _sion_file_set_second_fileptr(sion_filedesc->fileptr,secondfd);
936 
937  _sion_print_filedesc(sion_filedesc, 512, "sion_set_second_fd", 1);
938  /*
939  if (sion_filedesc->mode == SION_FILEMODE_READ) {
940  sion_seek(sid, SION_CURRENT_RANK, 0, 0);
941  }
942  */
943  return (rc);
944 }
945 
946 int sion_unset_second_fp(int sid)
947 {
948  int rc = SION_SUCCESS;
949  _sion_filedesc *sion_filedesc;
950 
951  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
952  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
953  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"sion_unset_second_fp: invalid sion_filedesc, aborting %d ...\n", sid));
954  }
955 
956  if(!(sion_filedesc->fileptr->flags&SION_FILE_FLAG_ANSI)) {
957  return(_sion_errorprint_on_rank(SION_NOT_SUCCESS,_SION_ERROR_RETURN,sion_filedesc->rank,"sion_unset_second_fp: file was not opened in ANSI mode, aborting %d ...", sid));
958  }
959 
961  return (rc);
962 }
963 
964 int sion_optimize_fp_buffer(int sid)
965 {
966  int rc = SION_SUCCESS;
967  _sion_filedesc *sion_filedesc;
968 
969  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
970  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
971  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"sion_set_second_fp: invalid sion_filedesc, aborting %d ...\n", sid));
972  }
973 
974  sion_filedesc->fpbuffer = (char *) malloc(sion_filedesc->fsblksize);
975  if (sion_filedesc->fpbuffer == NULL) {
976  return(_sion_errorprint_on_rank(SION_NOT_SUCCESS,_SION_ERROR_RETURN,sion_filedesc->rank,"sion_optimize_fp_buffer: cannot allocate internal buffer of size %lu , aborting ...", (unsigned long) sion_filedesc->fsblksize));
977  }
978  sion_filedesc->fpbuffer_size = sion_filedesc->fsblksize;
979 
980  rc=_sion_file_set_buffer(sion_filedesc->fileptr, sion_filedesc->fpbuffer, sion_filedesc->fpbuffer_size);
981  return (rc);
982 }
983 
991 int sion_flush(int sid)
992 {
993  int rc = SION_SUCCESS;
994  _sion_filedesc *sion_filedesc;
995 
996  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
997  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
998  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"sion_unset_second_fp: invalid sion_filedesc, aborting %d ...\n", sid));
999  }
1000  rc = _sion_flush_block(sion_filedesc);
1001  return (rc);
1002 }
1003 
1014 int sion_ensure_free_space(int sid, sion_int64 bytes)
1015 {
1016  _sion_filedesc *sion_filedesc;
1017  sion_int64 byteswritten;
1018  int rc = SION_SUCCESS;
1019 
1020  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
1021  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
1022  return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,"sion_ensure_free_space: invalid sion_filedesc, returning %d ...\n", sid));
1023  }
1024 
1025  DPRINTFP((8, "_sion_ensure_free_space", -1, "enter ensure_free sid=%d bytes=%lld\n", sid, bytes));
1026 
1027  if (sion_filedesc->mode != SION_FILEMODE_WRITE) {
1028  DPRINTFP((8, "_sion_ensure_free_space", -1, "invalid opened\n"));
1029  return(_sion_errorprint_on_rank(SION_NOT_SUCCESS,_SION_ERROR_RETURN,sion_filedesc->rank,"sion_ensure_free_space[%2d]: file is opened invalid sion_mode, returning ...", sion_filedesc->rank));
1030  }
1031  if (!sion_filedesc->usecoll) {
1032  if (sion_filedesc->fileptr == NULL) {
1033  DPRINTFP((8, "_sion_ensure_free_space", -1, "file not opened\n"));
1034  return(_sion_errorprint_on_rank(SION_NOT_SUCCESS,_SION_ERROR_RETURN,sion_filedesc->rank,"sion_ensure_free_space[%2d]: file is not open, returning ...", sion_filedesc->rank));
1035  }
1036  }
1037 
1038  if (bytes > sion_filedesc->chunksize) {
1039  DPRINTFP((8, "_sion_ensure_free_space", -1, "could not write %lld bytes, chunksize=%lld\n", bytes, sion_filedesc->chunksize));
1040  return(_sion_errorprint_on_rank(SION_NOT_SUCCESS,_SION_ERROR_RETURN,sion_filedesc->rank,"sion_ensure_free_space[%2d]: could not write %lld bytes, chunksize=%lld, returning ...",sion_filedesc->rank, bytes, sion_filedesc->chunksize));
1041  }
1042 
1043  _sion_flush_block(sion_filedesc);
1044 
1045  DPRINTFP((16, "_sion_ensure_free_space", -1,
1046  " after getpos sid=%d fileposition is %lld bytes=%lld\n", sid, sion_filedesc->currentpos, bytes));
1047 
1048  byteswritten = sion_filedesc->blocksizes[sion_filedesc->currentblocknr];
1049 
1050  DPRINTFP((16, "_sion_ensure_free_space", -1,
1051  " sid=%d byteswritten(%lld) + new bytes (%lld) = %lld\n", sid, byteswritten, bytes, byteswritten + bytes));
1052 
1053  if ((byteswritten + bytes) > sion_filedesc->chunksize) {
1054  /* not enough space for writing next data */
1055  _sion_create_new_block(sion_filedesc);
1056  }
1057 
1058  DPRINTFP((8, "_sion_ensure_free_space", -1,
1059  "leave ensure_free sid=%d fileposition is %lld bw+bytes=%lld <= chunksize=%lld (fsblksize=%d)\n",
1060  sid, sion_filedesc->currentpos, byteswritten + bytes, sion_filedesc->chunksize, sion_filedesc->fsblksize));
1061 
1062 
1063  return (rc);
1064 
1065 }
1066 
1067 int sion_is_thread_safe() {
1068 #ifdef SION_PTHREADS
1069  return(SION_SUCCESS);
1070 #else
1071  return(SION_NOT_SUCCESS);
1072 #endif
1073 }
1074 
1084 int sion_get_sizeof(int sid, int *numbytes, int *numfds) {
1085  _sion_filedesc *sion_filedesc;
1086  int rc=SION_NOT_SUCCESS;
1087 
1088  *numbytes=SION_SIZE_NOT_VALID;
1089  *numfds=SION_SIZE_NOT_VALID;
1090 
1091  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
1092  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
1093  return(_sion_errorprint(SION_SIZE_NOT_VALID,_SION_ERROR_RETURN,"sion_get_sizeof: invalid sion_filedesc, returning %d ...\n", sid));
1094  }
1095  DPRINTFP((2, "sion_get_sizeof", -1, "enter sid=%d\n", sid));
1096 
1097  rc=_sion_get_size_of_filedesc(sion_filedesc,numbytes,numfds);
1098 
1099  DPRINTFP((2, "sion_get_sizeof", -1, "leave sid=%d numbytes=%d numfds=%d\n", sid, *numbytes, *numfds));
1100 
1101  return (rc);
1102 
1103 }
1104 
1105 
1106 #define DFUNCTION "sion_dup"
1107 
1122 int sion_dup(int sid, int mode, int rank, uint64_t key)
1123 {
1124  int new_sid = SION_ID_NOT_VALID;
1125  _sion_filedesc *sion_filedesc;
1126 
1127  if ((sid<0) || (_sion_vcdtype(sid) != SION_FILEDESCRIPTOR)
1128  || !(sion_filedesc = _sion_vcdtovcon(sid))) {
1129  return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,"sion_dup: invalid sion_filedesc, returning %d ...\n", sid));
1130  }
1131  DPRINTFP((8, DFUNCTION, -1, "enter sid=%d\n", sid));
1132 
1133  if (sion_filedesc->mode != SION_FILEMODE_READ) {
1134  DPRINTFP((8, DFUNCTION, -1, "invalid opened\n"));
1135  return(_sion_errorprint_on_rank(SION_ID_NOT_VALID,_SION_ERROR_RETURN,sion_filedesc->rank, DFUNCTION "[%2d]: file is not opened in read mode, returning ...", sion_filedesc->rank));
1136  }
1137 
1138  new_sid=_sion_dup(sid, mode, rank, key);
1139 
1140  DPRINTFP((8, DFUNCTION, -1, "leave sid=%d new_sid=%d\n", sid, new_sid));
1141 
1142  return (new_sid);
1143 
1144 }
1145 #undef DFUNCTION
1146 
1147 #define DFUNCTION "sion_dedup"
1148 
1156 int sion_dedup(int sid)
1157 {
1158  int rc = 0;
1159  DPRINTFP((8, DFUNCTION, -1, "enter sid=%d\n", sid));
1160 
1161  rc=_sion_dedup(sid);
1162 
1163  DPRINTFP((8, DFUNCTION, -1, "leave sid=%d rc=%d\n", sid, rc));
1164 
1165  return (rc);
1166 
1167 }
1168 #undef DFUNCTION
1169 
1170 #define DFUNCTION "sion_lock_register_lock_callbacks"
1171 
1181 int sion_lock_register_lock_callbacks(int lock(void *), int unlock(void *), void *lock_data)
1182 {
1183  int rc = 0;
1184  DPRINTFP((8, DFUNCTION, -1, "enter\n"));
1185 
1186  rc=_sion_lock_register_lock_callbacks(lock,unlock,lock_data);
1187 
1188  DPRINTFP((8, DFUNCTION, -1, "leave rc=%d\n", rc));
1189 
1190  return (rc);
1191 }
1192 #undef DFUNCTION
1193 
1194 #define DFUNCTION "sion_lock_user_callbacks_defined"
1195 
1201 {
1202  int rc = 0;
1203  DPRINTFP((8, DFUNCTION, -1, "enter\n"));
1204 
1205  rc=_sion_lock_user_callbacks_defined();
1206 
1207  DPRINTFP((8, DFUNCTION, -1, "leave rc=%d\n", rc));
1208 
1209  return (rc);
1210 }
1211 #undef DFUNCTION
int sion_feof(int sid)
Function that indicates whether the end of file is reached for this task.
Definition: sion_common.c:770
sion_int64 _sion_file_write(const void *data, sion_int64 bytes, _sion_fileptr *sion_fileptr)
Write data to file.
Definition: sion_file.c:148
sion_int64 _sion_file_get_position(_sion_fileptr *sion_fileptr)
Get new position in file.
Definition: sion_file.c:272
int _sion_buffer_flush(_sion_filedesc *sion_filedesc)
Flush buffer.
Definition: sion_buffer.c:164
int _sion_flush_block(_sion_filedesc *sion_filedesc)
Update the internal data structure.
int sion_dup(int sid, int mode, int rank, uint64_t key)
Function which duplicates a sion file descriptor.
Definition: sion_common.c:1122
int _sion_seek_on_all_ranks_read(_sion_filedesc *sion_filedesc, int rank, int blocknr, sion_int64 posinblk)
Function to set the file pointer to a new position, updates internal data structure.
sion_int64 _sion_file_set_position(_sion_fileptr *sion_fileptr, sion_int64 startpointer)
Set new position in file.
Definition: sion_file.c:239
sion_int64 sion_bytes_avail_in_block(int sid)
Return the number of bytes available in the current chunk.
Definition: sion_common.c:840
sion_int64 sion_bytes_avail_in_chunk(int sid)
Function that returns the number of bytes available in the current chunk.
Definition: sion_common.c:855
int _sion_buffer_get_data_ptr(_sion_filedesc *sion_filedesc, void **data, sion_int64 *bytes)
Pop all data from buffer.
Definition: sion_buffer.c:139
Sion File Descriptor Structure.
Definition: sion_filedesc.h:77
int sion_get_endianness(void)
Return endianness.
Definition: sion_tools.c:30
int sion_ensure_free_space(int sid, sion_int64 bytes)
Funtion to ensure that enough space is available for writing.
Definition: sion_common.c:1014
sion_int64 * all_blockcount
sion_int64 sion_get_position(int sid)
Function that returns the current file position.
Definition: sion_common.c:891
int sion_get_file_endianness(int sid)
Returns edianness of data in file sid.
Definition: sion_common.c:255
#define SION_FILESTATE_SEROPEN
Definition: sion_filedesc.h:25
int _sion_file_purge(_sion_fileptr *sion_fileptr)
Purge data to file.
Definition: sion_file.c:328
sion_int64 _sion_file_read(void *data, sion_int64 bytes, _sion_fileptr *sion_fileptr)
Read data from file.
Definition: sion_file.c:169
int _sion_seek_on_all_ranks_read_mapped(_sion_filedesc *sion_filedesc_master, int rank, int blocknr, sion_int64 posinblk)
Function to set the file pointer to a new position, updates internal data structure.
sion_int64 * all_currentpos
int _sion_seek_on_all_ranks_write_mapped(_sion_filedesc *sion_filedesc_master, int rank, int blocknr, sion_int64 posinblk)
Function to set the file pointer to a new position, updates internal data structure.
int _sion_file_set_buffer(_sion_fileptr *sion_fileptr, char *buffer, sion_int32 buffer_size)
Set buffer of fp.
Definition: sion_file.c:358
sion_int64 * all_globalranks
int _sion_alloc_filedesc_arrays(_sion_filedesc *sion_filedesc)
Allocate memory for the internal sion arrays.
int sion_lock_register_lock_callbacks(int lock(void *), int unlock(void *), void *lock_data)
Function which registers callback funtions for lock and unlock internal access to shared data structu...
Definition: sion_common.c:1181
int _sion_get_size_of_filedesc(_sion_filedesc *sion_filedesc, int *numbytes, int *numfds)
get size of internal data structure sion_filedesc
sion_int64 * all_currentblocknr
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.
sion_int64 _sion_buffer_push(_sion_filedesc *sion_filedesc, const void *data, sion_int64 bytes)
Push data to buffer.
Definition: sion_buffer.c:103
int _sion_free_io_info(sion_io_stat_t *p)
frees an io_info data structure
int _sion_vcdtype(int sid)
Definition: sion_fd.c:56
int sion_get_current_locations(int sid, int *ntasks, sion_int64 **sion_currentpos, sion_int64 **sion_currentblocknr)
Returns current position in file and pointer fiels containing chunk sizes.
Definition: sion_common.c:309
int _sion_dedup(int sid)
Destroy a duplicated sion file descriptor.
Definition: sion_dup.c:155
sion_int32 fileptr_exported
int sion_get_locations(int sid, int *ntasks, int *maxchunks, sion_int64 *globalskip, sion_int64 *start_of_varheader, sion_int64 **sion_chunksizes, sion_int64 **sion_globalranks, sion_int64 **sion_blockcount, sion_int64 **sion_blocksizes)
Returns pointers to internal fields.
Definition: sion_common.c:86
int sion_get_mapping(int sid, int *mapping_size, sion_int32 **mapping, int *numfiles)
Returns pointers to the internal field mapping.
Definition: sion_common.c:221
size_t sion_fwrite(const void *data, size_t size, size_t nitems, int sid)
Write data to sion file.
Definition: sion_common.c:472
int sion_endianness_swap_needed(int sid)
Returns whether or not byte swapping is needed for sid.
Definition: sion_common.c:279
void * _sion_vcdtovcon(int sid)
Definition: sion_fd.c:51
#define SION_FILE_FLAG_ANSI
Definition: sion_file.h:19
int _sion_dup(int sid, int mode, int rank, uint64_t key)
Create a duplicated sion file descriptor.
Definition: sion_dup.c:50
#define SION_FILEMODE_READ
Definition: sion_filedesc.h:33
int sion_seek(int sid, int rank, int currentblocknr, sion_int64 posinblk)
Function to set the file pointer to a new position.
Definition: sion_common.c:659
int _sion_update_fileposition(_sion_filedesc *sion_filedesc)
Update the internal data structure (check fileposition)
int sion_lock_user_callbacks_defined()
Function which return flag, if user callback for locking are registered.
Definition: sion_common.c:1200
#define SION_FILESTATE_PAROPEN
Definition: sion_filedesc.h:24
int _sion_file_set_second_fileptr(_sion_fileptr *sion_fileptr, FILE *fileptr)
Set second fileptr for file if opened with ANSI.
Definition: sion_file.c:385
int sion_get_sizeof(int sid, int *numbytes, int *numfds)
Function returns size of internal data structure for sid.
Definition: sion_common.c:1084
int _sion_file_unset_second_fileptr(_sion_fileptr *sion_fileptr)
Unset second fileptr for file if opened with ANSI.
Definition: sion_file.c:405
int _sion_seek_on_all_ranks_read_master(_sion_filedesc *sion_filedesc, int rank, int blocknr, sion_int64 posinblk)
Function to set the file pointer to a new position, updates internal data structure.
sion_int32 fpbuffer_size
Definition: sion_filedesc.h:86
sion_int64 * blocksizes
Definition: sion_filedesc.h:98
#define SION_FILESTATE_PAROPENMAPPEDMASTER
Definition: sion_filedesc.h:28
sion_int32 currentblocknr
Definition: sion_filedesc.h:95
#define SION_FILESTATE_SEROPENRANK
Definition: sion_filedesc.h:26
int _sion_create_new_block(_sion_filedesc *sion_filedesc)
Create a new block for the internal data structure.
#define SION_FILEDESCRIPTOR
Definition: sion_fd.h:17
sion_int64 * all_chunksizes
int _sion_print_filedesc(_sion_filedesc *sion_filedesc, int level, char *desc, int flag)
Print the initialized sion file description.
int _sion_freevcd(int sid)
Definition: sion_fd.c:46
#define SION_FILESTATE_CLOSE
Definition: sion_filedesc.h:31
size_t sion_fread(void *data, size_t size, size_t nitems, int sid)
Read data from sion file.
Definition: sion_common.c:591
int _sion_seek_on_current_rank_read(_sion_filedesc *sion_filedesc, int rank, int blocknr, sion_int64 posinblk)
Function to set the file pointer to a new position in the same rank, updates internal data structure.
#define SION_FILEMODE_WRITE
Definition: sion_filedesc.h:34
int _sion_check_on_collective_mode(_sion_filedesc *sion_filedesc)
check if a collective operation are already called,
Sion Time Stamp Header.
int sion_dedup(int sid)
Function which destroy a duplicated sion file descriptor.
Definition: sion_common.c:1156
int _sion_seek_on_all_ranks_write(_sion_filedesc *sion_filedesc, int rank, int blocknr, sion_int64 posinblk)
Function to set the file pointer to a new position, updates internal data structure.
sion_int64 start_of_varheader
#define SION_FILESTATE_SEROPENMASTER
Definition: sion_filedesc.h:27
sion_int64 * all_blocksizes
int _sion_file_flush(_sion_fileptr *sion_fileptr)
Flush data to file.
Definition: sion_file.c:304
int sion_get_current_location(int sid, int *currentchunknr, sion_int64 *currentpos, int *maxchunks, sion_int64 **chunksizes)
Returns current position in file and pointer fiels containing chunk sizes.
Definition: sion_common.c:187
_sion_filedesc ** multifiles
_sion_fileptr * fileptr
Definition: sion_filedesc.h:80
int sion_seek_fp(int sid, int rank, int currentblocknr, sion_int64 posinblk, FILE **fileptr)
Deprecated. Use sion_seek() instead.
Definition: sion_common.c:682
int _sion_seek_on_current_rank_write(_sion_filedesc *sion_filedesc, int rank, int blocknr, sion_int64 posinblk)
Function to set the file pointer to a new position in the same rank, updates internal data structure.
int sion_flush(int sid)
Flushed sion file.
Definition: sion_common.c:991