14 #define _XOPEN_SOURCE 700
24 #include "sion_error_handler.h"
31 #define DFUNCTION "_sion_write_header"
40 int rc = SION_SUCCESS;
45 sion_uint32 endianness_writeval;
46 sion_int32 sion_version, sion_version_patchlevel, sion_fileformat_version;
49 DPRINTFP((2, DFUNCTION, -1,
"enter write\n"));
54 if (nwrite != strlen(sionstr)) {
55 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(SIONID) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
57 DPRINTFP((32, DFUNCTION, -1,
" wrote sionstr nwrite=%lu\n", (
unsigned long) nwrite));
60 endianness_writeval = sion_filedesc->
endianness;
62 if (nwrite !=
sizeof(endianness_writeval)) {
63 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(endianness) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
65 DPRINTFP((32, DFUNCTION, -1,
" wrote endianness 0x%x nwrite=%lu\n", endianness_writeval, (
unsigned long) nwrite));
68 sion_version = 1000 * SION_MAIN_VERSION + SION_SUB_VERSION;
69 sion_version_patchlevel = SION_VERSION_PATCHLEVEL;
70 sion_fileformat_version = SION_FILEFORMAT_VERSION;
73 if (nwrite !=
sizeof(sion_version)) {
74 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(sion_version) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
76 DPRINTFP((32, DFUNCTION, -1,
" wrote sion_version %ld nwrite=%lu\n", sion_version, (
unsigned long) nwrite));
79 if (nwrite !=
sizeof(sion_version_patchlevel)) {
80 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(sion_version_patchlevel) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
82 DPRINTFP((32, DFUNCTION, -1,
" wrote sion_version_patchlevel %ld nwrite=%lu\n", sion_version_patchlevel, (
unsigned long) nwrite));
85 if (nwrite !=
sizeof(sion_fileformat_version)) {
86 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(sion_fileformat_version) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
88 DPRINTFP((32, DFUNCTION, -1,
" wrote sion_fileformat_version %ld nwrite=%lu\n", sion_fileformat_version, (
unsigned long) nwrite));
92 if (nwrite !=
sizeof(sion_filedesc->
fsblksize)) {
93 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(fsblksize) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
95 DPRINTFP((32, DFUNCTION, -1,
" wrote fsblksize %ld nwrite=%lu\n", sion_filedesc->
fsblksize, (
unsigned long) nwrite));
99 if (nwrite !=
sizeof(sion_filedesc->
ntasks)) {
100 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(ntasks) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
102 DPRINTFP((32, DFUNCTION, -1,
" wrote ntasks %ld nwrite=%lu\n", sion_filedesc->
ntasks, (
unsigned long) nwrite));
106 if (nwrite !=
sizeof(sion_filedesc->
nfiles)) {
107 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(nfiles) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
109 DPRINTFP((32, DFUNCTION, -1,
" wrote nfiles %d nwrite=%lu\n", sion_filedesc->
nfiles, (
unsigned long) nwrite));
113 if (nwrite !=
sizeof(sion_filedesc->
filenumber)) {
114 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(filenumber) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
116 DPRINTFP((32, DFUNCTION, -1,
" wrote filenumber %d nwrite=%lu\n", sion_filedesc->
filenumber, (
unsigned long) nwrite));
121 if (nwrite !=
sizeof(sion_filedesc->
flag1)) {
122 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(flag1) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
124 DPRINTFP((32, DFUNCTION, -1,
" wrote flag1 %lld nwrite=%lu\n", sion_filedesc->
flag1, (
unsigned long) nwrite));
128 if (nwrite !=
sizeof(sion_filedesc->
flag2)) {
129 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(flag2) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
131 DPRINTFP((32, DFUNCTION, -1,
" wrote flag2 %d nwrite=%lu\n", sion_filedesc->
flag2, (
unsigned long) nwrite));
134 if (sion_filedesc->
prefix==NULL) {
135 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(prefix) to file, data not available, aborting ...\n"));
137 lprefix = calloc(SION_FILENAME_LENGTH,1);
138 if (lprefix == NULL) {
139 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot allocate temporary memory of size %lu (lprefix), aborting ...\n", (
unsigned long) SION_FILENAME_LENGTH));
141 strncpy(lprefix,sion_filedesc->
prefix,SION_FILENAME_LENGTH);
143 if (nwrite != SION_FILENAME_LENGTH) {
145 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(lprefix) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
147 free(lprefix); lprefix=NULL;
148 DPRINTFP((32, DFUNCTION, -1,
" wrote prefix =%s\n", sion_filedesc->
prefix));
152 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(globalranks) to file, data not available, aborting ...\n"));
155 if (nwrite !=
sizeof(sion_int64) * sion_filedesc->
ntasks) {
156 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(globalranks) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
158 DPRINTFP((32, DFUNCTION, -1,
" wrote globalranks nwrite=%lu\n", (
unsigned long) nwrite));
162 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(chunksizes) to file, data not available, aborting ...\n"));
165 if (nwrite !=
sizeof(sion_int64) * sion_filedesc->
ntasks) {
166 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(chunksizes) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
168 DPRINTFP((32, DFUNCTION, -1,
" wrote chunksizes nwrite=%lu\n", (
unsigned long) nwrite));
171 DPRINTFP((2, DFUNCTION, -1,
"leave write\n"));
177 #define DFUNCTION "_sion_write_header_var_info"
186 int rc = SION_SUCCESS;
189 DPRINTFP((2, DFUNCTION, -1,
"enter write\n"));
198 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(maxusedchunks) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
200 DPRINTFP((32, DFUNCTION, -1,
" wrote maxusedchunks %d nwrite=%lu\n", sion_filedesc->
maxusedchunks, (
unsigned long) nwrite));
205 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(start_of_varheader) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
207 DPRINTFP((32, DFUNCTION, -1,
" wrote start_of_varheader %d nwrite=%lu\n", sion_filedesc->
start_of_varheader, (
unsigned long) nwrite));
210 DPRINTFP((2, DFUNCTION, -1,
"leave write\n"));
216 #define DFUNCTION "_sion_write_header_var_part_blocksizes"
225 int rc = SION_SUCCESS;
228 DPRINTFP((2, DFUNCTION, -1,
"enter write\n"));
232 DPRINTFP((16, DFUNCTION, sion_filedesc->
rank,
" after set fp to start_of_varheader, fileptr is at position %14lld\n",
_sion_file_get_position(sion_filedesc->
fileptr)));
236 if (nwrite !=
sizeof(sion_int64) * sion_filedesc->
ntasks) {
237 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(all_blockcount) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
239 DPRINTFP((32, DFUNCTION, -1,
" wrote all_blockcount field %d elements nwrite=%lu\n", sion_filedesc->
ntasks, (
unsigned long) nwrite));
244 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(all_blocksizes) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
246 DPRINTFP((32, DFUNCTION, -1,
" wrote all_blocksizes field %d elements nwrite=%lu\n", sion_filedesc->
ntasks * sion_filedesc->
maxusedchunks, (
unsigned long) nwrite));
249 DPRINTFP((2, DFUNCTION, -1,
"leave write\n"));
255 #define DFUNCTION "_sion_write_header_var_part_mapping"
265 sion_int32 mapping_size,
266 sion_int32 *mapping )
268 int rc = SION_SUCCESS, lrank;
272 DPRINTFP((2, DFUNCTION, -1,
"enter write\n"));
275 + sion_filedesc->
ntasks *
sizeof(sion_int64)
280 DPRINTFP((16, DFUNCTION, sion_filedesc->
rank,
" after set fp to start_of_varheader, fileptr is at position %14lld\n",
_sion_file_get_position(sion_filedesc->
fileptr)));
284 if (nwrite !=
sizeof(sion_int32)) {
285 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(mapping_size) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
287 DPRINTFP((32, DFUNCTION, -1,
" wrote mapping_size=%d elements nwrite=%lu\n", mapping_size, (
unsigned long) nwrite));
292 if (nwrite !=
sizeof(sion_int32) * 2 * mapping_size) {
293 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot write header(mapping) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
295 DPRINTFP((32, DFUNCTION, -1,
" wrote mapping field %d elements nwrite=%lu\n", 2 * mapping_size, (
unsigned long) nwrite*2*mapping_size));
296 for (lrank = 0; lrank < mapping_size; lrank++) {
297 DPRINTFP((2048, DFUNCTION, - 1,
" mapping[%4d]=(%10ld,%10ld)\n", lrank,mapping[lrank*2],mapping[lrank*2+1]));
300 DPRINTFP((32, DFUNCTION, -1,
" wrote no mapping field\n"));
303 DPRINTFP((2, DFUNCTION, -1,
"leave write\n"));
310 #define DFUNCTION "_sion_read_header_fix_part"
319 int rc = SION_SUCCESS;
321 char *sionstr, *lprefix;
322 sion_uint32 lendianness;
323 sion_int32 lfsblksize;
324 sion_int32 Rsion_version, Rsion_version_patchlevel, Rsion_fileformat_version;
326 DPRINTFP((2, DFUNCTION, -1,
"enter read fix_part\n"));
330 sionstr = (
char *) malloc(strlen(
SION_ID) *
sizeof(char));
332 if (nread != strlen(
SION_ID)) {
333 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_fix_part: cannot read header(SION_ID) from file, aborting ... (%lu!=%lu)\n",
334 (
unsigned long) nread, (
unsigned long) strlen(
SION_ID)));
336 DPRINTFP((32, DFUNCTION, -1,
" sionstr =>%c%c%c%c<\n", sionstr[0], sionstr[1], sionstr[2], sionstr[3]));
339 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: not a sion file(ID: %c%c%c%c)\n", sionstr[0], sionstr[1], sionstr[2], sionstr[3]));
345 if (nread !=
sizeof(lendianness)) {
346 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header: cannot read header(endianness) from file, aborting ... (%lu!=%lu)\n",(
unsigned long) nread, (
unsigned long)
sizeof(lendianness)));
351 DPRINTFP((32, DFUNCTION, -1,
" endianness =0x%x swapbytes=%d\n", sion_filedesc->
endianness, sion_filedesc->
swapbytes));
356 if (nread !=
sizeof(Rsion_version)) {
357 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_fix_part: cannot read header(sion_version) from file, aborting ... (%lu!=%lu)\n", (
unsigned long) nread, (
unsigned long)
sizeof(Rsion_version)));
359 sion_swap(&Rsion_version, &Rsion_version,
sizeof(Rsion_version), 1, sion_filedesc->
swapbytes);
361 DPRINTFP((32, DFUNCTION, -1,
" sion_version=%d\n", Rsion_version));
363 nread =
_sion_file_read(&Rsion_version_patchlevel,
sizeof(Rsion_version_patchlevel), sion_filedesc->
fileptr);
364 if (nread !=
sizeof(Rsion_version_patchlevel)) {
365 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_fix_part: cannot read header(sion_version_patchlevel) from file, aborting ... (%lu!=%lu)\n",
366 (
unsigned long) nread, (
unsigned long)
sizeof(Rsion_version_patchlevel)));
368 sion_swap(&Rsion_version_patchlevel, &Rsion_version_patchlevel,
sizeof(Rsion_version_patchlevel), 1, sion_filedesc->
swapbytes);
370 DPRINTFP((32, DFUNCTION, -1,
" sion_version_patchlevel=%d\n", (
int) Rsion_version_patchlevel));
372 nread =
_sion_file_read(&Rsion_fileformat_version,
sizeof(Rsion_fileformat_version), sion_filedesc->
fileptr);
373 if (nread !=
sizeof(Rsion_fileformat_version)) {
374 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_fix_part: cannot read header(sion_fileformat_version) from file, aborting ... (%lu!=%lu)\n",
375 (
unsigned long) nread, (
unsigned long)
sizeof(Rsion_fileformat_version)));
377 sion_swap(&Rsion_fileformat_version, &Rsion_fileformat_version,
sizeof(Rsion_fileformat_version), 1, sion_filedesc->
swapbytes);
378 sion_filedesc->
fileversion=Rsion_fileformat_version;
379 DPRINTFP((32, DFUNCTION, -1,
" sion_fileformat_version=%d\n", (
int) Rsion_fileformat_version));
381 if (Rsion_fileformat_version != SION_FILEFORMAT_VERSION) {
382 if(Rsion_fileformat_version<2) {
383 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"sionlib: FATAL ERROR: file format version of file differs, aborting ... (%lu!=%lu)\n",
384 (
unsigned long) Rsion_fileformat_version, (
unsigned long) SION_FILEFORMAT_VERSION));
386 _sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_WARN,
"sionlib: FATAL WARNING: old file format version of file differs, trying to read ... (%lu!=%lu)\n",
387 (
unsigned long) Rsion_fileformat_version, (
unsigned long) SION_FILEFORMAT_VERSION);
394 if (nread !=
sizeof(sion_filedesc->
fsblksize)) {
395 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_fix_part: cannot read header(fsblksize) from file, aborting ... (%lu!=%lu)\n",
396 (
unsigned long) nread, (
unsigned long)
sizeof(sion_filedesc->
fsblksize)));
399 DPRINTFP((32, DFUNCTION, -1,
" fsblksize=%d\n", sion_filedesc->
fsblksize));
403 if (nread !=
sizeof(sion_filedesc->
ntasks)) {
404 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_fix_part: cannot read header(ntasks) from file, aborting ... (%lu!=%lu)\n",
405 (
unsigned long) nread, (
unsigned long)
sizeof(sion_filedesc->
ntasks)));
408 DPRINTFP((32, DFUNCTION, -1,
" ntasks =%d\n", sion_filedesc->
ntasks));
412 if (nread !=
sizeof(sion_filedesc->
nfiles)) {
413 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_fix_part: cannot read header(nfiles) from file, aborting ... (%lu!=%lu)\n",
414 (
unsigned long) nread, (
unsigned long)
sizeof(sion_filedesc->
nfiles)));
417 DPRINTFP((32, DFUNCTION, -1,
" nfiles =%d\n", sion_filedesc->
nfiles));
422 if (nread !=
sizeof(sion_filedesc->
filenumber)) {
423 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_fix_part: cannot read header(filenumber) from file, aborting ... (%lu!=%lu)\n",
424 (
unsigned long) nread, (
unsigned long)
sizeof(sion_filedesc->
filenumber)));
430 DPRINTFP((32, DFUNCTION, -1,
" filenumber =%d\n", sion_filedesc->
filenumber));
434 if(Rsion_fileformat_version>=3) {
436 if (nread !=
sizeof(sion_filedesc->
flag1)) {
437 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_fix_part: cannot read header(flag1) from file, aborting ... (%lu!=%lu)\n",
438 (
unsigned long) nread, (
unsigned long)
sizeof(sion_filedesc->
flag1)));
444 DPRINTFP((32, DFUNCTION, -1,
" flag1 =%lld\n", sion_filedesc->
flag1));
446 if(Rsion_fileformat_version>=5) {
461 if(Rsion_fileformat_version>=3) {
463 if (nread !=
sizeof(sion_filedesc->
flag2)) {
464 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_fix_part: cannot read header(flag2) from file, aborting ... (%lu!=%lu)\n",
465 (
unsigned long) nread, (
unsigned long)
sizeof(sion_filedesc->
flag2)));
471 DPRINTFP((32, DFUNCTION, -1,
" flag2 =%lld\n", sion_filedesc->
flag2));
474 lprefix = malloc(SION_FILENAME_LENGTH);
476 if (nread != SION_FILENAME_LENGTH) {
477 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_fix_part: cannot read header(lprefix) from file, aborting ... (%lu!=%d)\n", (
unsigned long) nread, SION_FILENAME_LENGTH));
479 sion_filedesc->
prefix=strdup(lprefix);
481 DPRINTFP((32, DFUNCTION, -1,
" prefix =%s\n", sion_filedesc->
prefix));
484 DPRINTFTS(sion_filedesc->
rank,
"before purge");
486 DPRINTFTS(sion_filedesc->
rank,
"after purge");
490 DPRINTFP((2, DFUNCTION, -1,
"leave read fix_part\n"));
496 #define DFUNCTION "_sion_read_header_var_part"
505 int rc = SION_SUCCESS;
507 sion_int32 Rmaxchunks;
509 DPRINTFP((32, DFUNCTION, -1,
"enter read var_part\n"));
514 if (nread !=
sizeof(sion_int64) * sion_filedesc->
ntasks) {
515 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_var_part: cannot read header(globalranks) from file, aborting ... (%d)\n", sion_filedesc->
ntasks));
521 if (nread !=
sizeof(sion_int64) * sion_filedesc->
ntasks) {
522 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_var_part: cannot read header(chunksizes) from file, aborting ... (%d!=%lu)\n", sion_filedesc->
ntasks, (
unsigned long) nread));
528 if (nread !=
sizeof(Rmaxchunks)) {
529 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_var_part: cannot read header(maxchunks) from file, aborting ... (%lu!=%lu)\n",
530 (
unsigned long) nread, (
unsigned long)
sizeof(Rmaxchunks)));
533 DPRINTFP((32, DFUNCTION, -1,
" maxchunks=%d\n", Rmaxchunks));
541 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_var_part: cannot read header(start_of_varheader) from file, aborting ... (%lu!=%lu)\n",
545 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_var_part: bad value for start_of_varheader (=%lu), aborting ...\n",
550 DPRINTFP((32, DFUNCTION, -1,
"leave read var_part start_of_varheader=%lld\n", sion_filedesc->
start_of_varheader));
557 #define DFUNCTION "_sion_rd_hdr_var_prt_blkcnt_to_field"
570 int rc = SION_SUCCESS;
573 DPRINTFP((32, DFUNCTION, -1,
"enter\n"));
576 if (field_size < sion_filedesc->ntasks) {
577 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_var_part_blockcount_to_field: cannot read header(blocksizes) field too small, aborting ... (%d<%d)\n", field_size, sion_filedesc->
ntasks));
584 if (nread !=
sizeof(sion_int64) * sion_filedesc->
ntasks) {
585 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_var_part_blockcount_to_field: cannot read blocksizes from meta block 2 of the file, aborting ... (%d,%d)\n", sion_filedesc->
ntasks, nread));
590 DPRINTFP((32, DFUNCTION, -1,
"leave \n"));
597 #define DFUNCTION "_sion_rd_hdr_vr_prt_nxtblksizes_to_field"
612 int rc = SION_SUCCESS;
614 DPRINTFP((32, DFUNCTION, -1,
"enter\n"));
617 if (field_size < sion_filedesc->ntasks) {
618 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_var_part_nextblocksizes_to_field: cannot read header(blocksizes) field too small, aborting ... (%d<%d)\n", field_size, sion_filedesc->
ntasks));
621 if (nread !=
sizeof(sion_int64) * sion_filedesc->
ntasks) {
622 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_var_part_nextblocksizes_to_field: cannot read blocksizes from meta block 2 of the file, aborting ... (%d,%d)\n", sion_filedesc->
ntasks, nread));
627 DPRINTFP((32, DFUNCTION, -1,
"leave \n"));
634 #define DFUNCTION "_sion_read_header_var_part_blocksizes"
643 int rc = SION_SUCCESS;
647 DPRINTFP((32, DFUNCTION, -1,
"enter read\n"));
655 if (nread !=
sizeof(sion_int64) * sion_filedesc->
ntasks) {
656 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_var_part_blocksizes: cannot read header from file(sion_blockcount), aborting ... (%d)\n", sion_filedesc->
ntasks));
659 for (i = 0; i < sion_filedesc->
ntasks; i++)
660 DPRINTFP((2048, DFUNCTION, -1,
" read, numblocks on task %02d is %10lld\n", i, sion_filedesc->
all_blockcount[i]));
665 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_var_part_blocksizes: cannot read header(sion_blocksizes) from file, aborting ... (%lu!=%lu)\n",
666 (
unsigned long) sion_filedesc->
ntasks * sion_filedesc->
maxusedchunks, (
unsigned long) nread));
670 for (i = 0; i < sion_filedesc->
ntasks; i++)
671 DPRINTFP((2048, DFUNCTION, -1,
" read, blocksize[0] on task %02d is %10lld\n", i, sion_filedesc->
all_blocksizes[0*sion_filedesc->
ntasks+i]));
673 DPRINTFP((32, DFUNCTION, -1,
"leave read\n"));
680 #define DFUNCTION "_sion_read_header_var_part_mapping"
691 int rc = SION_SUCCESS;
695 DPRINTFP((32, DFUNCTION, -1,
"enter read\n"));
698 + sion_filedesc->
ntasks *
sizeof(sion_int64)
708 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_var_part_mapping: cannot read header(mapping_size) from file, aborting ... (%d)\n", nread));
711 DPRINTFP((32, DFUNCTION, -1,
"mapping_size=%ld\n", (
long) sion_filedesc->
mapping_size));
714 sion_filedesc->
mapping = (sion_int32 *) malloc(sion_filedesc->
mapping_size * 2 *
sizeof(sion_int32));
715 if (sion_filedesc->
mapping == NULL) {
716 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_var_part_mapping: cannot allocate temporary memory of size %lu (mapping), aborting ...\n", (
unsigned long) 2 * sion_filedesc->
mapping_size *
sizeof(sion_int64)));
718 DPRINTFP((32, DFUNCTION, -1,
"alloc mapping vector size=%d (%lu bytes)\n", sion_filedesc->
mapping_size, (
long) sion_filedesc->
mapping_size * 2 *
sizeof(sion_int32)));
722 DPRINTFP((32, DFUNCTION, -1,
"read mapping, %d \n", nread));
723 if (nread != (
sizeof(sion_int32) * sion_filedesc->
mapping_size * 2)) {
724 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_var_part_mapping: cannot read header(mapping) from file, aborting ... (%d!=%lu)\n", sion_filedesc->
mapping_size*2, (
unsigned long) nread));
728 DPRINTFP((32, DFUNCTION, -1,
"leave read\n"));
735 #define DFUNCTION "_sion_read_header_var_part_locations_rank"
745 int rc = SION_SUCCESS;
749 sion_int64 helpint64;
751 DPRINTFP((32, DFUNCTION, -1,
"enter read for rank %d of %d\n",sion_filedesc->
rank,sion_filedesc->
ntasks));
759 numblocks = helpint64;
760 if (nread !=
sizeof(sion_int64)) {
761 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_var_part_locations_rank: cannot read header(numblocks) from file, aborting ... (%d)\n", sion_filedesc->
ntasks));
767 for (i = 0; i < numblocks; i++) {
770 + (i + 1) * sion_filedesc->
ntasks *
sizeof(sion_int64)
771 + sion_filedesc->
rank *
sizeof(sion_int64);
776 if (nread !=
sizeof(sion_int64)) {
777 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_var_part_locations_rank: cannot read header(blocksizes) from file, aborting ... (%d!=%lu)\n", 1, (
unsigned long) nread));
781 DPRINTFP((32,
"_sion_read_header_var_part_locations_rank", -1,
"read blocksizes[%i], %lld start_of_varheader=%lld\n", i, helpint64, sion_filedesc->
start_of_varheader));
785 DPRINTFP((32, DFUNCTION, -1,
"leave read\n"));
792 #define DFUNCTION "_sion_read_header_var_part_mapping_rank"
803 int rc = SION_SUCCESS;
807 sion_int32 helpint32;
809 DPRINTFP((32, DFUNCTION, -1,
"enter read for rank %d of %d\n",sion_filedesc->
rank,sion_filedesc->
ntasks));
812 + sion_filedesc->
ntasks *
sizeof(sion_int64)
821 if (nread !=
sizeof(sion_int32)) {
822 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_var_part_mapping_rank: cannot read header(mapping_size) from file, aborting ... (%d)\n", sion_filedesc->
ntasks));
826 DPRINTFP((32,
"_sion_read_header_var_part_mapping_rank", -1,
"read mapping_size %d \n", msize));
828 if((sion_filedesc->
rank<0) || (sion_filedesc->
rank>=msize)) {
829 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_var_part_mapping_rank: wrong rank %d not between 0 .. %d aborting ...\n", sion_filedesc->
rank,msize));
834 + sion_filedesc->
ntasks *
sizeof(sion_int64)
837 + 2*sion_filedesc->
rank*
sizeof(sion_int32);
845 sion_filedesc->
mapping = (sion_int32 *) malloc(sion_filedesc->
mapping_size * 2 *
sizeof(sion_int32));
846 if (sion_filedesc->
mapping == NULL) {
847 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_var_part_mapping: cannot allocate temporary memory of size %lu (mapping), aborting ...\n", (
unsigned long) 2 * sion_filedesc->
mapping_size *
sizeof(sion_int64)));
849 DPRINTFP((32, DFUNCTION, -1,
"alloc mapping vector size=%d (%lu bytes)\n", sion_filedesc->
mapping_size, (
long) sion_filedesc->
mapping_size * 2 *
sizeof(sion_int32)));
853 DPRINTFP((32, DFUNCTION, -1,
"read mapping, %d \n", nread));
854 if (nread != (
sizeof(sion_int32) * sion_filedesc->
mapping_size * 2)) {
855 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_var_part_mapping: cannot read header(mapping) from file, aborting ... (%d!=%lu)\n", sion_filedesc->
mapping_size*2, (
unsigned long) nread));
859 DPRINTFP((32, DFUNCTION, -1,
"leave read filenumber=%d lrank=%d\n",sion_filedesc->
mapping[0], sion_filedesc->
mapping[1]));
867 #define DFUNCTION "_sion_wr_hdr_var_prt_blkcnt_from_field"
883 DPRINTFP((32, DFUNCTION, -1,
"enter\n"));
886 if (field_size < sion_filedesc->ntasks) {
887 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_read_header_var_part_blockcount_to_field: cannot read header(blocksizes) field too small, aborting ... (%d<%d)\n", field_size, sion_filedesc->
ntasks));
894 if (nwrite !=
sizeof(sion_int64) * sion_filedesc->
ntasks) {
895 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header_var_part_blockcount_from_field: cannot write header(all_blockcount) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
897 DPRINTFP((32, DFUNCTION, -1,
" wrote all_blockcount field %d elements nwrite=%lu\n", sion_filedesc->
ntasks, (
unsigned long) nwrite));
899 DPRINTFP((32, DFUNCTION, -1,
"leave \n"));
906 #define DFUNCTION "_sion_wr_hdr_vr_prt_nxtblksizes_from_field"
923 DPRINTFP((32, DFUNCTION, -1,
"enter\n"));
926 if (field_size < sion_filedesc->ntasks) {
927 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header_var_part_nextblocksizes_from_field: cannot write header(blocksizes) field too small, aborting ... (%d<%d)\n", field_size, sion_filedesc->
ntasks));
930 if (nwrite !=
sizeof(sion_int64) * sion_filedesc->
ntasks) {
931 return(_sion_errorprint(SION_NOT_SUCCESS,_SION_ERROR_RETURN,
"_sion_write_header_var_part_nextblocksizes_from_field: cannot write header(all_blocksizes) to file, aborting ... (%lu)\n", (
unsigned long) nwrite));
933 DPRINTFP((32, DFUNCTION, -1,
" wrote all_blocksizes field %d elements nwrite=%lu\n", sion_filedesc->
ntasks, (
unsigned long) nwrite));
935 DPRINTFP((32, DFUNCTION, -1,
"leave \n"));
char * sion_keyval_type_to_str(int type)
Returns key value mode as string.
int sion_get_endianness(void)
Return endianness.
void sion_swap(void *target, void *source, int size, int n, int do_swap)
int _sion_file_flush(_sion_fileptr *sion_fileptr)
Flush data to file.
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.
sion_int64 _sion_file_write(const void *data, sion_int64 bytes, _sion_fileptr *sion_fileptr)
Write data to file.
sion_int64 _sion_file_read(void *data, sion_int64 bytes, _sion_fileptr *sion_fileptr)
Read data from 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.
Sion File Descriptor Structure.
sion_int64 * all_blocksizes
sion_int32 filesionversion
sion_int64 start_of_varheader
sion_int32 filesionpatchlevel
sion_int64 * all_chunksizes
sion_int64 * all_globalranks
sion_int64 * all_blockcount