17 #define _XOPEN_SOURCE 700
26 #include <sys/types.h>
33 #if defined(_SION_BGQ)
34 #include <stdio_ext.h>
37 #if defined(_SION_BGP)
38 #include <stdio_ext.h>
43 #include "sion_error_handler.h"
50 #include "sion_hints.h"
59 int _sion_open(
const char *fname,
const char *file_mode,
int *ntasks,
int *nfiles, sion_int64 **chunksizes, sion_int32 *fsblksize,
int **globalranks, FILE **fileptr)
62 int sid=SION_ID_UNDEF;
65 DPRINTFP((1,
"_sion_open", 0,
"enter open of file %s in %s mode\n", fname, file_mode));
68 if ( ! flags_store ) {
69 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_open: could not parse file mode in %s, aborting ...\n", file_mode));
72 if (flags_store->mask&_SION_FMODE_WRITE) {
75 sid=
_sion_open_write(fname,flags_store->mask,ntasks,nfiles,chunksizes,fsblksize,globalranks,fileptr);
79 sid=
_sion_open_read(fname,flags_store->mask,_SION_READ_ALL_OF_MULTI_FILES,ntasks,nfiles,chunksizes,fsblksize,globalranks,fileptr);
83 _sion_flags_destroy_store(&flags_store);
85 DPRINTFP((1,
"_sion_open", 0,
"leave open of file %s in %s mode sid=%d\n", fname, file_mode,sid));
106 int _sion_open_write(
const char *fname, sion_int64 file_mode_flags,
int *ntasks,
int *nfiles, sion_int64 **chunksizes, sion_int32 *fsblksize,
int **globalranks, FILE **fileptr)
111 sion_int64 new_fsblocksize, apiflag;
112 sion_int32 endianness = 0;
117 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: wrong number of tasks specific: ntasks=%d (<0), returning ...\n", *ntasks));
121 if ((chunksizes==NULL) || (*chunksizes==NULL)) {
122 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: chunksizes seems not to be a pointer to an array, returning ...\n"));
126 if ((globalranks==NULL) || (*globalranks==NULL)) {
127 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: globalranks seems not to be a pointer to an array, returning ...\n"));
132 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: write with nfiles > 1 currently not supported (nfiles=%d), returning ...\n",(
int) *nfiles));
137 if (sion_filedesc == NULL) {
138 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot allocate filedescriptor structure of size %lu (sion_filedesc), aborting ...\n", (
unsigned long)
sizeof(sion_filedesc)));
141 sion_filedesc->
fname = strdup(fname);
145 sion_filedesc->
sid=sid;
153 DPRINTFP((1,
"sion_open", 0,
" it is a write operation #tasks=%d\n", *ntasks));
160 sion_filedesc->
ntasks = *ntasks;
161 sion_filedesc->
nfiles = 1;
163 sion_filedesc->
prefix = strdup(fname);
166 #if defined(_SION_SIONFWD)
167 else if (file_mode_flags&_SION_FMODE_SIONFWD) apiflag=SION_FILE_FLAG_SIONFWD;
169 #ifdef _SION_IME_NATIVE
170 else if (file_mode_flags&_SION_FMODE_IME_NATIVE) apiflag=SION_FILE_FLAG_IME_NATIVE;
180 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot open %s for reading, aborting ...\n", fname));
182 sion_filedesc->
fileptr = sion_fileptr;
187 if((new_fsblocksize<0) || (new_fsblocksize>SION_MAX_FSBLOCKSIZE)) new_fsblocksize=SION_DEFAULT_FSBLOCKSIZE;
188 *fsblksize = new_fsblocksize;
190 DPRINTFP((32,
"_sion_paropen_multi_generic", 0,
"setting fsblksize to %lld\n", new_fsblocksize));
194 for (i = 0; i < *ntasks; i++) {
200 _sion_keyval_check_env(sion_filedesc, file_mode_flags);
202 _sion_alloc_filedesc_all_keyvalptr(sion_filedesc);
205 _sion_calculate_startpointers(sion_filedesc);
216 for (i = 0; i < *ntasks; i++) {
224 sion_filedesc->
rank = 0;
235 *fileptr=sion_filedesc->
fileptr->fileptr;
266 int _sion_open_read(
const char *fname, sion_int64 file_mode_flags,
int read_all,
int *ntasks,
int *nfiles, sion_int64 **chunksizes, sion_int32 *fsblksize,
int **globalranks, FILE **fileptr)
276 if (sion_filedesc == NULL) {
277 return(_sion_errorprint(SION_ID_UNDEF,SION_ID_UNDEF,
"sion_open: cannot allocate filedescriptor structure of size %lu (sion_filedesc), aborting ...\n", (
unsigned long)
sizeof(sion_filedesc)));
280 sion_filedesc->
fname = strdup(fname);
284 sion_filedesc->
sid=sid;
287 #if defined(_SION_SIONFWD)
288 else if (file_mode_flags&_SION_FMODE_SIONFWD) apiflag=SION_FILE_FLAG_SIONFWD;
290 #ifdef _SION_IME_NATIVE
291 else if (file_mode_flags&_SION_FMODE_IME_NATIVE) apiflag=SION_FILE_FLAG_IME_NATIVE;
295 DPRINTFP((1,
"sion_open", 0,
" it is a read operation\n"));
300 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot open %s for reading, aborting ...\n", fname));
302 sion_filedesc->
fileptr = sion_fileptr;
306 if (rc!=SION_SUCCESS) {
307 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot read header from file %s, aborting ...\n", fname));
309 sion_filedesc->
rank = 0;
318 if (rc!=SION_SUCCESS) {
319 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot read header (var part) from file %s, aborting ...\n", fname));
323 _sion_calculate_startpointers(sion_filedesc);
328 if (rc!=SION_SUCCESS) {
329 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot read header (var part block sizes) from file %s, aborting ...\n", fname));
333 _sion_keyval_check_env(sion_filedesc, file_mode_flags);
335 _sion_alloc_filedesc_all_keyvalptr(sion_filedesc);
341 if(read_all==_SION_READ_ALL_OF_MULTI_FILES) {
342 sid=_sion_open_read_master(fname,file_mode_flags,ntasks,nfiles,chunksizes,fsblksize,globalranks,fileptr,sion_filedesc);
344 sid=_sion_open_read_single(fname,file_mode_flags,ntasks,nfiles,chunksizes,fsblksize,globalranks,fileptr,sion_filedesc);
348 for (rank = 0; rank < sion_filedesc->
mapping_size; rank++) {
349 DPRINTFP((2048,
"sion_open", 0,
" mapping[%d] = %d , %d \n", rank,sion_filedesc->
mapping[rank*2+0],sion_filedesc->
mapping[rank*2+1]));
356 sid=_sion_open_read_single(fname,file_mode_flags,ntasks,nfiles,chunksizes,fsblksize,globalranks,fileptr,sion_filedesc);
364 int _sion_open_read_single(
const char *fname, sion_int64 file_mode_flags,
int *ntasks,
int *nfiles, sion_int64 **chunksizes, sion_int32 *fsblksize,
int **globalranks, FILE **fileptr,
_sion_filedesc *sion_filedesc)
370 sid=sion_filedesc->
sid;
376 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
383 for (i = 0; i < sion_filedesc->
ntasks; i++) {
390 *ntasks = sion_filedesc->
ntasks;
391 *nfiles = sion_filedesc->
nfiles;
394 if (chunksizes != NULL) {
395 sion_int64 *helpptr = NULL;
396 if ((*chunksizes) == NULL) {
397 helpptr = (sion_int64 *) malloc(*ntasks *
sizeof(sion_int64));
398 if (helpptr == NULL) {
399 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure of size %lu (chunksizes), aborting ...\n", (
unsigned long)
sizeof(sion_int64)));
401 *chunksizes = helpptr;
403 helpptr = *chunksizes;
405 for (i = 0; i < *ntasks; i++) {
409 if (globalranks != NULL) {
411 if ((*globalranks) == NULL) {
412 helpptr = (
int *) malloc(*ntasks *
sizeof(
int));
413 if (helpptr == NULL) {
414 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot allocate memory of size %lu (globalranks), aborting ...\n", (
unsigned long) (*ntasks) *
sizeof(int)));
416 *globalranks = helpptr;
418 helpptr = *globalranks;
420 for (i = 0; i < (*ntasks); i++) {
427 *fileptr=sion_filedesc->
fileptr->fileptr;
441 int _sion_open_read_master(
const char *fname, sion_int64 file_mode_flags,
int *ntasks,
int *nfiles, sion_int64 **chunksizes, sion_int32 *fsblksize,
int **globalranks, FILE **fileptr,
_sion_filedesc *sion_filedesc)
445 int sid_master, subsid, lfile, lrank, filenr;
454 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
461 for (i = 0; i < sion_filedesc->
ntasks; i++) {
469 for (rank = 0; rank < sion_filedesc->
mapping_size; rank++) {
470 DPRINTFP((32,
"sion_open", 0,
" mapping[%d] = %d , %d \n", rank,sion_filedesc->
mapping[rank*2+0],sion_filedesc->
mapping[rank*2+1]));
476 if (sion_filedesc_master == NULL) {
477 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot allocate filedescriptor structure of size %lu (sion_filedesc_master), aborting ...\n",
478 (
unsigned long)
sizeof(sion_filedesc_master)));
481 sion_filedesc_master->
fname = strdup(fname);
487 sion_filedesc_master->
sid=sid_master;
491 if (sion_filedesc_master->
multifiles == NULL) {
492 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure vector of size %lu (sion_filedesc), aborting ...\n",
498 sion_filedesc_master->
multifiles[0]=sion_filedesc;
500 for(filenr=1;filenr<sion_filedesc->
nfiles;filenr++) {
501 int sub_ntasts, sub_nfiles;
502 sion_int32 sub_chunksize;
506 DPRINTFP((32,
"sion_open", 0,
"open now sub file = %d %s\n", filenr, multi_fname));
508 file_mode_flags, _SION_READ_ALL_OF_MULTI_FILES, &sub_ntasts, &sub_nfiles, NULL, &sub_chunksize, NULL, &sub_fileptr);
509 sion_filedesc_sub=_sion_get_filedesc(subsid);
510 sion_filedesc_master->
multifiles[filenr]=sion_filedesc_sub;
511 DPRINTFP((32,
"sion_open", 0,
"sub file = %d %s opened\n", filenr, multi_fname));
520 sion_filedesc_master->
rank = 0;
523 lfile=sion_filedesc_master->
mapping[sion_filedesc_master->
rank*2+0];
524 lrank=sion_filedesc_master->
mapping[sion_filedesc_master->
rank*2+1];
525 sion_filedesc_sub=sion_filedesc_master->
multifiles[lfile];
535 sion_filedesc_master->
nfiles = sion_filedesc_sub->
nfiles;
536 sion_filedesc_master->
flag1 = sion_filedesc_sub->
flag1;
537 sion_filedesc_master->
flag2 = sion_filedesc_sub->
flag2;
539 sion_filedesc_master->
prefix = strdup(sion_filedesc->
prefix);
554 for(filenr=1;filenr<sion_filedesc->
nfiles;filenr++)
559 for (blknum = 0; blknum < sion_filedesc_sub->
all_blockcount[lrank]; blknum++) {
567 sion_filedesc = sion_filedesc_master;
575 *ntasks = sion_filedesc->
ntasks;
576 *nfiles = sion_filedesc->
nfiles;
578 if (chunksizes != NULL) {
579 sion_int64 *helpptr = NULL;
580 if ((*chunksizes) == NULL) {
581 helpptr = (sion_int64 *) malloc(*ntasks *
sizeof(sion_int64));
582 if (helpptr == NULL) {
583 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure of size %lu (chunksizes), aborting ...\n", (
unsigned long)
sizeof(sion_int64)));
585 *chunksizes = helpptr;
587 helpptr = *chunksizes;
589 for (i = 0; i < *ntasks; i++) {
590 lfile=sion_filedesc_master->
mapping[i*2+0]; lrank=sion_filedesc_master->
mapping[i*2+1];
594 if (globalranks != NULL) {
596 if ((*globalranks) == NULL) {
597 helpptr = (
int *) malloc(*ntasks *
sizeof(
int));
598 if (helpptr == NULL) {
599 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot allocate memory of size %lu (globalranks), aborting ...\n", (
unsigned long) (*ntasks) *
sizeof(int)));
601 *globalranks = helpptr;
604 helpptr = *globalranks;
606 for (i = 0; i < (*ntasks); i++) {
607 lfile=sion_filedesc_master->
mapping[i*2+0]; lrank=sion_filedesc_master->
mapping[i*2+1];
614 *fileptr=sion_filedesc->
fileptr->fileptr;
627 int _sion_open_rank(
const char *fname,
const char *file_mode, sion_int64 *chunksize, sion_int32 *fsblksize,
int *rank, FILE **fileptr)
630 int rc=SION_NOT_SUCCESS, sid=SION_ID_UNDEF;
631 int mapping_filenr, mapping_lrank;
638 DPRINTFTS(*rank,
"before open rank");
639 DPRINTFP((1,
"_sion_open_rank", *rank,
"enter open of file %s in %s mode\n", fname, file_mode));
643 if (sion_filedesc == NULL) {
644 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"_sion_open_rank: cannot allocate filedescriptor structure of size %lu (sion_filedesc), aborting ...", (
unsigned long)
sizeof(sion_filedesc)));
647 sion_filedesc->
fname = strdup(fname);
651 sion_filedesc->
sid=sid;
654 if ( ! flags_store ) {
655 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"sion_paropen_mpi: could not parse file mode in %s, aborting ...", file_mode));
659 #if defined(_SION_SIONFWD)
660 else if (flags_store->mask&_SION_FMODE_SIONFWD) apiflag=SION_FILE_FLAG_SIONFWD;
662 #ifdef _SION_IME_NATIVE
663 else if (flags_store->mask&_SION_FMODE_IME_NATIVE) apiflag=SION_FILE_FLAG_IME_NATIVE;
667 if (flags_store->mask&_SION_FMODE_WRITE) {
670 DPRINTFP((1,
"_sion_open_rank", *rank,
" it is a write operation\n"));
672 _sion_flags_destroy_store(&flags_store);
673 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"_sion_open_rank: %s for writing currently not supported, aborting ...", fname));
676 _sion_flags_destroy_store(&flags_store);
679 DPRINTFTS(*rank,
"start open read");
680 DPRINTFP((1,
"_sion_open_rank", *rank,
" it is a read operation rank=%d\n",*rank));
685 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"_sion_open_rank: cannot open %s for reading, aborting ...", fname));
687 sion_filedesc->
fileptr = sion_fileptr;
688 DPRINTFTS(*rank,
"start after open file 1");
690 DPRINTFTS(*rank,
"start after read header fix part 1");
691 if (rc==SION_NOT_SUCCESS) {
692 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"_sion_open_rank: cannot read header from file %s, aborting ...", fname));
694 sion_filedesc->
rank = *rank;
703 DPRINTFTS(*rank,
"start after read header var part 1");
704 if (rc==SION_NOT_SUCCESS) {
705 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"_sion_open_rank: cannot read var part header from file %s, aborting ...", fname));
708 DPRINTFP((1,
"_sion_open_rank", *rank,
"found number of files %d in %s rank=%d\n", sion_filedesc->
nfiles,sion_filedesc->
fname,*rank));
709 if(sion_filedesc->
nfiles>1) {
712 DPRINTFTS(*rank,
"start after read mapping rank 1");
713 if (rc==SION_NOT_SUCCESS) {
714 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"cannot read var part mapping header from file %s, aborting ...", fname));
716 mapping_filenr = sion_filedesc->
mapping[0];
717 mapping_lrank = sion_filedesc->
mapping[1];
718 DPRINTFP((1,
"_sion_open_rank", *rank,
"data for rank %d is in file %d (lrank=%d)\n", *rank, mapping_filenr,mapping_lrank));
719 DPRINTFTS(*rank,
"start after read mapping 1");
722 if(mapping_filenr>0) {
728 DPRINTFTS(*rank,
"start after close file 1");
733 DPRINTFP((1,
"_sion_open_rank", *rank,
"open file sion_filedesc->fname=%s fname=%s rank=%d\n", sion_filedesc->
fname,fname,*rank));
737 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"_sion_open_rank: cannot open %s for reading, aborting ...", fname));
739 sion_filedesc->
fileptr = sion_fileptr;
740 DPRINTFTS(*rank,
"start after open file i");
743 if (rc==SION_NOT_SUCCESS) {
744 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"sion_open: cannot read header from file %s, aborting ...", fname));
746 DPRINTFTS(*rank,
"start after read header fix part i");
749 if (rc==SION_NOT_SUCCESS) {
750 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"cannot var mapping data from file %s, aborting ...", fname));
752 DPRINTFTS(*rank,
"start after read header var part i");
755 sion_filedesc->
fname = strdup(fname);
761 DPRINTFP((1,
"_sion_open_rank", *rank,
"max blocks=%d\n", sion_filedesc->
maxusedchunks));
764 sion_filedesc->
prefix = strdup(&prefix);
766 _sion_calculate_startpointers(sion_filedesc);
768 sion_filedesc->
rank = mapping_lrank;
771 if (rc==SION_NOT_SUCCESS) {
772 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,sion_filedesc->
rank,
"cannot read header from file %s, aborting ...", fname));
774 DPRINTFTS(*rank,
"start after read header blocksizes i");
792 *fileptr=sion_filedesc->
fileptr->fileptr;
802 DPRINTFP((1,
"_sion_open_rank", 0,
"leave open of file %s in %s mode\n", fname, file_mode));
803 DPRINTFTS(*rank,
"after open rank");
813 int rc = SION_SUCCESS;
814 int blknum, rank, currentrank, mapping_size;
815 #ifdef SION_SERIAL_MASTER
821 DPRINTFP((1,
"_sion_close", -1,
"enter close sid=%d currentpos=%15lld\n", sion_filedesc->
sid, sion_filedesc->
currentpos));
829 return(_sion_errorprint_on_rank(SION_NOT_SUCCESS,_SION_ERROR_RETURN,sion_filedesc->
rank,
"_sion_close: invalid file open state (!SEROPEN), aborting %d ...", sion_filedesc->
sid));
835 DPRINTFP((1,
"_sion_close", -1,
" file was opened in write mode sid=%d setpos to %lld\n", sion_filedesc->
sid, sion_filedesc->
end_of_header));
839 DPRINTFP((1,
"_sion_close", -1,
" after flush block sid=%d fileptr is at position %14lld\n", sion_filedesc->
sid,
_sion_file_get_position(sion_filedesc->
fileptr)));
846 currentrank = sion_filedesc->
rank;
850 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
856 for (blknum = 0; blknum < sion_filedesc->
ntasks; blknum++)
867 for (blknum = 0; blknum < sion_filedesc->
maxusedchunks; blknum++) {
868 for (rank = 0; rank < sion_filedesc->
ntasks; rank++) {
872 DPRINTFP((1,
"_sion_close", -1,
873 " blocksize rank %2d blk %2d -> %lld\n",
895 #ifdef SION_SERIAL_MASTER
899 for(filenr=1;filenr<sion_filedesc->
nfiles;filenr++) {
900 _sion_close(sion_filedesc->
multifiles[filenr]);
902 _sion_free_filedesc(sion_filedesc->
multifiles[filenr]);
912 #ifdef SION_SERIAL_MASTER
917 DPRINTFP((1,
"_sion_close", -1,
"leave close sid=%d\n", sion_filedesc->
sid));
933 newfname = malloc(SION_FILENAME_LENGTH);
934 if (newfname == NULL) {
935 _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_get_multi_filename: Cannot allocate string newfname\n");
939 if(strlen(fname)<SION_FILENAME_LENGTH-7) {
940 sprintf(newfname,
"%s.%06d", fname, filenumber);
942 _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_get_multi_filename: filename too long\n");
947 strcpy(newfname, fname);
962 int rc = SION_SUCCESS;
966 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_flush_file: invalid sion_filedesc, aborting %d ...\n", sid));
968 DPRINTFP((32,
"_sion_flush_file", sion_filedesc->
rank,
"flush sid=%d\n", sid));
986 int rc = SION_SUCCESS;
988 DPRINTFP((2,
"_sion_update_fileposition", sion_filedesc->
rank,
"enter\n"));
1006 DPRINTFP((2,
"_sion_update_fileposition", sion_filedesc->
rank,
"leave pos=%lld usecoll=%d collector=%d rank\n",
1018 int rc = SION_SUCCESS;
1052 int rc = SION_SUCCESS;
1053 sion_int64 byteswritten;
1055 DPRINTFP((2,
"_sion_flush_block", sion_filedesc->
rank,
"enter fileposition=%lld\n", sion_filedesc->
currentpos));
1059 DPRINTFP((2,
"_sion_flush_block", sion_filedesc->
rank,
"after update fileposition=%lld\n", sion_filedesc->
currentpos));
1065 if (byteswritten > 0) {
1068 DPRINTFP((2,
"_sion_flush_block", sion_filedesc->
rank,
1069 "flushed lastchunknr->%d currentblocknr=%d byteswritten=%lld fileposition=%lld startpos=%lld (%lld)\n",
1073 rc = SION_NOT_SUCCESS;
1074 DPRINTFP((2,
"_sion_flush_block", sion_filedesc->
rank,
"not flushed lastchunknr->%d byteswritten=%lld fileposition=%lld startpos=%lld (%lld)\n",
1078 DPRINTFP((2,
"_sion_flush_block", sion_filedesc->
rank,
"leave\n"));
1091 int rc = SION_SUCCESS;
1093 DPRINTFP((2,
"_sion_create_new_block", _SION_DEFAULT_RANK,
"enter alloc \n"));
1102 _sion_apply_hints(sion_filedesc,SION_HINTS_FREE_TYPE_CHUNK);
1108 rc = _sion_apply_hints(sion_filedesc,SION_HINTS_ACCESS_TYPE_CHUNK);
1116 DPRINTFP((2,
"_sion_create_new_block", _SION_DEFAULT_RANK,
"skip to next already allocated block currentblocknr=%d lastchunknr->%d currentpos=%lld\n",
1131 _sion_apply_hints(sion_filedesc,SION_HINTS_FREE_TYPE_CHUNK);
1139 rc = _sion_apply_hints(sion_filedesc,SION_HINTS_ACCESS_TYPE_CHUNK);
1146 DPRINTFP((2,
"_sion_create_new_block", _SION_DEFAULT_RANK,
"skip to new allocated block currentblocknr=%d lastchunknr->%d currentpos=%lld\n",
1159 sion_int32 endianness = 0;
1161 DPRINTFP((2,
"_sion_get_endianness_flags", -1,
"enter with flags 0x%x\n", flags));
1166 endianness |= endianness << 24;
1167 if (flags & _SION_FMODE_ENDIANNESS_SET) {
1169 if (flags & _SION_FMODE_ENDIANNESS_BIG) {
1170 endianness |= 0x0101 << 8;
1173 else if (endianness & 1) {
1175 endianness |= 0x0101 << 8;
1178 DPRINTFP((2,
"_sion_get_endianness_flags", -1,
"leave with endianness 0x%x\n", endianness));
1183 #define DFUNCTION "_sion_getenv"
1188 char *name_with_prefix = NULL;
1189 char *getenv_result = NULL;
1190 const int full_len = strlen(name) + strlen(SION_LVERSION_PREFIX) + 1;
1192 DPRINTFP((2, DFUNCTION, -1,
"enter: name = %s\n", name));
1194 name_with_prefix = (
char *)malloc(full_len);
1195 sprintf(name_with_prefix,
"%s%s", SION_LVERSION_PREFIX, name);
1197 getenv_result = getenv(name_with_prefix);
1198 free(name_with_prefix);
1200 DPRINTFP((2, DFUNCTION, -1,
"leave: getenv_result = %s\n", getenv_result));
1202 return getenv_result;
1218 _sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_alloc_io_info: cannot allocate memory of size %lu (p_fn), aborting ...\n",
1226 p->names = (
const char **) malloc(p_nf *
sizeof(
char *));
1227 if (p->names == NULL) {
1228 _sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_alloc_io_info: cannot allocate memory of size %lu (names), aborting ...\n",
1229 (
unsigned long) p_nf *
sizeof(
char *));
1234 p->sizes = (
size_t *) malloc(p_nf *
sizeof(
size_t));
1235 if (p->sizes == NULL) {
1236 _sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_alloc_io_info: cannot allocate memory of size %lu (sizes), aborting ...\n",
1237 (
unsigned long) p_nf *
sizeof(
size_t));
1243 p->roles = (
int *) malloc(p_nf *
sizeof(
int));
1244 if (p->roles == NULL) {
1245 _sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_alloc_io_info: cannot allocate memory of size %lu (roles), aborting ...\n",
1246 (
unsigned long) p_nf *
sizeof(
int));
1253 for(i=0;i<p_nf;i++) {
1256 p->roles[i]=SION_ROLE_NONE;
1268 int rc=SION_SUCCESS;
1270 if(p->names!=NULL) free(p->names);
1271 if(p->sizes!=NULL) free(p->sizes);
1272 if(p->roles!=NULL) free(p->roles);
int _sion_buffer_flush(_sion_filedesc *sion_filedesc)
Flush buffer.
int sion_get_endianness(void)
Return endianness.
void * _sion_vcdtovcon(int sid)
int _sion_vcdtype(int sid)
int _sion_newvcd(void *data, int type)
int _sion_freevcd(int sid)
#define SION_FILEDESCRIPTOR
long _sion_file_get_opt_blksize(_sion_fileptr *sion_fileptr)
Get optional file system block size for a file.
int _sion_file_flush(_sion_fileptr *sion_fileptr)
Flush data to file.
int _sion_file_close(_sion_fileptr *sion_fileptr)
Close file and destroys fileptr structure.
sion_int64 _sion_file_set_position(_sion_fileptr *sion_fileptr, sion_int64 startpointer)
Set new position in file.
int _sion_file_purge(_sion_fileptr *sion_fileptr)
Purge data to file.
sion_int64 _sion_file_get_position(_sion_fileptr *sion_fileptr)
Get new position in file.
_sion_fileptr * _sion_file_open(const char *fname, unsigned int flags, unsigned int addflags)
Create and open a new file for writing.
#define SION_FILE_FLAG_READ
#define SION_FILE_FLAG_CREATE
#define SION_FILE_FLAG_ANSI
#define SION_FILE_FLAG_WRITE
#define SION_FILE_FLAG_POSIX
int _sion_init_filedesc(_sion_filedesc *sion_filedesc)
Initialize the sion file description.
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_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.
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_alloc_filedesc_block_arrays(_sion_filedesc *sion_filedesc)
Allocate memory for the internal sion structure, fields for all chunksizes of all tasks.
#define SION_FILEMODE_WRITE
#define SION_FILEMODE_READ
#define SION_FILESTATE_SEROPENRANK
#define SION_FILESTATE_SEROPENMASTER
#define SION_FILESTATE_SEROPEN
_sion_flags_store * _sion_parse_flags(const char *flags)
Parse flags and return a flags store with key value pairs.
int _sion_create_new_block(_sion_filedesc *sion_filedesc)
Create a new block for the internal data structure.
int _sion_open_write(const char *fname, sion_int64 file_mode_flags, int *ntasks, int *nfiles, sion_int64 **chunksizes, sion_int32 *fsblksize, int **globalranks, FILE **fileptr)
internal sion serial open function for writing on one file
char * _sion_getenv(const char *name)
int _sion_free_io_info(sion_io_stat_t *p)
frees an io_info data structure
char * _sion_get_multi_filename(const char *fname, int filenumber)
generates the multi filename
int _sion_flush_block(_sion_filedesc *sion_filedesc)
Update the internal data structure.
int _sion_check_on_collective_mode(_sion_filedesc *sion_filedesc)
check if a collective operation are already called,
sion_int32 _sion_get_endianness_with_flags(sion_int64 flags)
Return endianness including possible choice via flags.
sion_io_stat_t * _sion_alloc_io_info(int p_nf)
allocates an io_info data structure for nfiles files
int _sion_open_read(const char *fname, sion_int64 file_mode_flags, int read_all, int *ntasks, int *nfiles, sion_int64 **chunksizes, sion_int32 *fsblksize, int **globalranks, FILE **fileptr)
internal sion serial open function for reading on one or more files
int _sion_update_fileposition(_sion_filedesc *sion_filedesc)
Update the internal data structure (check fileposition)
int _sion_flush_file(int sid)
Flush the data to the disk for the current task.
Sion File Descriptor Structure.
sion_int64 * all_blocksizes
sion_int32 filesionversion
sion_int64 start_of_varheader
sion_int32 filesionpatchlevel
sion_int64 * all_chunksizes
sion_int64 * all_currentpos
sion_int64 * all_currentblocknr
sion_int32 fileptr_exported
_sion_filedesc ** multifiles
sion_int64 * all_globalranks
sion_int32 currentblocknr
sion_int64 * all_startpointers
sion_int64 * all_blockcount