24 #include "sion_error_handler.h" 36 #define DFUNCTION "_sion_seek_on_all_ranks_read" 53 sion_int64 posinblk ) {
54 int rc = SION_SUCCESS;
57 DPRINTFP((2, DFUNCTION, -1,
"enter seek r=%d b=%d p=%ld fn=%s\n",
58 rank,blocknr, (
long) posinblk,sion_filedesc->
fname));
62 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
63 "sion_seek: internal error, data structure not initialized, aborting ...\n"));
69 DPRINTFP((32, DFUNCTION, -1,
"rank has changed %d -> %d\n", sion_filedesc->
rank, rank));
71 if ((rank<0) || (rank >= sion_filedesc->
ntasks)) {
72 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: parameter rank %d (max. %d) out of range, aborting ...\n",
73 rank, sion_filedesc->
ntasks));
87 sion_filedesc->
rank = rank;
97 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
118 if(posinblk>=sion_filedesc->
blocksizes[blocknr]) {
124 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: seek after end of file, returning ...\n"));
137 DPRINTFP((2, DFUNCTION, -1,
"leave seek rc=%d\n",rc));
144 #define DFUNCTION "_sion_seek_on_all_ranks_read_master" 161 sion_int64 posinblk ) {
162 int rc = SION_SUCCESS;
163 int blknum, lfile, lrank;
165 DPRINTFP((2, DFUNCTION, -1,
"enter seek r=%d b=%d p=%ld fn=%s\n",
166 rank,blocknr, (
long) posinblk,sion_filedesc->
fname));
171 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
172 "sion_seek: internal error, data structure not initialized, aborting ...\n"));
177 lfile=sion_filedesc->
mapping[sion_filedesc->
rank*2+0];
178 lrank=sion_filedesc->
mapping[sion_filedesc->
rank*2+1];
183 if ((rank<0) || (rank >= sion_filedesc->
ntasks)) {
184 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: parameter rank %d (max. %d) out of range, aborting ...\n",
185 rank, sion_filedesc->
ntasks));
200 sion_filedesc->
rank = rank;
203 lfile=sion_filedesc->
mapping[sion_filedesc->
rank*2+0];
204 lrank=sion_filedesc->
mapping[sion_filedesc->
rank*2+1];
218 DPRINTFP((32, DFUNCTION, -1,
"switch to file %d and lrank %d currentpos=%ld, currentblocknr=%d\n",lfile, lrank,(
long) sion_filedesc->
currentpos, sion_filedesc->
currentblocknr ));
236 if(posinblk>=sion_filedesc->
blocksizes[blocknr]) {
237 posinblk=0;blocknr++;
239 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: seek after end of file, returning ...\n"));
251 DPRINTFP((2, DFUNCTION, -1,
"leave seek rc=%d\n",rc));
259 #define DFUNCTION "_sion_seek_on_current_rank_read" 274 sion_int64 posinblk ) {
275 int rc = SION_SUCCESS;
277 sion_int64 newposinblk=-1;
279 DPRINTFP((2, DFUNCTION, -1,
"enter seek r=%d b=%d p=%ld fn=%s\n",rank,blocknr, (
long) posinblk,sion_filedesc->
fname));
284 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
285 "sion_seek: parameter rank is different from current rank in parallel openened file, returning ...\n"));
292 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: error in searching abs pos, returning ...\n"));
293 }
else posinblk=newposinblk;
294 DPRINTFP((32, DFUNCTION, -1,
"sion_absolute_pos newblocknr=%d newpos=%ld fn=%s\n",newblocknr, (
long) newposinblk, sion_filedesc->
fname));
299 return _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_RETURN,
"sion_seek: error in searching end pos, returning ...\n");
301 else { posinblk = newposinblk;
303 DPRINTFP((32, DFUNCTION, -1,
"sion_end_pos newblocknr=%d newpos=%ld fn=%s\n", newblocknr, (
long)newposinblk, sion_filedesc->
fname));
308 DPRINTFP((32, DFUNCTION, -1,
"sion_current_blk newblocknr=%d newpos=%ld fn=%s\n",newblocknr, (
long) newposinblk, sion_filedesc->
fname));
311 if ( (blocknr >= 0) && (blocknr <= sion_filedesc->lastchunknr) ) {
314 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
315 "sion_seek: parameter chunk number (%d) is out of range (0 .. %d), returning ...\n",
318 DPRINTFP((32, DFUNCTION, -1,
"new blocknr newblocknr=%d newpos=%ld fn=%s\n",newblocknr, (
long) newposinblk, sion_filedesc->
fname));
327 DPRINTFP((32, DFUNCTION, -1,
"sion_current_pos newblocknr=%d newpos=%ld fn=%s %ld %ld %ld %ld\n",newblocknr, (
long) newposinblk, sion_filedesc->
fname,
332 ( (posinblk >= 0) && (posinblk <= sion_filedesc->blocksizes[newblocknr]) )
335 newposinblk=posinblk;
337 DPRINTFP((2, DFUNCTION, -1,
"sion_seek: parameter posinblk (%lld) is out of range (0 .. %lld), aborting ...\n",
338 posinblk, sion_filedesc->
blocksizes[newblocknr]));
339 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
340 "sion_seek: parameter posinblk (%lld) is out of range (0 .. %lld), aborting ...\n",
341 posinblk, sion_filedesc->
blocksizes[newblocknr]));
343 DPRINTFP((2, DFUNCTION, -1,
"new posinblk newblocknr=%d newpos=%ld fn=%s\n",newblocknr, (
long) newposinblk, sion_filedesc->
fname));
346 DPRINTFP((32, DFUNCTION, -1,
347 " before set pos: rank=%4d startpos=%ld currentblocknr=%d globalskip=%ld newposinblk=%ld\n", sion_filedesc->
rank 359 DPRINTFP((32, DFUNCTION, -1,
360 " set pos: rank=%4d newblocknr=%4d newposinblk=%4ld, set fileptr to position %14ld (%14ld) file=%s\n",
363 sion_filedesc->
fname));
366 DPRINTFP((2, DFUNCTION, -1,
"leave seek rc=%d\n",rc));
373 #define DFUNCTION "_sion_seek_on_all_ranks_read_mapped" 390 sion_int64 posinblk ) {
391 int rc = SION_SUCCESS;
392 int lfile, lrank, blknum, filenr, t;
395 DPRINTFP((2, DFUNCTION, -1,
"enter seek r=%d b=%d p=%ld fn=%s\n",
396 rank,blocknr, (
long) posinblk,sion_filedesc_master->
fname));
401 DPRINTFP((32, DFUNCTION, -1,
"rank has changed %d -> %d\n", sion_filedesc_master->
globalrank, rank));
404 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: parameter rank %d (max. %d) out of range, aborting ...\n",
413 lrank=sion_filedesc_master->
rank;
414 sion_filedesc_sub=sion_filedesc_master->
multifiles[lfile];
420 DPRINTFP((32, DFUNCTION, -1,
"set keyvalptr on sub to master lfile=%d,lrank=%d to %x\n",lfile,lrank,sion_filedesc_master->
keyvalptr));
423 DPRINTFP((32, DFUNCTION, -1,
"on file %d: sub,maxchunk=%d master,maxchunk=%d \n", lfile,sion_filedesc_sub->
maxchunks, sion_filedesc_master->
maxchunks));
426 DPRINTFP((32, DFUNCTION, -1,
"store current information lrank=%d lastchunknr=%d\n", lrank,sion_filedesc_sub->
lastchunknr));
431 DPRINTFP((32, DFUNCTION, -1,
"keyvalptr sub file=%d all_keyvalptr[%d] = %x\n",lfile,lrank,sion_filedesc_sub->
keyvalptr));
435 sion_filedesc_sub=NULL;
437 DPRINTFP((32, DFUNCTION, -1,
" nfiles=%d\n", sion_filedesc_master->
nfiles));
439 for(filenr=0;( (filenr<sion_filedesc_master->
nfiles) && (lrank==-1) );filenr++) {
440 DPRINTFP((4, DFUNCTION, -1,
" filenr=%d nlocaltasksinfile\n",
444 DPRINTFP((4, DFUNCTION, -1,
" check filenr=%d t=%d grank=%d with rank=%d\n",
447 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
454 DPRINTFP((32, DFUNCTION, -1,
"grank %d is found in file %d with lrank %d\n", rank,lfile,lrank));
455 if((lrank==-1) || (sion_filedesc_sub == NULL)) {
456 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: parameter rank %d is not opened on this tasks (mapped mode), aborting ...\n",
462 sion_filedesc_master->
rank = lrank;
472 DPRINTFP((32, DFUNCTION, -1,
"set keyvalptr on lfile=%d,lrank=%d to %x\n",lfile,lrank,sion_filedesc_sub->
all_keyvalptr[lrank]));
479 for (blknum = 0; blknum <= sion_filedesc_master->
lastchunknr; blknum++) {
495 if(posinblk>=sion_filedesc_master->
blocksizes[blocknr]) {
496 posinblk=0;blocknr++;
498 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: seek after end of file, returning ...\n"));
513 DPRINTFP((2, DFUNCTION, -1,
"leave seek\n"));
521 #define DFUNCTION "_sion_seek_on_all_ranks_write" 538 sion_int64 posinblk ) {
539 int rc = SION_SUCCESS;
542 DPRINTFP((2, DFUNCTION, -1,
"enter seek r=%d b=%d p=%ld fn=%s\n",
543 rank,blocknr, (
long) posinblk,sion_filedesc->
fname));
547 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
548 "sion_seek: internal error, data structure not initialized, aborting ...\n"));
554 DPRINTFP((32, DFUNCTION, -1,
"rank has changed %d -> %d\n", sion_filedesc->
rank, rank));
556 if ((rank<0) || (rank >= sion_filedesc->
ntasks)) {
557 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: parameter rank %d (max. %d) out of range, aborting ...\n",
558 rank, sion_filedesc->
ntasks));
570 DPRINTFP((32, DFUNCTION, -1,
"store data for rank %d currentpos=%d currentblocknr=%d lastchunknr=%d\n", sion_filedesc->
rank,
581 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
587 sion_filedesc->
rank = rank;
597 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
606 DPRINTFP((2, DFUNCTION, -1,
"leave seek\n"));
613 #define DFUNCTION "_sion_seek_on_all_ranks_write_mapped" 630 sion_int64 posinblk ) {
631 int rc = SION_SUCCESS;
632 int lfile, lrank, blknum, filenr, t;
635 DPRINTFP((2, DFUNCTION, -1,
"enter seek r=%d b=%d p=%ld fn=%s\n",
636 rank,blocknr, (
long) posinblk,sion_filedesc_master->
fname));
641 DPRINTFP((32, DFUNCTION, -1,
"rank has changed %d -> %d\n", sion_filedesc_master->
globalrank, rank));
644 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: parameter rank %d (max. %d) out of range, aborting ...\n",
658 lrank=sion_filedesc_master->
rank;
659 sion_filedesc_sub=sion_filedesc_master->
multifiles[lfile];
668 DPRINTFP((32, DFUNCTION, -1,
"on file %d: sub,maxchunk=%d master,maxchunk=%d \n", lfile,sion_filedesc_sub->
maxchunks, sion_filedesc_master->
maxchunks));
674 DPRINTFP((32, DFUNCTION, -1,
"store current information lrank=%d lastchunknr=%d\n", lrank,sion_filedesc_sub->
lastchunknr));
682 for (blknum = 0; blknum <= sion_filedesc_sub->
lastchunknr; blknum++) {
688 sion_filedesc_sub=NULL;
690 DPRINTFP((32, DFUNCTION, -1,
" nfiles=%d\n", sion_filedesc_master->
nfiles));
692 for(filenr=0;( (filenr<sion_filedesc_master->
nfiles) && (lrank==-1) );filenr++) {
693 DPRINTFP((32, DFUNCTION, -1,
" filenr=%d nlocaltasksinfile\n",
697 DPRINTFP((32, DFUNCTION, -1,
" check filenr=%d t=%d grank=%d with rank=%d\n",
700 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
707 DPRINTFP((32, DFUNCTION, -1,
"grank %d is found in file %d with lrank %d\n", rank,lfile,lrank));
708 if((lrank==-1) || (sion_filedesc_sub == NULL)) {
709 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: parameter rank %d is not opened on this tasks (mapped mode), aborting ...\n",
715 sion_filedesc_master->
rank = lrank;
729 for (blknum = 0; blknum <= sion_filedesc_sub->
lastchunknr; blknum++) {
744 DPRINTFP((2, DFUNCTION, -1,
"leave seek\n"));
752 #define DFUNCTION "_sion_seek_on_current_rank_write" 767 sion_int64 posinblk ) {
768 int rc = SION_SUCCESS;
770 DPRINTFP((2, DFUNCTION, -1,
"enter seek r=%d b=%d p=%ld fn=%s\n",rank,blocknr, (
long) posinblk,sion_filedesc->
fname));
774 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
775 "sion_seek: parameter rank is different from current rank in parallel openened file, returning ...\n"));
780 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
781 "sion_seek: serial write to file currently only for SION_CURRENT_BLK implemented, aborting ...\n"));
786 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
787 "sion_seek: serial write to file currently only for SION_CURRENT_POS implemented, aborting ...\n"));
803 DPRINTFP((2, DFUNCTION, -1,
"leave seek\n"));
810 #define DFUNCTION "_sion_seek_search_abs_pos" 825 sion_int64 *newposinblk ) {
826 int rc = SION_SUCCESS;
828 sion_int64 bytesinblock = 0;
832 bytes=0;*newblocknr=0;
833 bytesinblock = sion_filedesc->
blocksizes[*newblocknr];
834 while ( (*newblocknr<sion_filedesc->lastchunknr) && (bytes + bytesinblock < *newposinblk) ) {
835 bytes += bytesinblock;
837 bytesinblock = sion_filedesc->
blocksizes[*newblocknr];
841 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
842 "sion_seek: parameter pos in chunk (%d) is negative, aborting ...\n", (
int) abspos));
850 #define DFUNCTION "_sion_seek_search_end_pos" 865 sion_int64* newposinblk)
867 int rc = SION_SUCCESS;
870 *newposinblk = posend;
873 *newposinblk += sion_filedesc->
blocksizes[*newblocknr];
876 while ((*newblocknr >= 0) && (*newposinblk < 0));
879 if (*newposinblk < 0) {
880 return _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_RETURN,
881 "sion_seek: seek before beginning of file (posend = %ld, abspos = %ld), aborting ...\n", posend, *newposinblk);
885 return _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_RETURN,
886 "sion_seek: seek past end of file (%ld > 0), aborting ...\n", posend);
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.
int _sion_seek_on_all_ranks_read(_sion_filedesc *sion_filedesc, int rank, int blocknr, sion_int64 posinblk)
Function to set the file pointer to a new position, updates internal data structure.
sion_int64 _sion_file_set_position(_sion_fileptr *sion_fileptr, sion_int64 startpointer)
Set new position in file.
Sion File Descriptor Structure.
sion_int64 * all_blockcount
int _sion_file_purge(_sion_fileptr *sion_fileptr)
Purge data to file.
int _sion_seek_on_all_ranks_read_mapped(_sion_filedesc *sion_filedesc_master, int rank, int blocknr, sion_int64 posinblk)
Function to set the file pointer to a new position, updates internal data structure.
sion_int64 * all_currentpos
int _sion_seek_on_all_ranks_write_mapped(_sion_filedesc *sion_filedesc_master, int rank, int blocknr, sion_int64 posinblk)
Function to set the file pointer to a new position, updates internal data structure.
sion_int64 * all_globalranks
sion_int64 * all_currentblocknr
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_seek_search_abs_pos(_sion_filedesc *sion_filedesc, sion_int64 abspos, int *newblocknr, sion_int64 *newposinblk)
Find block and position inside block for absolute position abspos.
sion_int64 * all_startpointers
#define SION_CURRENT_RANK
int _sion_update_fileposition(_sion_filedesc *sion_filedesc)
Update the internal data structure (check fileposition)
int _sion_seek_search_end_pos(_sion_filedesc *sion_filedesc, sion_int64 posend, int *newblocknr, sion_int64 *newposinblk)
Find block and position inside block position relative to end.
int _sion_seek_on_all_ranks_read_master(_sion_filedesc *sion_filedesc, int rank, int blocknr, sion_int64 posinblk)
Function to set the file pointer to a new position, updates internal data structure.
#define SION_ABSOLUTE_POS
sion_int32 currentblocknr
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_seek_on_current_rank_read(_sion_filedesc *sion_filedesc, int rank, int blocknr, sion_int64 posinblk)
Function to set the file pointer to a new position in the same rank, updates internal data structure.
int _sion_seek_on_all_ranks_write(_sion_filedesc *sion_filedesc, int rank, int blocknr, sion_int64 posinblk)
Function to set the file pointer to a new position, updates internal data structure.
sion_int64 * all_blocksizes
sion_int32 ntotaltasksinfile
sion_int32 nlocaltasksinfile
_sion_filedesc ** multifiles
int _sion_seek_on_current_rank_write(_sion_filedesc *sion_filedesc, int rank, int blocknr, sion_int64 posinblk)
Function to set the file pointer to a new position in the same rank, updates internal data structure.