35 #define DFUNCTION "_sion_seek_on_all_ranks_read" 52 sion_int64 posinblk ) {
53 int rc = SION_SUCCESS;
56 DPRINTFP((2, DFUNCTION, -1,
"enter seek r=%d b=%d p=%ld fn=%s\n",
57 rank,blocknr, (
long) posinblk,sion_filedesc->
fname));
62 "sion_seek: internal error, data structure not initialized, aborting ...\n"));
68 DPRINTFP((32, DFUNCTION, -1,
"rank has changed %d -> %d\n", sion_filedesc->
rank, rank));
70 if ((rank<0) || (rank >= sion_filedesc->
ntasks)) {
71 return(
_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: parameter rank %d (max. %d) out of range, aborting ...\n",
72 rank, sion_filedesc->
ntasks));
86 sion_filedesc->
rank = rank;
96 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
117 if(posinblk>=sion_filedesc->
blocksizes[blocknr]) {
123 return(
_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: seek after end of file, returning ...\n"));
136 DPRINTFP((2, DFUNCTION, -1,
"leave seek rc=%d\n",rc));
143 #define DFUNCTION "_sion_seek_on_all_ranks_read_master" 160 sion_int64 posinblk ) {
161 int rc = SION_SUCCESS;
162 int blknum, lfile, lrank;
164 DPRINTFP((2, DFUNCTION, -1,
"enter seek r=%d b=%d p=%ld fn=%s\n",
165 rank,blocknr, (
long) posinblk,sion_filedesc->
fname));
171 "sion_seek: internal error, data structure not initialized, aborting ...\n"));
176 lfile=sion_filedesc->
mapping[sion_filedesc->
rank*2+0];
177 lrank=sion_filedesc->
mapping[sion_filedesc->
rank*2+1];
182 if ((rank<0) || (rank >= sion_filedesc->
ntasks)) {
183 return(
_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: parameter rank %d (max. %d) out of range, aborting ...\n",
184 rank, sion_filedesc->
ntasks));
199 sion_filedesc->
rank = rank;
202 lfile=sion_filedesc->
mapping[sion_filedesc->
rank*2+0];
203 lrank=sion_filedesc->
mapping[sion_filedesc->
rank*2+1];
217 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 ));
235 if(posinblk>=sion_filedesc->
blocksizes[blocknr]) {
236 posinblk=0;blocknr++;
238 return(
_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: seek after end of file, returning ...\n"));
250 DPRINTFP((2, DFUNCTION, -1,
"leave seek rc=%d\n",rc));
258 #define DFUNCTION "_sion_seek_on_current_rank_read" 273 sion_int64 posinblk ) {
274 int rc = SION_SUCCESS;
276 sion_int64 newposinblk=-1;
278 DPRINTFP((2, DFUNCTION, -1,
"enter seek r=%d b=%d p=%ld fn=%s\n",rank,blocknr, (
long) posinblk,sion_filedesc->
fname));
284 "sion_seek: parameter rank is different from current rank in parallel openened file, returning ...\n"));
291 return(
_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: error in searching abs pos, returning ...\n"));
292 }
else posinblk=newposinblk;
293 DPRINTFP((32, DFUNCTION, -1,
"sion_absolute_pos newblocknr=%d newpos=%ld fn=%s\n",newblocknr, (
long) newposinblk, sion_filedesc->
fname));
298 return _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_RETURN,
"sion_seek: error in searching end pos, returning ...\n");
300 else { posinblk = newposinblk;
302 DPRINTFP((32, DFUNCTION, -1,
"sion_end_pos newblocknr=%d newpos=%ld fn=%s\n", newblocknr, (
long)newposinblk, sion_filedesc->
fname));
307 DPRINTFP((32, DFUNCTION, -1,
"sion_current_blk newblocknr=%d newpos=%ld fn=%s\n",newblocknr, (
long) newposinblk, sion_filedesc->
fname));
310 if ( (blocknr >= 0) && (blocknr <= sion_filedesc->lastchunknr) ) {
314 "sion_seek: parameter chunk number (%d) is out of range (0 .. %d), returning ...\n",
317 DPRINTFP((32, DFUNCTION, -1,
"new blocknr newblocknr=%d newpos=%ld fn=%s\n",newblocknr, (
long) newposinblk, sion_filedesc->
fname));
326 DPRINTFP((32, DFUNCTION, -1,
"sion_current_pos newblocknr=%d newpos=%ld fn=%s %ld %ld %ld %ld\n",newblocknr, (
long) newposinblk, sion_filedesc->
fname,
331 ( (posinblk >= 0) && (posinblk <= sion_filedesc->blocksizes[newblocknr]) )
334 newposinblk=posinblk;
336 DPRINTFP((2, DFUNCTION, -1,
"sion_seek: parameter posinblk (%lld) is out of range (0 .. %lld), aborting ...\n",
337 posinblk, sion_filedesc->
blocksizes[newblocknr]));
339 "sion_seek: parameter posinblk (%lld) is out of range (0 .. %lld), aborting ...\n",
340 posinblk, sion_filedesc->
blocksizes[newblocknr]));
342 DPRINTFP((2, DFUNCTION, -1,
"new posinblk newblocknr=%d newpos=%ld fn=%s\n",newblocknr, (
long) newposinblk, sion_filedesc->
fname));
345 DPRINTFP((32, DFUNCTION, -1,
346 " before set pos: rank=%4d startpos=%ld currentblocknr=%d globalskip=%ld newposinblk=%ld\n", sion_filedesc->
rank 358 DPRINTFP((32, DFUNCTION, -1,
359 " set pos: rank=%4d newblocknr=%4d newposinblk=%4ld, set fileptr to position %14ld (%14ld) file=%s\n",
362 sion_filedesc->
fname));
365 DPRINTFP((2, DFUNCTION, -1,
"leave seek rc=%d\n",rc));
372 #define DFUNCTION "_sion_seek_on_all_ranks_read_mapped" 389 sion_int64 posinblk ) {
390 int rc = SION_SUCCESS;
391 int lfile, lrank, blknum, filenr, t;
394 DPRINTFP((2, DFUNCTION, -1,
"enter seek r=%d b=%d p=%ld fn=%s\n",
395 rank,blocknr, (
long) posinblk,sion_filedesc_master->
fname));
400 DPRINTFP((32, DFUNCTION, -1,
"rank has changed %d -> %d\n", sion_filedesc_master->
globalrank, rank));
403 return(
_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: parameter rank %d (max. %d) out of range, aborting ...\n",
412 lrank=sion_filedesc_master->
rank;
413 sion_filedesc_sub=sion_filedesc_master->
multifiles[lfile];
419 DPRINTFP((32, DFUNCTION, -1,
"set keyvalptr on sub to master lfile=%d,lrank=%d to %x\n",lfile,lrank,sion_filedesc_master->
keyvalptr));
422 DPRINTFP((32, DFUNCTION, -1,
"on file %d: sub,maxchunk=%d master,maxchunk=%d \n", lfile,sion_filedesc_sub->
maxchunks, sion_filedesc_master->
maxchunks));
425 DPRINTFP((32, DFUNCTION, -1,
"store current information lrank=%d lastchunknr=%d\n", lrank,sion_filedesc_sub->
lastchunknr));
430 DPRINTFP((32, DFUNCTION, -1,
"keyvalptr sub file=%d all_keyvalptr[%d] = %x\n",lfile,lrank,sion_filedesc_sub->
keyvalptr));
434 sion_filedesc_sub=NULL;
436 DPRINTFP((32, DFUNCTION, -1,
" nfiles=%d\n", sion_filedesc_master->
nfiles));
438 for(filenr=0;( (filenr<sion_filedesc_master->
nfiles) && (lrank==-1) );filenr++) {
439 DPRINTFP((4, DFUNCTION, -1,
" filenr=%d nlocaltasksinfile\n",
443 DPRINTFP((4, DFUNCTION, -1,
" check filenr=%d t=%d grank=%d with rank=%d\n",
446 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
453 DPRINTFP((32, DFUNCTION, -1,
"grank %d is found in file %d with lrank %d\n", rank,lfile,lrank));
455 return(
_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: parameter rank %d is not opened on this tasks (mapped mode), aborting ...\n",
461 sion_filedesc_master->
rank = lrank;
471 DPRINTFP((32, DFUNCTION, -1,
"set keyvalptr on lfile=%d,lrank=%d to %x\n",lfile,lrank,sion_filedesc_sub->
all_keyvalptr[lrank]));
478 for (blknum = 0; blknum <= sion_filedesc_master->
lastchunknr; blknum++) {
494 if(posinblk>=sion_filedesc_master->
blocksizes[blocknr]) {
495 posinblk=0;blocknr++;
497 return(
_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: seek after end of file, returning ...\n"));
512 DPRINTFP((2, DFUNCTION, -1,
"leave seek\n"));
520 #define DFUNCTION "_sion_seek_on_all_ranks_write" 537 sion_int64 posinblk ) {
538 int rc = SION_SUCCESS;
541 DPRINTFP((2, DFUNCTION, -1,
"enter seek r=%d b=%d p=%ld fn=%s\n",
542 rank,blocknr, (
long) posinblk,sion_filedesc->
fname));
547 "sion_seek: internal error, data structure not initialized, aborting ...\n"));
553 DPRINTFP((32, DFUNCTION, -1,
"rank has changed %d -> %d\n", sion_filedesc->
rank, rank));
555 if ((rank<0) || (rank >= sion_filedesc->
ntasks)) {
556 return(
_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: parameter rank %d (max. %d) out of range, aborting ...\n",
557 rank, sion_filedesc->
ntasks));
569 DPRINTFP((32, DFUNCTION, -1,
"store data for rank %d currentpos=%d currentblocknr=%d lastchunknr=%d\n", sion_filedesc->
rank,
580 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
586 sion_filedesc->
rank = rank;
596 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
605 DPRINTFP((2, DFUNCTION, -1,
"leave seek\n"));
612 #define DFUNCTION "_sion_seek_on_all_ranks_write_mapped" 629 sion_int64 posinblk ) {
630 int rc = SION_SUCCESS;
631 int lfile, lrank, blknum, filenr, t;
634 DPRINTFP((2, DFUNCTION, -1,
"enter seek r=%d b=%d p=%ld fn=%s\n",
635 rank,blocknr, (
long) posinblk,sion_filedesc_master->
fname));
640 DPRINTFP((32, DFUNCTION, -1,
"rank has changed %d -> %d\n", sion_filedesc_master->
globalrank, rank));
643 return(
_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: parameter rank %d (max. %d) out of range, aborting ...\n",
657 lrank=sion_filedesc_master->
rank;
658 sion_filedesc_sub=sion_filedesc_master->
multifiles[lfile];
667 DPRINTFP((32, DFUNCTION, -1,
"on file %d: sub,maxchunk=%d master,maxchunk=%d \n", lfile,sion_filedesc_sub->
maxchunks, sion_filedesc_master->
maxchunks));
673 DPRINTFP((32, DFUNCTION, -1,
"store current information lrank=%d lastchunknr=%d\n", lrank,sion_filedesc_sub->
lastchunknr));
681 for (blknum = 0; blknum <= sion_filedesc_sub->
lastchunknr; blknum++) {
687 sion_filedesc_sub=NULL;
689 DPRINTFP((32, DFUNCTION, -1,
" nfiles=%d\n", sion_filedesc_master->
nfiles));
691 for(filenr=0;( (filenr<sion_filedesc_master->
nfiles) && (lrank==-1) );filenr++) {
692 DPRINTFP((32, DFUNCTION, -1,
" filenr=%d nlocaltasksinfile\n",
696 DPRINTFP((32, DFUNCTION, -1,
" check filenr=%d t=%d grank=%d with rank=%d\n",
699 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
706 DPRINTFP((32, DFUNCTION, -1,
"grank %d is found in file %d with lrank %d\n", rank,lfile,lrank));
708 return(
_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: parameter rank %d is not opened on this tasks (mapped mode), aborting ...\n",
714 sion_filedesc_master->
rank = lrank;
728 for (blknum = 0; blknum <= sion_filedesc_sub->
lastchunknr; blknum++) {
743 DPRINTFP((2, DFUNCTION, -1,
"leave seek\n"));
751 #define DFUNCTION "_sion_seek_on_current_rank_write" 766 sion_int64 posinblk ) {
767 int rc = SION_SUCCESS;
769 DPRINTFP((2, DFUNCTION, -1,
"enter seek r=%d b=%d p=%ld fn=%s\n",rank,blocknr, (
long) posinblk,sion_filedesc->
fname));
774 "sion_seek: parameter rank is different from current rank in parallel openened file, returning ...\n"));
780 "sion_seek: serial write to file currently only for SION_CURRENT_BLK implemented, aborting ...\n"));
786 "sion_seek: serial write to file currently only for SION_CURRENT_POS implemented, aborting ...\n"));
802 DPRINTFP((2, DFUNCTION, -1,
"leave seek\n"));
809 #define DFUNCTION "_sion_seek_search_abs_pos" 824 sion_int64 *newposinblk ) {
825 int rc = SION_SUCCESS;
827 sion_int64 bytesinblock = 0;
831 bytes=0;*newblocknr=0;
832 bytesinblock = sion_filedesc->
blocksizes[*newblocknr];
833 while ( (*newblocknr<sion_filedesc->lastchunknr) && (bytes + bytesinblock < *newposinblk) ) {
834 bytes += bytesinblock;
836 bytesinblock = sion_filedesc->
blocksizes[*newblocknr];
841 "sion_seek: parameter pos in chunk (%d) is negative, aborting ...\n", (
int) abspos));
849 #define DFUNCTION "_sion_seek_search_end_pos" 864 sion_int64* newposinblk)
866 int rc = SION_SUCCESS;
869 *newposinblk = posend;
872 *newposinblk += sion_filedesc->
blocksizes[*newblocknr];
875 while ((*newblocknr >= 0) && (*newposinblk < 0));
878 if (*newposinblk < 0) {
880 "sion_seek: seek before beginning of file (posend = %ld, abspos = %ld), aborting ...\n", posend, *newposinblk);
885 "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_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_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.