14 #define _XOPEN_SOURCE 700
26 #include "sion_error_handler.h"
38 #define DFUNCTION "_sion_seek_on_all_ranks_read"
55 sion_int64 posinblk ) {
56 int rc = SION_SUCCESS;
59 DPRINTFP((2, DFUNCTION, -1,
"enter seek r=%d b=%d p=%ld fn=%s\n",
60 rank,blocknr, (
long) posinblk,sion_filedesc->
fname));
64 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
65 "sion_seek: internal error, data structure not initialized, aborting ...\n"));
71 DPRINTFP((32, DFUNCTION, -1,
"rank has changed %d -> %d\n", sion_filedesc->
rank, rank));
73 if ((rank<0) || (rank >= sion_filedesc->
ntasks)) {
74 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: parameter rank %d (max. %d) out of range, aborting ...\n",
75 rank, sion_filedesc->
ntasks));
89 sion_filedesc->
rank = rank;
99 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
120 if(posinblk>=sion_filedesc->
blocksizes[blocknr]) {
126 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: seek after end of file, returning ...\n"));
139 DPRINTFP((2, DFUNCTION, -1,
"leave seek rc=%d\n",rc));
146 #define DFUNCTION "_sion_seek_on_all_ranks_read_master"
163 sion_int64 posinblk ) {
164 int rc = SION_SUCCESS;
165 int blknum, lfile, lrank;
167 DPRINTFP((2, DFUNCTION, -1,
"enter seek r=%d b=%d p=%ld fn=%s\n",
168 rank,blocknr, (
long) posinblk,sion_filedesc->
fname));
173 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
174 "sion_seek: internal error, data structure not initialized, aborting ...\n"));
179 lfile=sion_filedesc->
mapping[sion_filedesc->
rank*2+0];
180 lrank=sion_filedesc->
mapping[sion_filedesc->
rank*2+1];
185 if ((rank<0) || (rank >= sion_filedesc->
ntasks)) {
186 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: parameter rank %d (max. %d) out of range, aborting ...\n",
187 rank, sion_filedesc->
ntasks));
202 sion_filedesc->
rank = rank;
205 lfile=sion_filedesc->
mapping[sion_filedesc->
rank*2+0];
206 lrank=sion_filedesc->
mapping[sion_filedesc->
rank*2+1];
220 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 ));
238 if(posinblk>=sion_filedesc->
blocksizes[blocknr]) {
239 posinblk=0;blocknr++;
241 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: seek after end of file, returning ...\n"));
253 DPRINTFP((2, DFUNCTION, -1,
"leave seek rc=%d\n",rc));
261 #define DFUNCTION "_sion_seek_on_current_rank_read"
276 sion_int64 posinblk ) {
277 int rc = SION_SUCCESS;
279 sion_int64 newposinblk=-1;
281 DPRINTFP((2, DFUNCTION, -1,
"enter seek r=%d b=%d p=%ld fn=%s\n",rank,blocknr, (
long) posinblk,sion_filedesc->
fname));
286 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
287 "sion_seek: parameter rank is different from current rank in parallel openened file, returning ...\n"));
294 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: error in searching abs pos, returning ...\n"));
295 }
else posinblk=newposinblk;
296 DPRINTFP((32, DFUNCTION, -1,
"sion_absolute_pos newblocknr=%d newpos=%ld fn=%s\n",newblocknr, (
long) newposinblk, sion_filedesc->
fname));
301 return _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_RETURN,
"sion_seek: error in searching end pos, returning ...\n");
303 else { posinblk = newposinblk;
305 DPRINTFP((32, DFUNCTION, -1,
"sion_end_pos newblocknr=%d newpos=%ld fn=%s\n", newblocknr, (
long)newposinblk, sion_filedesc->
fname));
310 DPRINTFP((32, DFUNCTION, -1,
"sion_current_blk newblocknr=%d newpos=%ld fn=%s\n",newblocknr, (
long) newposinblk, sion_filedesc->
fname));
313 if ( (blocknr >= 0) && (blocknr <= sion_filedesc->lastchunknr) ) {
316 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
317 "sion_seek: parameter chunk number (%d) is out of range (0 .. %d), returning ...\n",
320 DPRINTFP((32, DFUNCTION, -1,
"new blocknr newblocknr=%d newpos=%ld fn=%s\n",newblocknr, (
long) newposinblk, sion_filedesc->
fname));
329 DPRINTFP((32, DFUNCTION, -1,
"sion_current_pos newblocknr=%d newpos=%ld fn=%s %ld %ld %ld %ld\n",newblocknr, (
long) newposinblk, sion_filedesc->
fname,
334 ( (posinblk >= 0) && (posinblk <= sion_filedesc->blocksizes[newblocknr]) )
337 newposinblk=posinblk;
339 DPRINTFP((2, DFUNCTION, -1,
"sion_seek: parameter posinblk (%lld) is out of range (0 .. %lld), aborting ...\n",
340 posinblk, sion_filedesc->
blocksizes[newblocknr]));
341 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
342 "sion_seek: parameter posinblk (%lld) is out of range (0 .. %lld), aborting ...\n",
343 posinblk, sion_filedesc->
blocksizes[newblocknr]));
345 DPRINTFP((2, DFUNCTION, -1,
"new posinblk newblocknr=%d newpos=%ld fn=%s\n",newblocknr, (
long) newposinblk, sion_filedesc->
fname));
348 DPRINTFP((32, DFUNCTION, -1,
349 " before set pos: rank=%4d startpos=%ld currentblocknr=%d globalskip=%ld newposinblk=%ld\n", sion_filedesc->
rank
361 DPRINTFP((32, DFUNCTION, -1,
362 " set pos: rank=%4d newblocknr=%4d newposinblk=%4ld, set fileptr to position %14ld (%14ld) file=%s\n",
365 sion_filedesc->
fname));
368 DPRINTFP((2, DFUNCTION, -1,
"leave seek rc=%d\n",rc));
375 #define DFUNCTION "_sion_seek_on_all_ranks_read_mapped"
392 sion_int64 posinblk ) {
393 int rc = SION_SUCCESS;
394 int lfile, lrank, blknum, filenr, t;
397 DPRINTFP((2, DFUNCTION, -1,
"enter seek r=%d b=%d p=%ld fn=%s\n",
398 rank,blocknr, (
long) posinblk,sion_filedesc_master->
fname));
403 DPRINTFP((32, DFUNCTION, -1,
"rank has changed %d -> %d\n", sion_filedesc_master->
globalrank, rank));
406 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: parameter rank %d (max. %d) out of range, aborting ...\n",
415 lrank=sion_filedesc_master->
rank;
416 sion_filedesc_sub=sion_filedesc_master->
multifiles[lfile];
422 DPRINTFP((32, DFUNCTION, -1,
"set keyvalptr on sub to master lfile=%d,lrank=%d to %x\n",lfile,lrank,sion_filedesc_master->
keyvalptr));
425 DPRINTFP((32, DFUNCTION, -1,
"on file %d: sub,maxchunk=%d master,maxchunk=%d \n", lfile,sion_filedesc_sub->
maxchunks, sion_filedesc_master->
maxchunks));
428 DPRINTFP((32, DFUNCTION, -1,
"store current information lrank=%d lastchunknr=%d\n", lrank,sion_filedesc_sub->
lastchunknr));
433 DPRINTFP((32, DFUNCTION, -1,
"keyvalptr sub file=%d all_keyvalptr[%d] = %x\n",lfile,lrank,sion_filedesc_sub->
keyvalptr));
437 sion_filedesc_sub=NULL;
439 DPRINTFP((32, DFUNCTION, -1,
" nfiles=%d\n", sion_filedesc_master->
nfiles));
441 for(filenr=0;( (filenr<sion_filedesc_master->
nfiles) && (lrank==-1) );filenr++) {
442 DPRINTFP((4, DFUNCTION, -1,
" filenr=%d nlocaltasksinfile\n",
446 DPRINTFP((4, DFUNCTION, -1,
" check filenr=%d t=%d grank=%d with rank=%d\n",
449 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
456 DPRINTFP((32, DFUNCTION, -1,
"grank %d is found in file %d with lrank %d\n", rank,lfile,lrank));
457 if((lrank==-1) || (sion_filedesc_sub == NULL)) {
458 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: parameter rank %d is not opened on this tasks (mapped mode), aborting ...\n",
464 sion_filedesc_master->
rank = lrank;
474 DPRINTFP((32, DFUNCTION, -1,
"set keyvalptr on lfile=%d,lrank=%d to %x\n",lfile,lrank,sion_filedesc_sub->
all_keyvalptr[lrank]));
481 for (blknum = 0; blknum <= sion_filedesc_master->
lastchunknr; blknum++) {
497 if(posinblk>=sion_filedesc_master->
blocksizes[blocknr]) {
498 posinblk=0;blocknr++;
500 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: seek after end of file, returning ...\n"));
515 DPRINTFP((2, DFUNCTION, -1,
"leave seek\n"));
523 #define DFUNCTION "_sion_seek_on_all_ranks_write"
540 sion_int64 posinblk ) {
541 int rc = SION_SUCCESS;
544 DPRINTFP((2, DFUNCTION, -1,
"enter seek r=%d b=%d p=%ld fn=%s\n",
545 rank,blocknr, (
long) posinblk,sion_filedesc->
fname));
549 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
550 "sion_seek: internal error, data structure not initialized, aborting ...\n"));
556 DPRINTFP((32, DFUNCTION, -1,
"rank has changed %d -> %d\n", sion_filedesc->
rank, rank));
558 if ((rank<0) || (rank >= sion_filedesc->
ntasks)) {
559 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: parameter rank %d (max. %d) out of range, aborting ...\n",
560 rank, sion_filedesc->
ntasks));
572 DPRINTFP((32, DFUNCTION, -1,
"store data for rank %d currentpos=%d currentblocknr=%d lastchunknr=%d\n", sion_filedesc->
rank,
583 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
589 sion_filedesc->
rank = rank;
599 for (blknum = 0; blknum <= sion_filedesc->
lastchunknr; blknum++) {
608 DPRINTFP((2, DFUNCTION, -1,
"leave seek\n"));
615 #define DFUNCTION "_sion_seek_on_all_ranks_write_mapped"
632 sion_int64 posinblk ) {
633 int rc = SION_SUCCESS;
634 int lfile, lrank, blknum, filenr, t;
637 DPRINTFP((2, DFUNCTION, -1,
"enter seek r=%d b=%d p=%ld fn=%s\n",
638 rank,blocknr, (
long) posinblk,sion_filedesc_master->
fname));
643 DPRINTFP((32, DFUNCTION, -1,
"rank has changed %d -> %d\n", sion_filedesc_master->
globalrank, rank));
646 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: parameter rank %d (max. %d) out of range, aborting ...\n",
660 lrank=sion_filedesc_master->
rank;
661 sion_filedesc_sub=sion_filedesc_master->
multifiles[lfile];
670 DPRINTFP((32, DFUNCTION, -1,
"on file %d: sub,maxchunk=%d master,maxchunk=%d \n", lfile,sion_filedesc_sub->
maxchunks, sion_filedesc_master->
maxchunks));
676 DPRINTFP((32, DFUNCTION, -1,
"store current information lrank=%d lastchunknr=%d\n", lrank,sion_filedesc_sub->
lastchunknr));
684 for (blknum = 0; blknum <= sion_filedesc_sub->
lastchunknr; blknum++) {
690 sion_filedesc_sub=NULL;
692 DPRINTFP((32, DFUNCTION, -1,
" nfiles=%d\n", sion_filedesc_master->
nfiles));
694 for(filenr=0;( (filenr<sion_filedesc_master->
nfiles) && (lrank==-1) );filenr++) {
695 DPRINTFP((32, DFUNCTION, -1,
" filenr=%d nlocaltasksinfile\n",
699 DPRINTFP((32, DFUNCTION, -1,
" check filenr=%d t=%d grank=%d with rank=%d\n",
702 sion_filedesc_sub=sion_filedesc_master->
multifiles[filenr];
709 DPRINTFP((32, DFUNCTION, -1,
"grank %d is found in file %d with lrank %d\n", rank,lfile,lrank));
710 if((lrank==-1) || (sion_filedesc_sub == NULL)) {
711 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sion_seek: parameter rank %d is not opened on this tasks (mapped mode), aborting ...\n",
717 sion_filedesc_master->
rank = lrank;
731 for (blknum = 0; blknum <= sion_filedesc_sub->
lastchunknr; blknum++) {
746 DPRINTFP((2, DFUNCTION, -1,
"leave seek\n"));
754 #define DFUNCTION "_sion_seek_on_current_rank_write"
769 sion_int64 posinblk ) {
770 int rc = SION_SUCCESS;
772 DPRINTFP((2, DFUNCTION, -1,
"enter seek r=%d b=%d p=%ld fn=%s\n",rank,blocknr, (
long) posinblk,sion_filedesc->
fname));
776 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
777 "sion_seek: parameter rank is different from current rank in parallel openened file, returning ...\n"));
782 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
783 "sion_seek: serial write to file currently only for SION_CURRENT_BLK implemented, aborting ...\n"));
788 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
789 "sion_seek: serial write to file currently only for SION_CURRENT_POS implemented, aborting ...\n"));
805 DPRINTFP((2, DFUNCTION, -1,
"leave seek\n"));
812 #define DFUNCTION "_sion_seek_search_abs_pos"
827 sion_int64 *newposinblk ) {
828 int rc = SION_SUCCESS;
830 sion_int64 bytesinblock = 0;
834 bytes=0;*newblocknr=0;
835 bytesinblock = sion_filedesc->
blocksizes[*newblocknr];
836 while ( (*newblocknr<sion_filedesc->lastchunknr) && (bytes + bytesinblock < *newposinblk) ) {
837 bytes += bytesinblock;
839 bytesinblock = sion_filedesc->
blocksizes[*newblocknr];
843 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
844 "sion_seek: parameter pos in chunk (%d) is negative, aborting ...\n", (
int) abspos));
852 #define DFUNCTION "_sion_seek_search_end_pos"
867 sion_int64* newposinblk)
869 int rc = SION_SUCCESS;
872 *newposinblk = posend;
875 *newposinblk += sion_filedesc->
blocksizes[*newblocknr];
878 while ((*newblocknr >= 0) && (*newposinblk < 0));
881 if (*newposinblk < 0) {
882 return _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_RETURN,
883 "sion_seek: seek before beginning of file (posend = %ld, abspos = %ld), aborting ...\n", posend, *newposinblk);
887 return _sion_errorprint(SION_NOT_SUCCESS, _SION_ERROR_RETURN,
888 "sion_seek: seek past end of file (%ld > 0), aborting ...\n", posend);
int _sion_buffer_flush(_sion_filedesc *sion_filedesc)
Flush buffer.
#define SION_ABSOLUTE_POS
#define SION_CURRENT_RANK
sion_int64 _sion_file_set_position(_sion_fileptr *sion_fileptr, sion_int64 startpointer)
Set new position in file.
int _sion_file_purge(_sion_fileptr *sion_fileptr)
Purge data to file.
sion_int64 _sion_file_get_position(_sion_fileptr *sion_fileptr)
Get new position in file.
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_print_filedesc(_sion_filedesc *sion_filedesc, int level, char *desc, int flag)
Print the initialized sion file description.
int _sion_flush_block(_sion_filedesc *sion_filedesc)
Update the internal data structure.
int _sion_update_fileposition(_sion_filedesc *sion_filedesc)
Update the internal data structure (check fileposition)
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_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.
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.
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.
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.
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.
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.
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.
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.
Sion File Descriptor Structure.
sion_int64 * all_blocksizes
sion_int32 nlocaltasksinfile
sion_int64 * all_chunksizes
sion_int64 * all_currentpos
sion_int64 * all_currentblocknr
_sion_filedesc ** multifiles
sion_int64 * all_globalranks
sion_int32 ntotaltasksinfile
sion_int32 currentblocknr
sion_int64 * all_startpointers
sion_int64 * all_blockcount