22 #ifndef __USE_FILE_OFFSET64 23 #define __USE_FILE_OFFSET64 29 #include <sys/types.h> 36 #if defined(_SION_BGQ) 37 #include <stdio_ext.h> 40 #if defined(_SION_BGP) 41 #include <stdio_ext.h> 52 #include "sion_hints.h" 60 int _sion_open(
const char *fname,
const char *file_mode,
int *ntasks,
int *nfiles, sion_int64 **chunksizes, sion_int32 *fsblksize,
int **globalranks, FILE **fileptr)
63 int sid=SION_ID_UNDEF;
66 DPRINTFP((1,
"_sion_open", 0,
"enter open of file %s in %s mode\n", fname, file_mode));
69 if ( ! flags_store ) {
70 return(
_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_open: could not parse file mode in %s, aborting ...\n", file_mode));
73 if (flags_store->mask&_SION_FMODE_WRITE) {
76 sid=
_sion_open_write(fname,flags_store->mask,ntasks,nfiles,chunksizes,fsblksize,globalranks,fileptr);
80 sid=
_sion_open_read(fname,flags_store->mask,_SION_READ_ALL_OF_MULTI_FILES,ntasks,nfiles,chunksizes,fsblksize,globalranks,fileptr);
84 _sion_flags_destroy_store(flags_store);
86 DPRINTFP((1,
"_sion_open", 0,
"leave open of file %s in %s mode sid=%d\n", fname, file_mode,sid));
107 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)
112 sion_int64 new_fsblocksize, apiflag;
113 sion_int32 endianness = 0;
118 return(
_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: wrong number of tasks specific: ntasks=%d (<0), returning ...\n", *ntasks));
122 if ((chunksizes==NULL) || (*chunksizes==NULL)) {
123 return(
_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: chunksizes seems not to be a pointer to an array, returning ...\n"));
127 if ((globalranks==NULL) || (*globalranks==NULL)) {
128 return(
_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: globalranks seems not to be a pointer to an array, returning ...\n"));
133 return(
_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: write with nfiles > 1 currently not supported (nfiles=%d), returning ...\n",(
int) *nfiles));
138 if (sion_filedesc == NULL) {
139 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)));
142 sion_filedesc->
fname = strdup(fname);
146 sion_filedesc->
sid=sid;
154 DPRINTFP((1,
"sion_open", 0,
" it is a write operation #tasks=%d\n", *ntasks));
161 sion_filedesc->
ntasks = *ntasks;
162 sion_filedesc->
nfiles = 1;
164 sion_filedesc->
prefix = strdup(fname);
175 return(
_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot open %s for reading, aborting ...\n", fname));
177 sion_filedesc->
fileptr = sion_fileptr;
182 if((new_fsblocksize<0) || (new_fsblocksize>SION_MAX_FSBLOCKSIZE)) new_fsblocksize=SION_DEFAULT_FSBLOCKSIZE;
183 *fsblksize = new_fsblocksize;
185 DPRINTFP((32,
"_sion_paropen_multi_generic", 0,
"setting fsblksize to %lld\n", new_fsblocksize));
189 for (i = 0; i < *ntasks; i++) {
195 _sion_keyval_check_env(sion_filedesc, file_mode_flags);
197 _sion_alloc_filedesc_all_keyvalptr(sion_filedesc);
200 _sion_calculate_startpointers(sion_filedesc);
211 for (i = 0; i < *ntasks; i++) {
219 sion_filedesc->
rank = 0;
230 *fileptr=sion_filedesc->
fileptr->fileptr;
261 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)
271 if (sion_filedesc == NULL) {
272 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)));
275 sion_filedesc->
fname = strdup(fname);
279 sion_filedesc->
sid=sid;
284 DPRINTFP((1,
"sion_open", 0,
" it is a read operation\n"));
289 return(
_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot open %s for reading, aborting ...\n", fname));
291 sion_filedesc->
fileptr = sion_fileptr;
295 if (rc!=SION_SUCCESS) {
296 return(
_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot read header from file %s, aborting ...\n", fname));
298 sion_filedesc->
rank = 0;
307 if (rc!=SION_SUCCESS) {
308 return(
_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot read header (var part) from file %s, aborting ...\n", fname));
312 _sion_calculate_startpointers(sion_filedesc);
317 if (rc!=SION_SUCCESS) {
318 return(
_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot read header (var part block sizes) from file %s, aborting ...\n", fname));
322 _sion_keyval_check_env(sion_filedesc, file_mode_flags);
324 _sion_alloc_filedesc_all_keyvalptr(sion_filedesc);
330 if(read_all==_SION_READ_ALL_OF_MULTI_FILES) {
331 sid=_sion_open_read_master(fname,file_mode_flags,ntasks,nfiles,chunksizes,fsblksize,globalranks,fileptr,sion_filedesc);
333 sid=_sion_open_read_single(fname,file_mode_flags,ntasks,nfiles,chunksizes,fsblksize,globalranks,fileptr,sion_filedesc);
337 for (rank = 0; rank < sion_filedesc->
mapping_size; rank++) {
338 DPRINTFP((2048,
"sion_open", 0,
" mapping[%d] = %d , %d \n", rank,sion_filedesc->
mapping[rank*2+0],sion_filedesc->
mapping[rank*2+1]));
345 sid=_sion_open_read_single(fname,file_mode_flags,ntasks,nfiles,chunksizes,fsblksize,globalranks,fileptr,sion_filedesc);
353 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)
359 sid=sion_filedesc->
sid;
365 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
372 for (i = 0; i < sion_filedesc->
ntasks; i++) {
379 *ntasks = sion_filedesc->
ntasks;
380 *nfiles = sion_filedesc->
nfiles;
383 if (chunksizes != NULL) {
384 sion_int64 *helpptr = NULL;
385 if ((*chunksizes) == NULL) {
386 helpptr = (sion_int64 *) malloc(*ntasks *
sizeof(sion_int64));
387 if (helpptr == NULL) {
388 return(
_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure of size %lu (chunksizes), aborting ...\n", (
unsigned long)
sizeof(sion_int64)));
390 *chunksizes = helpptr;
392 helpptr = *chunksizes;
394 for (i = 0; i < *ntasks; i++) {
398 if (globalranks != NULL) {
400 if ((*globalranks) == NULL) {
401 helpptr = (
int *) malloc(*ntasks *
sizeof(
int));
402 if (helpptr == NULL) {
403 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)));
405 *globalranks = helpptr;
407 helpptr = *globalranks;
409 for (i = 0; i < (*ntasks); i++) {
416 *fileptr=sion_filedesc->
fileptr->fileptr;
430 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)
434 int sid_master, subsid, lfile, lrank, filenr;
437 sid=sion_filedesc->
sid;
440 sid=sion_filedesc->
sid;
446 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
453 for (i = 0; i < sion_filedesc->
ntasks; i++) {
461 for (rank = 0; rank < sion_filedesc->
mapping_size; rank++) {
462 DPRINTFP((32,
"sion_open", 0,
" mapping[%d] = %d , %d \n", rank,sion_filedesc->
mapping[rank*2+0],sion_filedesc->
mapping[rank*2+1]));
468 if (sion_filedesc_master == NULL) {
469 return(
_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot allocate filedescriptor structure of size %lu (sion_filedesc_master), aborting ...\n",
470 (
unsigned long)
sizeof(sion_filedesc_master)));
473 sion_filedesc_master->
fname = strdup(fname);
479 sion_filedesc_master->
sid=sid_master;
483 if (sion_filedesc_master->
multifiles == NULL) {
484 return(
_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure vector of size %lu (sion_filedesc), aborting ...\n",
490 sion_filedesc_master->
multifiles[0]=sion_filedesc;
492 for(filenr=1;filenr<sion_filedesc->
nfiles;filenr++) {
493 int sub_ntasts, sub_nfiles;
494 sion_int32 sub_chunksize;
498 DPRINTFP((32,
"sion_open", 0,
"open now sub file = %d %s\n", filenr, multi_fname));
500 file_mode_flags, _SION_READ_ALL_OF_MULTI_FILES, &sub_ntasts, &sub_nfiles, NULL, &sub_chunksize, NULL, &sub_fileptr);
501 sion_filedesc_sub=_sion_get_filedesc(subsid);
502 sion_filedesc_master->
multifiles[filenr]=sion_filedesc_sub;
503 DPRINTFP((32,
"sion_open", 0,
"sub file = %d %s opened\n", filenr, multi_fname));
512 sion_filedesc_master->
rank = 0;
515 lfile=sion_filedesc_master->
mapping[sion_filedesc_master->
rank*2+0];
516 lrank=sion_filedesc_master->
mapping[sion_filedesc_master->
rank*2+1];
517 sion_filedesc_sub=sion_filedesc_master->
multifiles[lfile];
527 sion_filedesc_master->
nfiles = sion_filedesc_sub->
nfiles;
528 sion_filedesc_master->
flag1 = sion_filedesc_sub->
flag1;
529 sion_filedesc_master->
flag2 = sion_filedesc_sub->
flag2;
531 sion_filedesc_master->
prefix = strdup(sion_filedesc->
prefix);
546 for(filenr=1;filenr<sion_filedesc->
nfiles;filenr++)
551 for (blknum = 0; blknum < sion_filedesc_sub->
all_blockcount[lrank]; blknum++) {
559 sion_filedesc = sion_filedesc_master;
567 *ntasks = sion_filedesc->
ntasks;
568 *nfiles = sion_filedesc->
nfiles;
570 if (chunksizes != NULL) {
571 sion_int64 *helpptr = NULL;
572 if ((*chunksizes) == NULL) {
573 helpptr = (sion_int64 *) malloc(*ntasks *
sizeof(sion_int64));
574 if (helpptr == NULL) {
575 return(
_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure of size %lu (chunksizes), aborting ...\n", (
unsigned long)
sizeof(sion_int64)));
577 *chunksizes = helpptr;
579 helpptr = *chunksizes;
581 for (i = 0; i < *ntasks; i++) {
582 lfile=sion_filedesc_master->
mapping[i*2+0]; lrank=sion_filedesc_master->
mapping[i*2+1];
586 if (globalranks != NULL) {
588 if ((*globalranks) == NULL) {
589 helpptr = (
int *) malloc(*ntasks *
sizeof(
int));
590 if (helpptr == NULL) {
591 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)));
593 *globalranks = helpptr;
596 helpptr = *globalranks;
598 for (i = 0; i < (*ntasks); i++) {
599 lfile=sion_filedesc_master->
mapping[i*2+0]; lrank=sion_filedesc_master->
mapping[i*2+1];
606 *fileptr=sion_filedesc->
fileptr->fileptr;
619 int _sion_open_rank(
const char *fname,
const char *file_mode, sion_int64 *chunksize, sion_int32 *fsblksize,
int *rank, FILE **fileptr)
622 int rc=SION_NOT_SUCCESS, sid=SION_ID_UNDEF;
623 int mapping_filenr, mapping_lrank;
630 DPRINTFTS(*rank,
"before open rank");
631 DPRINTFP((1,
"_sion_open_rank", *rank,
"enter open of file %s in %s mode\n", fname, file_mode));
633 prefix = calloc(SION_FILENAME_LENGTH,1);
634 if (prefix == NULL) {
635 return(_sion_errorprint_on_rank(SION_NOT_SUCCESS,_SION_ERROR_RETURN,*rank,
"_sion_open_rank: cannot allocate prefix string of size %lu , aborting ...\n", (
unsigned long) SION_FILENAME_LENGTH));
640 if (sion_filedesc == NULL) {
641 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)));
644 sion_filedesc->
fname = strdup(fname);
648 sion_filedesc->
sid=sid;
651 if ( ! flags_store ) {
652 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));
658 if (flags_store->mask&_SION_FMODE_WRITE) {
661 DPRINTFP((1,
"_sion_open_rank", *rank,
" it is a write operation\n"));
663 _sion_flags_destroy_store(flags_store);
664 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"_sion_open_rank: %s for writing currently not supported, aborting ...", fname));
669 DPRINTFTS(*rank,
"start open read");
670 DPRINTFP((1,
"_sion_open_rank", *rank,
" it is a read operation rank=%d\n",*rank));
675 _sion_flags_destroy_store(flags_store);
676 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"_sion_open_rank: cannot open %s for reading, aborting ...", fname));
678 sion_filedesc->
fileptr = sion_fileptr;
679 DPRINTFTS(*rank,
"start after open file 1");
681 DPRINTFTS(*rank,
"start after read header fix part 1");
682 if (rc==SION_NOT_SUCCESS) {
683 _sion_flags_destroy_store(flags_store);
684 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"_sion_open_rank: cannot read header from file %s, aborting ...", fname));
686 sion_filedesc->
rank = *rank;
695 DPRINTFTS(*rank,
"start after read header var part 1");
696 if (rc==SION_NOT_SUCCESS) {
697 _sion_flags_destroy_store(flags_store);
698 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));
701 DPRINTFP((1,
"_sion_open_rank", *rank,
"found number of files %d in %s rank=%d\n", sion_filedesc->
nfiles,sion_filedesc->
fname,*rank));
702 if(sion_filedesc->
nfiles>1) {
705 DPRINTFTS(*rank,
"start after read mapping rank 1");
706 if (rc==SION_NOT_SUCCESS) {
707 _sion_flags_destroy_store(flags_store);
708 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"cannot read var part mapping header from file %s, aborting ...", fname));
710 mapping_filenr = sion_filedesc->
mapping[0];
711 mapping_lrank = sion_filedesc->
mapping[1];
712 DPRINTFP((1,
"_sion_open_rank", *rank,
"data for rank %d is in file %d (lrank=%d)\n", *rank, mapping_filenr,mapping_lrank));
713 DPRINTFTS(*rank,
"start after read mapping 1");
716 if(mapping_filenr>0) {
722 DPRINTFTS(*rank,
"start after close file 1");
727 DPRINTFP((1,
"_sion_open_rank", *rank,
"open file sion_filedesc->fname=%s fname=%s rank=%d\n", sion_filedesc->
fname,fname,*rank));
731 _sion_flags_destroy_store(flags_store);
732 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"_sion_open_rank: cannot open %s for reading, aborting ...", fname));
734 sion_filedesc->
fileptr = sion_fileptr;
735 DPRINTFTS(*rank,
"start after open file i");
738 if (rc==SION_NOT_SUCCESS) {
739 _sion_flags_destroy_store(flags_store);
740 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"sion_open: cannot read header from file %s, aborting ...", fname));
742 DPRINTFTS(*rank,
"start after read header fix part i");
745 if (rc==SION_NOT_SUCCESS) {
746 _sion_flags_destroy_store(flags_store);
747 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"cannot var mapping data from file %s, aborting ...", fname));
749 DPRINTFTS(*rank,
"start after read header var part i");
752 sion_filedesc->
fname = strdup(fname);
759 DPRINTFP((1,
"_sion_open_rank", *rank,
"max blocks=%d\n", sion_filedesc->
maxusedchunks));
762 sion_filedesc->
prefix = strdup(prefix);
764 _sion_calculate_startpointers(sion_filedesc);
766 sion_filedesc->
rank = mapping_lrank;
769 if (rc==SION_NOT_SUCCESS) {
770 _sion_flags_destroy_store(flags_store);
771 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,sion_filedesc->
rank,
"cannot read header from file %s, aborting ...", fname));
773 DPRINTFTS(*rank,
"start after read header blocksizes i");
791 *fileptr=sion_filedesc->
fileptr->fileptr;
802 _sion_flags_destroy_store(flags_store);
805 DPRINTFP((1,
"_sion_open_rank", 0,
"leave open of file %s in %s mode\n", fname, file_mode));
806 DPRINTFTS(*rank,
"after open rank");
816 int rc = SION_SUCCESS;
817 int blknum, rank, currentrank, mapping_size;
818 #ifdef SION_SERIAL_MASTER 824 DPRINTFP((1,
"_sion_close", -1,
"enter close sid=%d currentpos=%15lld\n", sion_filedesc->
sid, sion_filedesc->
currentpos));
832 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));
838 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));
842 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)));
849 currentrank = sion_filedesc->
rank;
853 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
859 for (blknum = 0; blknum < sion_filedesc->
ntasks; blknum++)
870 for (blknum = 0; blknum < sion_filedesc->
maxusedchunks; blknum++) {
871 for (rank = 0; rank < sion_filedesc->
ntasks; rank++) {
875 DPRINTFP((1,
"_sion_close", -1,
876 " blocksize rank %2d blk %2d -> %lld\n",
898 #ifdef SION_SERIAL_MASTER 902 for(filenr=1;filenr<sion_filedesc->
nfiles;filenr++) {
903 _sion_close(sion_filedesc->
multifiles[filenr]);
905 _sion_free_filedesc(sion_filedesc->
multifiles[filenr]);
915 #ifdef SION_SERIAL_MASTER 920 DPRINTFP((1,
"_sion_close", -1,
"leave close sid=%d\n", sion_filedesc->
sid));
936 newfname = malloc(SION_FILENAME_LENGTH);
937 if (newfname == NULL) {
938 _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_get_multi_filename: Cannot allocate string newfname\n");
942 if(strlen(fname)<SION_FILENAME_LENGTH-7) {
943 sprintf(newfname,
"%s.%06d", fname, filenumber);
945 _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_get_multi_filename: filename too long\n");
949 strcpy(newfname, fname);
964 int rc = SION_SUCCESS;
968 return(
_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_flush_file: invalid sion_filedesc, aborting %d ...\n", sid));
970 DPRINTFP((32,
"_sion_flush_file", sion_filedesc->
rank,
"flush sid=%d\n", sid));
988 int rc = SION_SUCCESS;
990 DPRINTFP((2,
"_sion_update_fileposition", sion_filedesc->
rank,
"enter\n"));
1008 DPRINTFP((2,
"_sion_update_fileposition", sion_filedesc->
rank,
"leave pos=%lld usecoll=%d collector=%d rank\n",
1020 int rc = SION_SUCCESS;
1054 int rc = SION_SUCCESS;
1055 sion_int64 byteswritten;
1057 DPRINTFP((2,
"_sion_flush_block", sion_filedesc->
rank,
"enter\n"));
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 rc = _sion_apply_hints(sion_filedesc,SION_HINTS_FREE_TYPE_CHUNK);
1108 rc = _sion_apply_hints(sion_filedesc,SION_HINTS_ACCESS_TYPE_CHUNK);
1114 DPRINTFP((2,
"_sion_create_new_block", _SION_DEFAULT_RANK,
"skip to next already allocated block currentblocknr=%d lastchunknr->%d currentpos=%lld\n",
1129 rc = _sion_apply_hints(sion_filedesc,SION_HINTS_FREE_TYPE_CHUNK);
1137 rc = _sion_apply_hints(sion_filedesc,SION_HINTS_ACCESS_TYPE_CHUNK);
1143 DPRINTFP((2,
"_sion_create_new_block", _SION_DEFAULT_RANK,
"skip to new allocated block currentblocknr=%d lastchunknr->%d currentpos=%lld\n",
1162 case _SION_ERROR_RETURN:
1163 fprintf(stderr,
"SION_ERROR_RETURN on rank %d, rc=%d: ",rank,rc);
1164 va_start(ap, format);
1165 vfprintf(stderr, format, ap);
1167 fprintf(stderr,
"\n");
1170 case _SION_ERROR_WARN:
1171 fprintf(stderr,
"SION_ERROR_WARN on rank %d, rc=%d: ",rank,rc);
1172 va_start(ap, format);
1173 vfprintf(stderr, format, ap);
1175 fprintf(stderr,
"\n");
1178 case _SION_ERROR_ABORT:
1179 fprintf(stderr,
"SION_ERROR_ABORT on rank %d, rc=%d: \n",rank,rc);
1180 va_start(ap, format);
1181 vfprintf(stderr, format, ap);
1183 fprintf(stderr,
"\n");
1187 fprintf(stderr,
"SION_ERROR_UNKNOWN on rank %d, rc=%d: ",rank,rc);
1188 va_start(ap, format);
1189 vfprintf(stderr, format, ap);
1191 fprintf(stderr,
"\n");
1197 int _sion_errorprint_on_rank(
int rc,
int level,
int rank,
const char *format, ...)
1204 if (t) rankselect = atoi(t);
1207 case _SION_ERROR_RETURN:
1208 if((rankselect<0) || (rankselect==rank)) {
1209 fprintf(stderr,
"SION_ERROR_RETURN on rank %d, rc=%d: ",rank,rc);
1210 va_start(ap, format);
1211 vfprintf(stderr, format, ap);
1213 fprintf(stderr,
"\n");
1217 case _SION_ERROR_ABORT:
1218 if((rankselect<0) || (rankselect==rank)) {
1219 fprintf(stderr,
"SION_ERROR_ABORT on rank %d, rc=%d: ",rank,rc);
1220 va_start(ap, format);
1221 vfprintf(stderr, format, ap);
1223 fprintf(stderr,
"\n");
1228 if((rankselect<0) || (rankselect==rank)) {
1230 fprintf(stderr,
"SION_ERROR_UNKNOWN on rank %d, rc=%d: ",rank,rc);
1231 va_start(ap, format);
1232 vfprintf(stderr, format, ap);
1234 fprintf(stderr,
"\n");
1246 sion_int32 endianness = 0;
1248 DPRINTFP((2,
"_sion_get_endianness_flags", -1,
"enter with flags 0x%x\n", flags));
1253 endianness |= endianness << 24;
1254 if (flags & _SION_FMODE_ENDIANNESS_SET) {
1256 if (flags & _SION_FMODE_ENDIANNESS_BIG) {
1257 endianness |= 0x0101 << 8;
1260 else if (endianness & 1) {
1262 endianness |= 0x0101 << 8;
1265 DPRINTFP((2,
"_sion_get_endianness_flags", -1,
"leave with endianness 0x%x\n", endianness));
1270 #define DFUNCTION "_sion_getenv" 1275 char *name_with_prefix = NULL;
1276 char *getenv_result = NULL;
1277 const int full_len = strlen(name) + strlen(SION_LVERSION_PREFIX) + 1;
1279 DPRINTFP((2, DFUNCTION, -1,
"enter: name = %s\n", name));
1281 name_with_prefix = (
char *)malloc(full_len);
1282 sprintf(name_with_prefix,
"%s%s", SION_LVERSION_PREFIX, name);
1284 getenv_result = getenv(name_with_prefix);
1285 free(name_with_prefix);
1287 DPRINTFP((2, DFUNCTION, -1,
"leave: getenv_result = %s\n", getenv_result));
1289 return getenv_result;
long _sion_file_get_opt_blksize(_sion_fileptr *sion_fileptr)
Get optional file system block size for a file.
sion_int64 _sion_file_get_position(_sion_fileptr *sion_fileptr)
Get new position in file.
int _sion_buffer_flush(_sion_filedesc *sion_filedesc)
Flush buffer.
int _sion_flush_block(_sion_filedesc *sion_filedesc)
Update the internal data structure.
sion_int64 _sion_file_set_position(_sion_fileptr *sion_fileptr, sion_int64 startpointer)
Set new position in file.
_sion_filedesc * _sion_alloc_filedesc()
Allocates memory for internal sion structure.
_sion_fileptr * _sion_file_open(const char *fname, unsigned int flags, unsigned int addflags)
Create and open a new file for writing.
Sion File Descriptor Structure.
int sion_get_endianness(void)
Return endianness.
sion_int64 * all_blockcount
#define SION_FILE_FLAG_WRITE
#define SION_FILESTATE_SEROPEN
int _sion_file_purge(_sion_fileptr *sion_fileptr)
Purge data to file.
sion_int64 * all_currentpos
sion_int32 filesionpatchlevel
sion_int64 * all_globalranks
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
int _sion_alloc_filedesc_arrays(_sion_filedesc *sion_filedesc)
Allocate memory for the internal sion arrays.
int _sion_free_filedesc_arrays(_sion_filedesc *sion_filedesc)
free memory for the internal sion arrays
sion_int64 * all_currentblocknr
#define SION_FILE_FLAG_READ
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_vcdtype(int sid)
sion_int32 fileptr_exported
sion_int32 _sion_get_endianness_with_flags(sion_int64 flags)
Return endianness including possible choice via flags.
#define SION_FILE_FLAG_POSIX
_sion_flags_store * _sion_parse_flags(const char *flags)
Parse flags and return a flags store with key value pairs.
char * _sion_getenv(const char *name)
void * _sion_vcdtovcon(int sid)
#define SION_FILE_FLAG_ANSI
#define SION_FILE_FLAG_CREATE
#define SION_FILEMODE_READ
sion_int64 * all_startpointers
int _sion_file_close(_sion_fileptr *sion_fileptr)
Close file and destroys fileptr structure.
int _sion_errorprint(int rc, int level, const char *format,...)
Internal SION error.
int _sion_update_fileposition(_sion_filedesc *sion_filedesc)
Update the internal data structure (check fileposition)
int _sion_newvcd(void *data, int type)
sion_int32 currentblocknr
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_FILESTATE_SEROPENRANK
char * _sion_get_multi_filename(const char *fname, int filenumber)
generates the multi filename
int _sion_create_new_block(_sion_filedesc *sion_filedesc)
Create a new block for the internal data structure.
#define SION_FILEDESCRIPTOR
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)
int _sion_init_filedesc(_sion_filedesc *sion_filedesc)
Initialize the sion file description.
#define SION_FILEMODE_WRITE
sion_int32 filesionversion
int _sion_check_on_collective_mode(_sion_filedesc *sion_filedesc)
check if a collective operation are already called,
sion_int64 start_of_varheader
int _sion_flush_file(int sid)
Flush the data to the disk for the current task.
#define SION_FILESTATE_SEROPENMASTER
sion_int64 * all_blocksizes
int _sion_file_flush(_sion_fileptr *sion_fileptr)
Flush data to file.
_sion_filedesc ** multifiles
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