14 #define _XOPEN_SOURCE 700 23 #include <sys/types.h> 30 #if defined(_SION_BGQ) 31 #include <stdio_ext.h> 34 #if defined(_SION_BGP) 35 #include <stdio_ext.h> 40 #include "sion_error_handler.h" 47 #include "sion_hints.h" 56 int _sion_open(
const char *fname,
const char *file_mode,
int *ntasks,
int *nfiles, sion_int64 **chunksizes, sion_int32 *fsblksize,
int **globalranks, FILE **fileptr)
59 int sid=SION_ID_UNDEF;
62 DPRINTFP((1,
"_sion_open", 0,
"enter open of file %s in %s mode\n", fname, file_mode));
65 if ( ! flags_store ) {
66 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_open: could not parse file mode in %s, aborting ...\n", file_mode));
69 if (flags_store->mask&_SION_FMODE_WRITE) {
72 sid=
_sion_open_write(fname,flags_store->mask,ntasks,nfiles,chunksizes,fsblksize,globalranks,fileptr);
76 sid=
_sion_open_read(fname,flags_store->mask,_SION_READ_ALL_OF_MULTI_FILES,ntasks,nfiles,chunksizes,fsblksize,globalranks,fileptr);
80 _sion_flags_destroy_store(&flags_store);
82 DPRINTFP((1,
"_sion_open", 0,
"leave open of file %s in %s mode sid=%d\n", fname, file_mode,sid));
103 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)
108 sion_int64 new_fsblocksize, apiflag;
109 sion_int32 endianness = 0;
114 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: wrong number of tasks specific: ntasks=%d (<0), returning ...\n", *ntasks));
118 if ((chunksizes==NULL) || (*chunksizes==NULL)) {
119 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: chunksizes seems not to be a pointer to an array, returning ...\n"));
123 if ((globalranks==NULL) || (*globalranks==NULL)) {
124 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: globalranks seems not to be a pointer to an array, returning ...\n"));
129 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: write with nfiles > 1 currently not supported (nfiles=%d), returning ...\n",(
int) *nfiles));
134 if (sion_filedesc == NULL) {
135 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)));
138 sion_filedesc->
fname = strdup(fname);
142 sion_filedesc->
sid=sid;
150 DPRINTFP((1,
"sion_open", 0,
" it is a write operation #tasks=%d\n", *ntasks));
157 sion_filedesc->
ntasks = *ntasks;
158 sion_filedesc->
nfiles = 1;
160 sion_filedesc->
prefix = strdup(fname);
171 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot open %s for reading, aborting ...\n", fname));
173 sion_filedesc->
fileptr = sion_fileptr;
178 if((new_fsblocksize<0) || (new_fsblocksize>SION_MAX_FSBLOCKSIZE)) new_fsblocksize=SION_DEFAULT_FSBLOCKSIZE;
179 *fsblksize = new_fsblocksize;
181 DPRINTFP((32,
"_sion_paropen_multi_generic", 0,
"setting fsblksize to %lld\n", new_fsblocksize));
185 for (i = 0; i < *ntasks; i++) {
191 _sion_keyval_check_env(sion_filedesc, file_mode_flags);
193 _sion_alloc_filedesc_all_keyvalptr(sion_filedesc);
196 _sion_calculate_startpointers(sion_filedesc);
207 for (i = 0; i < *ntasks; i++) {
215 sion_filedesc->
rank = 0;
226 *fileptr=sion_filedesc->
fileptr->fileptr;
257 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)
267 if (sion_filedesc == NULL) {
268 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)));
271 sion_filedesc->
fname = strdup(fname);
275 sion_filedesc->
sid=sid;
280 DPRINTFP((1,
"sion_open", 0,
" it is a read operation\n"));
285 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot open %s for reading, aborting ...\n", fname));
287 sion_filedesc->
fileptr = sion_fileptr;
291 if (rc!=SION_SUCCESS) {
292 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot read header from file %s, aborting ...\n", fname));
294 sion_filedesc->
rank = 0;
303 if (rc!=SION_SUCCESS) {
304 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot read header (var part) from file %s, aborting ...\n", fname));
308 _sion_calculate_startpointers(sion_filedesc);
313 if (rc!=SION_SUCCESS) {
314 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot read header (var part block sizes) from file %s, aborting ...\n", fname));
318 _sion_keyval_check_env(sion_filedesc, file_mode_flags);
320 _sion_alloc_filedesc_all_keyvalptr(sion_filedesc);
326 if(read_all==_SION_READ_ALL_OF_MULTI_FILES) {
327 sid=_sion_open_read_master(fname,file_mode_flags,ntasks,nfiles,chunksizes,fsblksize,globalranks,fileptr,sion_filedesc);
329 sid=_sion_open_read_single(fname,file_mode_flags,ntasks,nfiles,chunksizes,fsblksize,globalranks,fileptr,sion_filedesc);
333 for (rank = 0; rank < sion_filedesc->
mapping_size; rank++) {
334 DPRINTFP((2048,
"sion_open", 0,
" mapping[%d] = %d , %d \n", rank,sion_filedesc->
mapping[rank*2+0],sion_filedesc->
mapping[rank*2+1]));
341 sid=_sion_open_read_single(fname,file_mode_flags,ntasks,nfiles,chunksizes,fsblksize,globalranks,fileptr,sion_filedesc);
349 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)
355 sid=sion_filedesc->
sid;
361 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
368 for (i = 0; i < sion_filedesc->
ntasks; i++) {
375 *ntasks = sion_filedesc->
ntasks;
376 *nfiles = sion_filedesc->
nfiles;
379 if (chunksizes != NULL) {
380 sion_int64 *helpptr = NULL;
381 if ((*chunksizes) == NULL) {
382 helpptr = (sion_int64 *) malloc(*ntasks *
sizeof(sion_int64));
383 if (helpptr == NULL) {
384 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure of size %lu (chunksizes), aborting ...\n", (
unsigned long)
sizeof(sion_int64)));
386 *chunksizes = helpptr;
388 helpptr = *chunksizes;
390 for (i = 0; i < *ntasks; i++) {
394 if (globalranks != NULL) {
396 if ((*globalranks) == NULL) {
397 helpptr = (
int *) malloc(*ntasks *
sizeof(
int));
398 if (helpptr == NULL) {
399 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)));
401 *globalranks = helpptr;
403 helpptr = *globalranks;
405 for (i = 0; i < (*ntasks); i++) {
412 *fileptr=sion_filedesc->
fileptr->fileptr;
426 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)
430 int sid_master, subsid, lfile, lrank, filenr;
439 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
446 for (i = 0; i < sion_filedesc->
ntasks; i++) {
454 for (rank = 0; rank < sion_filedesc->
mapping_size; rank++) {
455 DPRINTFP((32,
"sion_open", 0,
" mapping[%d] = %d , %d \n", rank,sion_filedesc->
mapping[rank*2+0],sion_filedesc->
mapping[rank*2+1]));
461 if (sion_filedesc_master == NULL) {
462 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot allocate filedescriptor structure of size %lu (sion_filedesc_master), aborting ...\n",
463 (
unsigned long)
sizeof(sion_filedesc_master)));
466 sion_filedesc_master->
fname = strdup(fname);
472 sion_filedesc_master->
sid=sid_master;
476 if (sion_filedesc_master->
multifiles == NULL) {
477 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure vector of size %lu (sion_filedesc), aborting ...\n",
483 sion_filedesc_master->
multifiles[0]=sion_filedesc;
485 for(filenr=1;filenr<sion_filedesc->
nfiles;filenr++) {
486 int sub_ntasts, sub_nfiles;
487 sion_int32 sub_chunksize;
491 DPRINTFP((32,
"sion_open", 0,
"open now sub file = %d %s\n", filenr, multi_fname));
493 file_mode_flags, _SION_READ_ALL_OF_MULTI_FILES, &sub_ntasts, &sub_nfiles, NULL, &sub_chunksize, NULL, &sub_fileptr);
494 sion_filedesc_sub=_sion_get_filedesc(subsid);
495 sion_filedesc_master->
multifiles[filenr]=sion_filedesc_sub;
496 DPRINTFP((32,
"sion_open", 0,
"sub file = %d %s opened\n", filenr, multi_fname));
505 sion_filedesc_master->
rank = 0;
508 lfile=sion_filedesc_master->
mapping[sion_filedesc_master->
rank*2+0];
509 lrank=sion_filedesc_master->
mapping[sion_filedesc_master->
rank*2+1];
510 sion_filedesc_sub=sion_filedesc_master->
multifiles[lfile];
520 sion_filedesc_master->
nfiles = sion_filedesc_sub->
nfiles;
521 sion_filedesc_master->
flag1 = sion_filedesc_sub->
flag1;
522 sion_filedesc_master->
flag2 = sion_filedesc_sub->
flag2;
524 sion_filedesc_master->
prefix = strdup(sion_filedesc->
prefix);
539 for(filenr=1;filenr<sion_filedesc->
nfiles;filenr++)
544 for (blknum = 0; blknum < sion_filedesc_sub->
all_blockcount[lrank]; blknum++) {
552 sion_filedesc = sion_filedesc_master;
560 *ntasks = sion_filedesc->
ntasks;
561 *nfiles = sion_filedesc->
nfiles;
563 if (chunksizes != NULL) {
564 sion_int64 *helpptr = NULL;
565 if ((*chunksizes) == NULL) {
566 helpptr = (sion_int64 *) malloc(*ntasks *
sizeof(sion_int64));
567 if (helpptr == NULL) {
568 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure of size %lu (chunksizes), aborting ...\n", (
unsigned long)
sizeof(sion_int64)));
570 *chunksizes = helpptr;
572 helpptr = *chunksizes;
574 for (i = 0; i < *ntasks; i++) {
575 lfile=sion_filedesc_master->
mapping[i*2+0]; lrank=sion_filedesc_master->
mapping[i*2+1];
579 if (globalranks != NULL) {
581 if ((*globalranks) == NULL) {
582 helpptr = (
int *) malloc(*ntasks *
sizeof(
int));
583 if (helpptr == NULL) {
584 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)));
586 *globalranks = helpptr;
589 helpptr = *globalranks;
591 for (i = 0; i < (*ntasks); i++) {
592 lfile=sion_filedesc_master->
mapping[i*2+0]; lrank=sion_filedesc_master->
mapping[i*2+1];
599 *fileptr=sion_filedesc->
fileptr->fileptr;
612 int _sion_open_rank(
const char *fname,
const char *file_mode, sion_int64 *chunksize, sion_int32 *fsblksize,
int *rank, FILE **fileptr)
615 int rc=SION_NOT_SUCCESS, sid=SION_ID_UNDEF;
616 int mapping_filenr, mapping_lrank;
623 DPRINTFTS(*rank,
"before open rank");
624 DPRINTFP((1,
"_sion_open_rank", *rank,
"enter open of file %s in %s mode\n", fname, file_mode));
628 if (sion_filedesc == NULL) {
629 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)));
632 sion_filedesc->
fname = strdup(fname);
636 sion_filedesc->
sid=sid;
639 if ( ! flags_store ) {
640 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));
646 if (flags_store->mask&_SION_FMODE_WRITE) {
649 DPRINTFP((1,
"_sion_open_rank", *rank,
" it is a write operation\n"));
651 _sion_flags_destroy_store(&flags_store);
652 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"_sion_open_rank: %s for writing currently not supported, aborting ...", fname));
655 _sion_flags_destroy_store(&flags_store);
658 DPRINTFTS(*rank,
"start open read");
659 DPRINTFP((1,
"_sion_open_rank", *rank,
" it is a read operation rank=%d\n",*rank));
664 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"_sion_open_rank: cannot open %s for reading, aborting ...", fname));
666 sion_filedesc->
fileptr = sion_fileptr;
667 DPRINTFTS(*rank,
"start after open file 1");
669 DPRINTFTS(*rank,
"start after read header fix part 1");
670 if (rc==SION_NOT_SUCCESS) {
671 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"_sion_open_rank: cannot read header from file %s, aborting ...", fname));
673 sion_filedesc->
rank = *rank;
682 DPRINTFTS(*rank,
"start after read header var part 1");
683 if (rc==SION_NOT_SUCCESS) {
684 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));
687 DPRINTFP((1,
"_sion_open_rank", *rank,
"found number of files %d in %s rank=%d\n", sion_filedesc->
nfiles,sion_filedesc->
fname,*rank));
688 if(sion_filedesc->
nfiles>1) {
691 DPRINTFTS(*rank,
"start after read mapping rank 1");
692 if (rc==SION_NOT_SUCCESS) {
693 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"cannot read var part mapping header from file %s, aborting ...", fname));
695 mapping_filenr = sion_filedesc->
mapping[0];
696 mapping_lrank = sion_filedesc->
mapping[1];
697 DPRINTFP((1,
"_sion_open_rank", *rank,
"data for rank %d is in file %d (lrank=%d)\n", *rank, mapping_filenr,mapping_lrank));
698 DPRINTFTS(*rank,
"start after read mapping 1");
701 if(mapping_filenr>0) {
707 DPRINTFTS(*rank,
"start after close file 1");
712 DPRINTFP((1,
"_sion_open_rank", *rank,
"open file sion_filedesc->fname=%s fname=%s rank=%d\n", sion_filedesc->
fname,fname,*rank));
716 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"_sion_open_rank: cannot open %s for reading, aborting ...", fname));
718 sion_filedesc->
fileptr = sion_fileptr;
719 DPRINTFTS(*rank,
"start after open file i");
722 if (rc==SION_NOT_SUCCESS) {
723 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"sion_open: cannot read header from file %s, aborting ...", fname));
725 DPRINTFTS(*rank,
"start after read header fix part i");
728 if (rc==SION_NOT_SUCCESS) {
729 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"cannot var mapping data from file %s, aborting ...", fname));
731 DPRINTFTS(*rank,
"start after read header var part i");
734 sion_filedesc->
fname = strdup(fname);
740 DPRINTFP((1,
"_sion_open_rank", *rank,
"max blocks=%d\n", sion_filedesc->
maxusedchunks));
743 sion_filedesc->
prefix = strdup(&prefix);
745 _sion_calculate_startpointers(sion_filedesc);
747 sion_filedesc->
rank = mapping_lrank;
750 if (rc==SION_NOT_SUCCESS) {
751 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,sion_filedesc->
rank,
"cannot read header from file %s, aborting ...", fname));
753 DPRINTFTS(*rank,
"start after read header blocksizes i");
771 *fileptr=sion_filedesc->
fileptr->fileptr;
781 DPRINTFP((1,
"_sion_open_rank", 0,
"leave open of file %s in %s mode\n", fname, file_mode));
782 DPRINTFTS(*rank,
"after open rank");
792 int rc = SION_SUCCESS;
793 int blknum, rank, currentrank, mapping_size;
794 #ifdef SION_SERIAL_MASTER 800 DPRINTFP((1,
"_sion_close", -1,
"enter close sid=%d currentpos=%15lld\n", sion_filedesc->
sid, sion_filedesc->
currentpos));
808 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));
814 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));
818 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)));
825 currentrank = sion_filedesc->
rank;
829 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
835 for (blknum = 0; blknum < sion_filedesc->
ntasks; blknum++)
846 for (blknum = 0; blknum < sion_filedesc->
maxusedchunks; blknum++) {
847 for (rank = 0; rank < sion_filedesc->
ntasks; rank++) {
851 DPRINTFP((1,
"_sion_close", -1,
852 " blocksize rank %2d blk %2d -> %lld\n",
874 #ifdef SION_SERIAL_MASTER 878 for(filenr=1;filenr<sion_filedesc->
nfiles;filenr++) {
879 _sion_close(sion_filedesc->
multifiles[filenr]);
881 _sion_free_filedesc(sion_filedesc->
multifiles[filenr]);
891 #ifdef SION_SERIAL_MASTER 896 DPRINTFP((1,
"_sion_close", -1,
"leave close sid=%d\n", sion_filedesc->
sid));
912 newfname = malloc(SION_FILENAME_LENGTH);
913 if (newfname == NULL) {
914 _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_get_multi_filename: Cannot allocate string newfname\n");
918 if(strlen(fname)<SION_FILENAME_LENGTH-7) {
919 sprintf(newfname,
"%s.%06d", fname, filenumber);
921 _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_get_multi_filename: filename too long\n");
926 strcpy(newfname, fname);
941 int rc = SION_SUCCESS;
945 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_flush_file: invalid sion_filedesc, aborting %d ...\n", sid));
947 DPRINTFP((32,
"_sion_flush_file", sion_filedesc->
rank,
"flush sid=%d\n", sid));
965 int rc = SION_SUCCESS;
967 DPRINTFP((2,
"_sion_update_fileposition", sion_filedesc->
rank,
"enter\n"));
985 DPRINTFP((2,
"_sion_update_fileposition", sion_filedesc->
rank,
"leave pos=%lld usecoll=%d collector=%d rank\n",
997 int rc = SION_SUCCESS;
1031 int rc = SION_SUCCESS;
1032 sion_int64 byteswritten;
1034 DPRINTFP((2,
"_sion_flush_block", sion_filedesc->
rank,
"enter fileposition=%lld\n", sion_filedesc->
currentpos));
1038 DPRINTFP((2,
"_sion_flush_block", sion_filedesc->
rank,
"after update fileposition=%lld\n", sion_filedesc->
currentpos));
1044 if (byteswritten > 0) {
1047 DPRINTFP((2,
"_sion_flush_block", sion_filedesc->
rank,
1048 "flushed lastchunknr->%d currentblocknr=%d byteswritten=%lld fileposition=%lld startpos=%lld (%lld)\n",
1052 rc = SION_NOT_SUCCESS;
1053 DPRINTFP((2,
"_sion_flush_block", sion_filedesc->
rank,
"not flushed lastchunknr->%d byteswritten=%lld fileposition=%lld startpos=%lld (%lld)\n",
1057 DPRINTFP((2,
"_sion_flush_block", sion_filedesc->
rank,
"leave\n"));
1070 int rc = SION_SUCCESS;
1072 DPRINTFP((2,
"_sion_create_new_block", _SION_DEFAULT_RANK,
"enter alloc \n"));
1081 _sion_apply_hints(sion_filedesc,SION_HINTS_FREE_TYPE_CHUNK);
1087 rc = _sion_apply_hints(sion_filedesc,SION_HINTS_ACCESS_TYPE_CHUNK);
1095 DPRINTFP((2,
"_sion_create_new_block", _SION_DEFAULT_RANK,
"skip to next already allocated block currentblocknr=%d lastchunknr->%d currentpos=%lld\n",
1110 _sion_apply_hints(sion_filedesc,SION_HINTS_FREE_TYPE_CHUNK);
1118 rc = _sion_apply_hints(sion_filedesc,SION_HINTS_ACCESS_TYPE_CHUNK);
1125 DPRINTFP((2,
"_sion_create_new_block", _SION_DEFAULT_RANK,
"skip to new allocated block currentblocknr=%d lastchunknr->%d currentpos=%lld\n",
1138 sion_int32 endianness = 0;
1140 DPRINTFP((2,
"_sion_get_endianness_flags", -1,
"enter with flags 0x%x\n", flags));
1145 endianness |= endianness << 24;
1146 if (flags & _SION_FMODE_ENDIANNESS_SET) {
1148 if (flags & _SION_FMODE_ENDIANNESS_BIG) {
1149 endianness |= 0x0101 << 8;
1152 else if (endianness & 1) {
1154 endianness |= 0x0101 << 8;
1157 DPRINTFP((2,
"_sion_get_endianness_flags", -1,
"leave with endianness 0x%x\n", endianness));
1162 #define DFUNCTION "_sion_getenv" 1167 char *name_with_prefix = NULL;
1168 char *getenv_result = NULL;
1169 const int full_len = strlen(name) + strlen(SION_LVERSION_PREFIX) + 1;
1171 DPRINTFP((2, DFUNCTION, -1,
"enter: name = %s\n", name));
1173 name_with_prefix = (
char *)malloc(full_len);
1174 sprintf(name_with_prefix,
"%s%s", SION_LVERSION_PREFIX, name);
1176 getenv_result = getenv(name_with_prefix);
1177 free(name_with_prefix);
1179 DPRINTFP((2, DFUNCTION, -1,
"leave: getenv_result = %s\n", getenv_result));
1181 return getenv_result;
1197 _sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_alloc_io_info: cannot allocate memory of size %lu (p_fn), aborting ...\n",
1205 p->names = (
const char **) malloc(p_nf *
sizeof(
char *));
1206 if (p->names == NULL) {
1207 _sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_alloc_io_info: cannot allocate memory of size %lu (names), aborting ...\n",
1208 (
unsigned long) p_nf *
sizeof(
char *));
1213 p->sizes = (
size_t *) malloc(p_nf *
sizeof(
size_t));
1214 if (p->sizes == NULL) {
1215 _sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_alloc_io_info: cannot allocate memory of size %lu (sizes), aborting ...\n",
1216 (
unsigned long) p_nf *
sizeof(
size_t));
1222 p->roles = (
int *) malloc(p_nf *
sizeof(
int));
1223 if (p->roles == NULL) {
1224 _sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_alloc_io_info: cannot allocate memory of size %lu (roles), aborting ...\n",
1225 (
unsigned long) p_nf *
sizeof(
int));
1232 for(i=0;i<p_nf;i++) {
1235 p->roles[i]=SION_ROLE_NONE;
1247 int rc=SION_SUCCESS;
1249 if(p->names!=NULL) free(p->names);
1250 if(p->sizes!=NULL) free(p->sizes);
1251 if(p->roles!=NULL) free(p->roles);
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_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_free_io_info(sion_io_stat_t *p)
frees an io_info data structure
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_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)
_sion_filedesc * _sion_alloc_filedesc(void)
Allocates memory for internal sion structure.
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
sion_io_stat_t * _sion_alloc_io_info(int p_nf)
allocates an io_info data structure for nfiles files