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> 46 #include "sion_error_handler.h" 53 #include "sion_hints.h" 61 int _sion_open(
const char *fname,
const char *file_mode,
int *ntasks,
int *nfiles, sion_int64 **chunksizes, sion_int32 *fsblksize,
int **globalranks, FILE **fileptr)
64 int sid=SION_ID_UNDEF;
67 DPRINTFP((1,
"_sion_open", 0,
"enter open of file %s in %s mode\n", fname, file_mode));
70 if ( ! flags_store ) {
71 return(_sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_open: could not parse file mode in %s, aborting ...\n", file_mode));
74 if (flags_store->mask&_SION_FMODE_WRITE) {
77 sid=
_sion_open_write(fname,flags_store->mask,ntasks,nfiles,chunksizes,fsblksize,globalranks,fileptr);
81 sid=
_sion_open_read(fname,flags_store->mask,_SION_READ_ALL_OF_MULTI_FILES,ntasks,nfiles,chunksizes,fsblksize,globalranks,fileptr);
85 _sion_flags_destroy_store(&flags_store);
87 DPRINTFP((1,
"_sion_open", 0,
"leave open of file %s in %s mode sid=%d\n", fname, file_mode,sid));
108 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)
113 sion_int64 new_fsblocksize, apiflag;
114 sion_int32 endianness = 0;
119 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: wrong number of tasks specific: ntasks=%d (<0), returning ...\n", *ntasks));
123 if ((chunksizes==NULL) || (*chunksizes==NULL)) {
124 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: chunksizes seems not to be a pointer to an array, returning ...\n"));
128 if ((globalranks==NULL) || (*globalranks==NULL)) {
129 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: globalranks seems not to be a pointer to an array, returning ...\n"));
134 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: write with nfiles > 1 currently not supported (nfiles=%d), returning ...\n",(
int) *nfiles));
139 if (sion_filedesc == NULL) {
140 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)));
143 sion_filedesc->
fname = strdup(fname);
147 sion_filedesc->
sid=sid;
155 DPRINTFP((1,
"sion_open", 0,
" it is a write operation #tasks=%d\n", *ntasks));
162 sion_filedesc->
ntasks = *ntasks;
163 sion_filedesc->
nfiles = 1;
165 sion_filedesc->
prefix = strdup(fname);
176 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot open %s for reading, aborting ...\n", fname));
178 sion_filedesc->
fileptr = sion_fileptr;
183 if((new_fsblocksize<0) || (new_fsblocksize>SION_MAX_FSBLOCKSIZE)) new_fsblocksize=SION_DEFAULT_FSBLOCKSIZE;
184 *fsblksize = new_fsblocksize;
186 DPRINTFP((32,
"_sion_paropen_multi_generic", 0,
"setting fsblksize to %lld\n", new_fsblocksize));
190 for (i = 0; i < *ntasks; i++) {
196 _sion_keyval_check_env(sion_filedesc, file_mode_flags);
198 _sion_alloc_filedesc_all_keyvalptr(sion_filedesc);
201 _sion_calculate_startpointers(sion_filedesc);
212 for (i = 0; i < *ntasks; i++) {
220 sion_filedesc->
rank = 0;
231 *fileptr=sion_filedesc->
fileptr->fileptr;
262 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)
272 if (sion_filedesc == NULL) {
273 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)));
276 sion_filedesc->
fname = strdup(fname);
280 sion_filedesc->
sid=sid;
285 DPRINTFP((1,
"sion_open", 0,
" it is a read operation\n"));
290 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot open %s for reading, aborting ...\n", fname));
292 sion_filedesc->
fileptr = sion_fileptr;
296 if (rc!=SION_SUCCESS) {
297 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot read header from file %s, aborting ...\n", fname));
299 sion_filedesc->
rank = 0;
308 if (rc!=SION_SUCCESS) {
309 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot read header (var part) from file %s, aborting ...\n", fname));
313 _sion_calculate_startpointers(sion_filedesc);
318 if (rc!=SION_SUCCESS) {
319 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot read header (var part block sizes) from file %s, aborting ...\n", fname));
323 _sion_keyval_check_env(sion_filedesc, file_mode_flags);
325 _sion_alloc_filedesc_all_keyvalptr(sion_filedesc);
331 if(read_all==_SION_READ_ALL_OF_MULTI_FILES) {
332 sid=_sion_open_read_master(fname,file_mode_flags,ntasks,nfiles,chunksizes,fsblksize,globalranks,fileptr,sion_filedesc);
334 sid=_sion_open_read_single(fname,file_mode_flags,ntasks,nfiles,chunksizes,fsblksize,globalranks,fileptr,sion_filedesc);
338 for (rank = 0; rank < sion_filedesc->
mapping_size; rank++) {
339 DPRINTFP((2048,
"sion_open", 0,
" mapping[%d] = %d , %d \n", rank,sion_filedesc->
mapping[rank*2+0],sion_filedesc->
mapping[rank*2+1]));
346 sid=_sion_open_read_single(fname,file_mode_flags,ntasks,nfiles,chunksizes,fsblksize,globalranks,fileptr,sion_filedesc);
354 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)
360 sid=sion_filedesc->
sid;
366 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
373 for (i = 0; i < sion_filedesc->
ntasks; i++) {
380 *ntasks = sion_filedesc->
ntasks;
381 *nfiles = sion_filedesc->
nfiles;
384 if (chunksizes != NULL) {
385 sion_int64 *helpptr = NULL;
386 if ((*chunksizes) == NULL) {
387 helpptr = (sion_int64 *) malloc(*ntasks *
sizeof(sion_int64));
388 if (helpptr == NULL) {
389 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure of size %lu (chunksizes), aborting ...\n", (
unsigned long)
sizeof(sion_int64)));
391 *chunksizes = helpptr;
393 helpptr = *chunksizes;
395 for (i = 0; i < *ntasks; i++) {
399 if (globalranks != NULL) {
401 if ((*globalranks) == NULL) {
402 helpptr = (
int *) malloc(*ntasks *
sizeof(
int));
403 if (helpptr == NULL) {
404 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)));
406 *globalranks = helpptr;
408 helpptr = *globalranks;
410 for (i = 0; i < (*ntasks); i++) {
417 *fileptr=sion_filedesc->
fileptr->fileptr;
431 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)
435 int sid_master, subsid, lfile, lrank, filenr;
444 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
451 for (i = 0; i < sion_filedesc->
ntasks; i++) {
459 for (rank = 0; rank < sion_filedesc->
mapping_size; rank++) {
460 DPRINTFP((32,
"sion_open", 0,
" mapping[%d] = %d , %d \n", rank,sion_filedesc->
mapping[rank*2+0],sion_filedesc->
mapping[rank*2+1]));
466 if (sion_filedesc_master == NULL) {
467 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"sion_open: cannot allocate filedescriptor structure of size %lu (sion_filedesc_master), aborting ...\n",
468 (
unsigned long)
sizeof(sion_filedesc_master)));
471 sion_filedesc_master->
fname = strdup(fname);
477 sion_filedesc_master->
sid=sid_master;
481 if (sion_filedesc_master->
multifiles == NULL) {
482 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure vector of size %lu (sion_filedesc), aborting ...\n",
488 sion_filedesc_master->
multifiles[0]=sion_filedesc;
490 for(filenr=1;filenr<sion_filedesc->
nfiles;filenr++) {
491 int sub_ntasts, sub_nfiles;
492 sion_int32 sub_chunksize;
496 DPRINTFP((32,
"sion_open", 0,
"open now sub file = %d %s\n", filenr, multi_fname));
498 file_mode_flags, _SION_READ_ALL_OF_MULTI_FILES, &sub_ntasts, &sub_nfiles, NULL, &sub_chunksize, NULL, &sub_fileptr);
499 sion_filedesc_sub=_sion_get_filedesc(subsid);
500 sion_filedesc_master->
multifiles[filenr]=sion_filedesc_sub;
501 DPRINTFP((32,
"sion_open", 0,
"sub file = %d %s opened\n", filenr, multi_fname));
510 sion_filedesc_master->
rank = 0;
513 lfile=sion_filedesc_master->
mapping[sion_filedesc_master->
rank*2+0];
514 lrank=sion_filedesc_master->
mapping[sion_filedesc_master->
rank*2+1];
515 sion_filedesc_sub=sion_filedesc_master->
multifiles[lfile];
525 sion_filedesc_master->
nfiles = sion_filedesc_sub->
nfiles;
526 sion_filedesc_master->
flag1 = sion_filedesc_sub->
flag1;
527 sion_filedesc_master->
flag2 = sion_filedesc_sub->
flag2;
529 sion_filedesc_master->
prefix = strdup(sion_filedesc->
prefix);
544 for(filenr=1;filenr<sion_filedesc->
nfiles;filenr++)
549 for (blknum = 0; blknum < sion_filedesc_sub->
all_blockcount[lrank]; blknum++) {
557 sion_filedesc = sion_filedesc_master;
565 *ntasks = sion_filedesc->
ntasks;
566 *nfiles = sion_filedesc->
nfiles;
568 if (chunksizes != NULL) {
569 sion_int64 *helpptr = NULL;
570 if ((*chunksizes) == NULL) {
571 helpptr = (sion_int64 *) malloc(*ntasks *
sizeof(sion_int64));
572 if (helpptr == NULL) {
573 return(_sion_errorprint(SION_ID_UNDEF,_SION_ERROR_RETURN,
"cannot allocate filedescriptor structure of size %lu (chunksizes), aborting ...\n", (
unsigned long)
sizeof(sion_int64)));
575 *chunksizes = helpptr;
577 helpptr = *chunksizes;
579 for (i = 0; i < *ntasks; i++) {
580 lfile=sion_filedesc_master->
mapping[i*2+0]; lrank=sion_filedesc_master->
mapping[i*2+1];
584 if (globalranks != NULL) {
586 if ((*globalranks) == NULL) {
587 helpptr = (
int *) malloc(*ntasks *
sizeof(
int));
588 if (helpptr == NULL) {
589 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)));
591 *globalranks = helpptr;
594 helpptr = *globalranks;
596 for (i = 0; i < (*ntasks); i++) {
597 lfile=sion_filedesc_master->
mapping[i*2+0]; lrank=sion_filedesc_master->
mapping[i*2+1];
604 *fileptr=sion_filedesc->
fileptr->fileptr;
617 int _sion_open_rank(
const char *fname,
const char *file_mode, sion_int64 *chunksize, sion_int32 *fsblksize,
int *rank, FILE **fileptr)
620 int rc=SION_NOT_SUCCESS, sid=SION_ID_UNDEF;
621 int mapping_filenr, mapping_lrank;
628 DPRINTFTS(*rank,
"before open rank");
629 DPRINTFP((1,
"_sion_open_rank", *rank,
"enter open of file %s in %s mode\n", fname, file_mode));
631 prefix = calloc(SION_FILENAME_LENGTH,1);
632 if (prefix == NULL) {
633 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));
638 if (sion_filedesc == NULL) {
640 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)));
643 sion_filedesc->
fname = strdup(fname);
647 sion_filedesc->
sid=sid;
650 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);
665 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"_sion_open_rank: %s for writing currently not supported, aborting ...", fname));
670 DPRINTFTS(*rank,
"start open read");
671 DPRINTFP((1,
"_sion_open_rank", *rank,
" it is a read operation rank=%d\n",*rank));
676 _sion_flags_destroy_store(&flags_store);
678 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"_sion_open_rank: cannot open %s for reading, aborting ...", fname));
680 sion_filedesc->
fileptr = sion_fileptr;
681 DPRINTFTS(*rank,
"start after open file 1");
683 DPRINTFTS(*rank,
"start after read header fix part 1");
684 if (rc==SION_NOT_SUCCESS) {
685 _sion_flags_destroy_store(&flags_store);
687 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"_sion_open_rank: cannot read header from file %s, aborting ...", fname));
689 sion_filedesc->
rank = *rank;
698 DPRINTFTS(*rank,
"start after read header var part 1");
699 if (rc==SION_NOT_SUCCESS) {
700 _sion_flags_destroy_store(&flags_store);
702 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));
705 DPRINTFP((1,
"_sion_open_rank", *rank,
"found number of files %d in %s rank=%d\n", sion_filedesc->
nfiles,sion_filedesc->
fname,*rank));
706 if(sion_filedesc->
nfiles>1) {
709 DPRINTFTS(*rank,
"start after read mapping rank 1");
710 if (rc==SION_NOT_SUCCESS) {
711 _sion_flags_destroy_store(&flags_store);
713 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"cannot read var part mapping header from file %s, aborting ...", fname));
715 mapping_filenr = sion_filedesc->
mapping[0];
716 mapping_lrank = sion_filedesc->
mapping[1];
717 DPRINTFP((1,
"_sion_open_rank", *rank,
"data for rank %d is in file %d (lrank=%d)\n", *rank, mapping_filenr,mapping_lrank));
718 DPRINTFTS(*rank,
"start after read mapping 1");
721 if(mapping_filenr>0) {
727 DPRINTFTS(*rank,
"start after close file 1");
732 DPRINTFP((1,
"_sion_open_rank", *rank,
"open file sion_filedesc->fname=%s fname=%s rank=%d\n", sion_filedesc->
fname,fname,*rank));
736 _sion_flags_destroy_store(&flags_store);
738 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"_sion_open_rank: cannot open %s for reading, aborting ...", fname));
740 sion_filedesc->
fileptr = sion_fileptr;
741 DPRINTFTS(*rank,
"start after open file i");
744 if (rc==SION_NOT_SUCCESS) {
745 _sion_flags_destroy_store(&flags_store);
747 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"sion_open: cannot read header from file %s, aborting ...", fname));
749 DPRINTFTS(*rank,
"start after read header fix part i");
752 if (rc==SION_NOT_SUCCESS) {
753 _sion_flags_destroy_store(&flags_store);
755 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,*rank,
"cannot var mapping data from file %s, aborting ...", fname));
757 DPRINTFTS(*rank,
"start after read header var part i");
760 sion_filedesc->
fname = strdup(fname);
766 DPRINTFP((1,
"_sion_open_rank", *rank,
"max blocks=%d\n", sion_filedesc->
maxusedchunks));
769 sion_filedesc->
prefix = strdup(prefix);
771 _sion_calculate_startpointers(sion_filedesc);
773 sion_filedesc->
rank = mapping_lrank;
776 if (rc==SION_NOT_SUCCESS) {
777 _sion_flags_destroy_store(&flags_store);
779 return(_sion_errorprint_on_rank(SION_ID_UNDEF,_SION_ERROR_RETURN,sion_filedesc->
rank,
"cannot read header from file %s, aborting ...", fname));
781 DPRINTFTS(*rank,
"start after read header blocksizes i");
799 *fileptr=sion_filedesc->
fileptr->fileptr;
810 _sion_flags_destroy_store(&flags_store);
813 DPRINTFP((1,
"_sion_open_rank", 0,
"leave open of file %s in %s mode\n", fname, file_mode));
814 DPRINTFTS(*rank,
"after open rank");
824 int rc = SION_SUCCESS;
825 int blknum, rank, currentrank, mapping_size;
826 #ifdef SION_SERIAL_MASTER 832 DPRINTFP((1,
"_sion_close", -1,
"enter close sid=%d currentpos=%15lld\n", sion_filedesc->
sid, sion_filedesc->
currentpos));
840 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));
846 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));
850 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)));
857 currentrank = sion_filedesc->
rank;
861 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
867 for (blknum = 0; blknum < sion_filedesc->
ntasks; blknum++)
878 for (blknum = 0; blknum < sion_filedesc->
maxusedchunks; blknum++) {
879 for (rank = 0; rank < sion_filedesc->
ntasks; rank++) {
883 DPRINTFP((1,
"_sion_close", -1,
884 " blocksize rank %2d blk %2d -> %lld\n",
906 #ifdef SION_SERIAL_MASTER 910 for(filenr=1;filenr<sion_filedesc->
nfiles;filenr++) {
911 _sion_close(sion_filedesc->
multifiles[filenr]);
913 _sion_free_filedesc(sion_filedesc->
multifiles[filenr]);
923 #ifdef SION_SERIAL_MASTER 928 DPRINTFP((1,
"_sion_close", -1,
"leave close sid=%d\n", sion_filedesc->
sid));
944 newfname = malloc(SION_FILENAME_LENGTH);
945 if (newfname == NULL) {
946 _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_get_multi_filename: Cannot allocate string newfname\n");
950 if(strlen(fname)<SION_FILENAME_LENGTH-7) {
951 sprintf(newfname,
"%s.%06d", fname, filenumber);
953 _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_get_multi_filename: filename too long\n");
958 strcpy(newfname, fname);
973 int rc = SION_SUCCESS;
977 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_flush_file: invalid sion_filedesc, aborting %d ...\n", sid));
979 DPRINTFP((32,
"_sion_flush_file", sion_filedesc->
rank,
"flush sid=%d\n", sid));
997 int rc = SION_SUCCESS;
999 DPRINTFP((2,
"_sion_update_fileposition", sion_filedesc->
rank,
"enter\n"));
1017 DPRINTFP((2,
"_sion_update_fileposition", sion_filedesc->
rank,
"leave pos=%lld usecoll=%d collector=%d rank\n",
1029 int rc = SION_SUCCESS;
1063 int rc = SION_SUCCESS;
1064 sion_int64 byteswritten;
1066 DPRINTFP((2,
"_sion_flush_block", sion_filedesc->
rank,
"enter fileposition=%lld\n", sion_filedesc->
currentpos));
1070 DPRINTFP((2,
"_sion_flush_block", sion_filedesc->
rank,
"after update fileposition=%lld\n", sion_filedesc->
currentpos));
1076 if (byteswritten > 0) {
1079 DPRINTFP((2,
"_sion_flush_block", sion_filedesc->
rank,
1080 "flushed lastchunknr->%d currentblocknr=%d byteswritten=%lld fileposition=%lld startpos=%lld (%lld)\n",
1084 rc = SION_NOT_SUCCESS;
1085 DPRINTFP((2,
"_sion_flush_block", sion_filedesc->
rank,
"not flushed lastchunknr->%d byteswritten=%lld fileposition=%lld startpos=%lld (%lld)\n",
1089 DPRINTFP((2,
"_sion_flush_block", sion_filedesc->
rank,
"leave\n"));
1102 int rc = SION_SUCCESS;
1104 DPRINTFP((2,
"_sion_create_new_block", _SION_DEFAULT_RANK,
"enter alloc \n"));
1113 _sion_apply_hints(sion_filedesc,SION_HINTS_FREE_TYPE_CHUNK);
1119 rc = _sion_apply_hints(sion_filedesc,SION_HINTS_ACCESS_TYPE_CHUNK);
1127 DPRINTFP((2,
"_sion_create_new_block", _SION_DEFAULT_RANK,
"skip to next already allocated block currentblocknr=%d lastchunknr->%d currentpos=%lld\n",
1142 _sion_apply_hints(sion_filedesc,SION_HINTS_FREE_TYPE_CHUNK);
1150 rc = _sion_apply_hints(sion_filedesc,SION_HINTS_ACCESS_TYPE_CHUNK);
1157 DPRINTFP((2,
"_sion_create_new_block", _SION_DEFAULT_RANK,
"skip to new allocated block currentblocknr=%d lastchunknr->%d currentpos=%lld\n",
1170 sion_int32 endianness = 0;
1172 DPRINTFP((2,
"_sion_get_endianness_flags", -1,
"enter with flags 0x%x\n", flags));
1177 endianness |= endianness << 24;
1178 if (flags & _SION_FMODE_ENDIANNESS_SET) {
1180 if (flags & _SION_FMODE_ENDIANNESS_BIG) {
1181 endianness |= 0x0101 << 8;
1184 else if (endianness & 1) {
1186 endianness |= 0x0101 << 8;
1189 DPRINTFP((2,
"_sion_get_endianness_flags", -1,
"leave with endianness 0x%x\n", endianness));
1194 #define DFUNCTION "_sion_getenv" 1199 char *name_with_prefix = NULL;
1200 char *getenv_result = NULL;
1201 const int full_len = strlen(name) + strlen(SION_LVERSION_PREFIX) + 1;
1203 DPRINTFP((2, DFUNCTION, -1,
"enter: name = %s\n", name));
1205 name_with_prefix = (
char *)malloc(full_len);
1206 sprintf(name_with_prefix,
"%s%s", SION_LVERSION_PREFIX, name);
1208 getenv_result = getenv(name_with_prefix);
1209 free(name_with_prefix);
1211 DPRINTFP((2, DFUNCTION, -1,
"leave: getenv_result = %s\n", getenv_result));
1213 return getenv_result;
1229 _sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_alloc_io_info: cannot allocate memory of size %lu (p_fn), aborting ...\n",
1237 p->names = (
const char **) malloc(p_nf *
sizeof(
char *));
1238 if (p->names == NULL) {
1239 _sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_alloc_io_info: cannot allocate memory of size %lu (names), aborting ...\n",
1240 (
unsigned long) p_nf *
sizeof(
char *));
1245 p->sizes = (
size_t *) malloc(p_nf *
sizeof(
size_t));
1246 if (p->sizes == NULL) {
1247 _sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_alloc_io_info: cannot allocate memory of size %lu (sizes), aborting ...\n",
1248 (
unsigned long) p_nf *
sizeof(
size_t));
1254 p->roles = (
int *) malloc(p_nf *
sizeof(
int));
1255 if (p->roles == NULL) {
1256 _sion_errorprint(SION_ID_NOT_VALID,_SION_ERROR_RETURN,
"_sion_alloc_io_info: cannot allocate memory of size %lu (roles), aborting ...\n",
1257 (
unsigned long) p_nf *
sizeof(
int));
1264 for(i=0;i<p_nf;i++) {
1267 p->roles[i]=SION_ROLE_NONE;
1279 int rc=SION_SUCCESS;
1281 if(p->names!=NULL) free(p->names);
1282 if(p->sizes!=NULL) free(p->sizes);
1283 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_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_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)
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